Add type champs "Address" plug at the BAN

This commit is contained in:
Xavier J 2016-06-09 12:08:18 +02:00
parent 35a07aec87
commit 23ab25396f
18 changed files with 2804 additions and 13 deletions

View file

@ -0,0 +1,36 @@
module Carto
module Bano
# input : address
# output : Array List label address
class AddressRetriever
def initialize(address)
@address = address
end
def list
@list ||= convert_driver_result_to_full_address
end
private
def driver
@driver ||= Carto::Bano::Driver.new @address, 5
end
def convert_driver_result_to_full_address
result = JSON.parse(driver.call)
if result['features'].size == 0
Rails.logger.error "unable to find location for address #{@address}"
return []
end
result['features'].inject([]) do |acc, feature|
acc.push feature['properties']['label']
end
rescue TypeError, JSON::ParserError
[]
end
end
end
end

View file

@ -3,12 +3,15 @@ module Carto
# input : string (address)
# output : json
class Driver
def initialize(address)
def initialize(address, limit = 1)
@address = address
@limit = limit
end
def call
RestClient.get api_url, params: { q: @address, limit: 1 }
RestClient.get api_url, params: { q: @address, limit: @limit }
rescue RestClient::ServiceUnavailable
nil
end
def api_url