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)


316
317
318
319
# File 'app/models/georeference/geo_locate.rb', line 316

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.



313
314
315
# File 'app/models/georeference/geo_locate.rb', line 313

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)


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

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.



322
323
324
# File 'app/models/georeference/geo_locate.rb', line 322

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.



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

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.



327
328
329
330
# File 'app/models/georeference/geo_locate.rb', line 327

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