First Commit

This commit is contained in:
Xavier J 2015-08-10 11:05:06 +02:00
commit b5b83e939a
213 changed files with 8688 additions and 0 deletions

19
lib/carto/bano/driver.rb Normal file
View file

@ -0,0 +1,19 @@
module Carto
module Bano
# input : string (address)
# output : json
class Driver
def initialize(address)
@address = address
end
def call
RestClient.get api_url, params: { q: @address, limit: 1 }
end
def api_url
'http://api-adresse.data.gouv.fr/search'
end
end
end
end

View file

@ -0,0 +1,30 @@
module Carto
module Bano
# input : address
# output : point RGeo::Cartesian::PointImpl
class PointRetriever
def initialize(address)
@address = address
end
def point
@point ||= convert_driver_result_to_point
end
private
def driver
@driver ||= Carto::Bano::Driver.new @address
end
def convert_driver_result_to_point
result = JSON.parse(driver.call)
if result['features'].size == 0
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
end
end

11
lib/carto/geocodeur.rb Normal file
View file

@ -0,0 +1,11 @@
module Carto
# this class take a string in input and return a point
class Geocodeur
def self.convert_adresse_to_point(address)
Carto::Bano::PointRetriever.new(address)
rescue RestClient::Exception, JSON::ParserError => e
Rails.logger.error e.message
nil
end
end
end