diff --git a/app/lib/api_adresse/address_retriever.rb b/app/lib/api_adresse/address_retriever.rb index 4a1fc2640..735fe5bad 100644 --- a/app/lib/api_adresse/address_retriever.rb +++ b/app/lib/api_adresse/address_retriever.rb @@ -1,28 +1,26 @@ -module ApiAdresse - class AddressRetriever - def initialize(address) - @address = address +class ApiAdresse::AddressRetriever + def initialize(address) + @address = address + end + + def list + @list ||= convert_api_result_to_full_address + end + + private + + def convert_api_result_to_full_address + result = JSON.parse(ApiAdresse::API.call(@address, 5)) + + if result['features'].empty? + Rails.logger.error "unable to find location for address #{@address}" + return [] end - def list - @list ||= convert_api_result_to_full_address - end - - private - - def convert_api_result_to_full_address - result = JSON.parse(ApiAdresse::API.call(@address, 5)) - - if result['features'].empty? - Rails.logger.error "unable to find location for address #{@address}" - return [] - end - - result['features'].map do |feature| - feature['properties']['label'] - end - rescue TypeError, JSON::ParserError - [] + result['features'].map do |feature| + feature['properties']['label'] end + rescue TypeError, JSON::ParserError + [] end end diff --git a/app/lib/api_adresse/geocodeur.rb b/app/lib/api_adresse/geocodeur.rb index 1d471fd76..8c252998d 100644 --- a/app/lib/api_adresse/geocodeur.rb +++ b/app/lib/api_adresse/geocodeur.rb @@ -1,10 +1,8 @@ -module ApiAdresse - class Geocodeur - def self.convert_adresse_to_point(address) - ApiAdresse::PointRetriever.new(address).point - rescue RestClient::Exception, JSON::ParserError => e - Rails.logger.error(e.message) - nil - end +class ApiAdresse::Geocodeur + def self.convert_adresse_to_point(address) + ApiAdresse::PointRetriever.new(address).point + rescue RestClient::Exception, JSON::ParserError => e + Rails.logger.error(e.message) + nil end end diff --git a/app/lib/api_adresse/point_retriever.rb b/app/lib/api_adresse/point_retriever.rb index 837d9c3ab..3a4b5ee9f 100644 --- a/app/lib/api_adresse/point_retriever.rb +++ b/app/lib/api_adresse/point_retriever.rb @@ -1,22 +1,20 @@ -module ApiAdresse - class PointRetriever - def initialize(address) - @address = address - end +class ApiAdresse::PointRetriever + def initialize(address) + @address = address + end - def point - @point ||= convert_api_result_to_point - end + def point + @point ||= convert_api_result_to_point + end - private + private - def convert_api_result_to_point - result = JSON.parse(ApiAdresse::API.call(@address)) - if result['features'].empty? - Rails.logger.error "unable to find location for address #{@address}" - return nil - end - RGeo::GeoJSON.decode(result['features'][0]['geometry'], json_parser: :json) + def convert_api_result_to_point + result = JSON.parse(ApiAdresse::API.call(@address)) + if result['features'].empty? + Rails.logger.error "unable to find location for address #{@address}" + return nil end + RGeo::GeoJSON.decode(result['features'][0]['geometry'], json_parser: :json) end end diff --git a/app/lib/api_geo/driver.rb b/app/lib/api_geo/driver.rb index 9f5d36077..78fca7f83 100644 --- a/app/lib/api_geo/driver.rb +++ b/app/lib/api_geo/driver.rb @@ -1,25 +1,23 @@ -module ApiGeo - class Driver - def self.regions - url = [API_GEO_URL, "regions"].join("/") - call(url) - end +class ApiGeo::Driver + def self.regions + url = [API_GEO_URL, "regions"].join("/") + call(url) + end - def self.departements - url = [API_GEO_URL, "departements"].join("/") - call(url) - end + def self.departements + url = [API_GEO_URL, "departements"].join("/") + call(url) + end - def self.pays - File.open('app/lib/api_geo/pays.json').read - end + def self.pays + File.open('app/lib/api_geo/pays.json').read + end - private + private - def self.call(url) - RestClient.get(url, params: { fields: :nom }) - rescue RestClient::ServiceUnavailable - nil - end + def self.call(url) + RestClient.get(url, params: { fields: :nom }) + rescue RestClient::ServiceUnavailable + nil end end