Class: Georeference::GeoLocate::Response

Inherits:
Object
  • Object
show all
Defined in:
app/models/georeference/geo_locate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Response

Returns a new instance of Response.

Parameters:

  • request (JSON object)


292
293
294
295
# File 'app/models/georeference/geo_locate.rb', line 292

def initialize(request)
  @result           = JSON.parse(call_api(Georeference::GeoLocate::API_HOST, request))
  request.succeeded = true if @result['numResults'].to_i > 0
end

Instance Attribute Details

#resultObject

Returns the value of attribute result.



289
290
291
# File 'app/models/georeference/geo_locate.rb', line 289

def result
  @result
end

Instance Method Details

#call_api(host, request) ⇒ HTTP object (protected)

Parameters:

  • host (String)

    domain name

  • request (String)

    string.

Returns:

  • (HTTP object)


319
320
321
# File 'app/models/georeference/geo_locate.rb', line 319

def call_api(host, request)
  Net::HTTP.get(host, request.request_string)
end

#coordinatesString

Returns coordinates from the response set.

Returns:

  • (String)

    coordinates from the response set.



298
299
300
# File 'app/models/georeference/geo_locate.rb', line 298

def coordinates
  @result['resultSet']['features'][0]['geometry']['coordinates']
end

#uncertainty_polygonString

Returns uncertainty_polygon from the response set.

Returns:

  • (String)

    uncertainty_polygon from the response set.



309
310
311
312
# File 'app/models/georeference/geo_locate.rb', line 309

def uncertainty_polygon
  retval = @result['resultSet']['features'][0]['properties']['uncertaintyPolygon']
  (retval == 'Unavailable') ? nil : retval['coordinates'][0]
end

#uncertainty_radiusString

Returns uncertainty_radius from the response set.

Returns:

  • (String)

    uncertainty_radius from the response set.



303
304
305
306
# File 'app/models/georeference/geo_locate.rb', line 303

def uncertainty_radius
  retval = @result['resultSet']['features'][0]['properties']['uncertaintyRadiusMeters']
  (retval == 'Unavailable') ? 3 : retval
end