Simplify ApiAdresse
This commit is contained in:
parent
a841a517df
commit
8b4ba42f15
4 changed files with 5 additions and 18 deletions
|
@ -12,12 +12,8 @@ module ApiAdresse
|
|||
|
||||
private
|
||||
|
||||
def api
|
||||
@api ||= ApiAdresse::API.new(@address, 5)
|
||||
end
|
||||
|
||||
def convert_api_result_to_full_address
|
||||
result = JSON.parse(api.call)
|
||||
result = JSON.parse(ApiAdresse::API.call(@address, 5))
|
||||
|
||||
if result['features'].empty?
|
||||
Rails.logger.error "unable to find location for address #{@address}"
|
||||
|
|
|
@ -1,15 +1,10 @@
|
|||
class ApiAdresse::API
|
||||
# input : string (address)
|
||||
# output : json
|
||||
def initialize(address, limit = 1)
|
||||
@address = address
|
||||
@limit = limit
|
||||
end
|
||||
|
||||
def call
|
||||
def self.call(address, limit = 1)
|
||||
search_url = [API_ADRESSE_URL, "search"].join("/")
|
||||
|
||||
RestClient.get(search_url, params: { q: @address, limit: @limit })
|
||||
RestClient.get(search_url, params: { q: address, limit: limit })
|
||||
rescue RestClient::ServiceUnavailable
|
||||
nil
|
||||
end
|
||||
|
|
|
@ -12,12 +12,8 @@ module ApiAdresse
|
|||
|
||||
private
|
||||
|
||||
def api
|
||||
@api ||= ApiAdresse::API.new(@address)
|
||||
end
|
||||
|
||||
def convert_api_result_to_point
|
||||
result = JSON.parse(api.call)
|
||||
result = JSON.parse(ApiAdresse::API.call(@address))
|
||||
if result['features'].empty?
|
||||
Rails.logger.error "unable to find location for address #{@address}"
|
||||
return nil
|
||||
|
|
|
@ -8,7 +8,7 @@ describe ApiAdresse::Geocodeur do
|
|||
end
|
||||
context 'when RestClient::Exception' do
|
||||
before do
|
||||
allow_any_instance_of(ApiAdresse::API).to receive(:call).and_raise(RestClient::Exception)
|
||||
allow(ApiAdresse::API).to receive(:call).and_raise(RestClient::Exception)
|
||||
end
|
||||
it 'return nil' do
|
||||
expect(described_class.convert_adresse_to_point(address)).to be_nil
|
||||
|
|
Loading…
Reference in a new issue