2018-10-15 18:08:13 +02:00
|
|
|
class ApiAdresse::PointAdapter
|
2018-10-15 17:26:06 +02:00
|
|
|
def initialize(address)
|
|
|
|
@address = address
|
|
|
|
end
|
2018-10-15 16:33:42 +02:00
|
|
|
|
2018-10-15 22:37:59 +02:00
|
|
|
def geocode
|
2018-10-15 17:26:06 +02:00
|
|
|
@point ||= convert_api_result_to_point
|
|
|
|
end
|
2018-10-15 16:33:42 +02:00
|
|
|
|
2018-10-15 17:26:06 +02:00
|
|
|
private
|
2018-10-15 16:33:42 +02:00
|
|
|
|
2018-10-15 17:26:06 +02:00
|
|
|
def convert_api_result_to_point
|
|
|
|
result = JSON.parse(ApiAdresse::API.call(@address))
|
2018-10-15 17:37:38 +02:00
|
|
|
|
2018-10-15 17:26:06 +02:00
|
|
|
if result['features'].empty?
|
|
|
|
Rails.logger.error "unable to find location for address #{@address}"
|
|
|
|
return nil
|
2018-10-15 16:33:42 +02:00
|
|
|
end
|
2018-10-15 17:37:38 +02:00
|
|
|
|
2018-10-15 17:26:06 +02:00
|
|
|
RGeo::GeoJSON.decode(result['features'][0]['geometry'], json_parser: :json)
|
2018-10-15 16:33:42 +02:00
|
|
|
end
|
|
|
|
end
|