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)


338
339
340
341
# File 'app/models/georeference/geo_locate.rb', line 338

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

#result ⇒ Object

Returns the value of attribute result.



335
336
337
# File 'app/models/georeference/geo_locate.rb', line 335

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)


365
366
367
# File 'app/models/georeference/geo_locate.rb', line 365

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

#coordinates ⇒ String

Returns coordinates from the response set.

Returns:

  • (String) —

    coordinates from the response set.



344
345
346
# File 'app/models/georeference/geo_locate.rb', line 344

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

#uncertainty_polygon ⇒ String

Returns uncertainty_polygon from the response set.

Returns:

  • (String) —

    uncertainty_polygon from the response set.



355
356
357
358
# File 'app/models/georeference/geo_locate.rb', line 355

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

#uncertainty_radius ⇒ String

Returns uncertainty_radius from the response set.

Returns:

  • (String) —

    uncertainty_radius from the response set.



349
350
351
352
# File 'app/models/georeference/geo_locate.rb', line 349

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