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

0
lib/assets/.keep Normal file
View file

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

35
lib/siade/api.rb Normal file
View file

@ -0,0 +1,35 @@
class SIADE::Api
class << self
attr_accessor :token
end
def initialize
end
def self.entreprise(siren)
endpoint = "/api/v1/entreprises/#{siren}"
call(base_url + endpoint)
end
def self.etablissement(siret)
endpoint = "/api/v1/etablissements/#{siret}"
call(base_url + endpoint)
end
def self.call(url)
verify_ssl_mode = OpenSSL::SSL::VERIFY_NONE
RestClient::Resource.new(
url,
verify_ssl: verify_ssl_mode
).get(params: { token: SIADETOKEN })
rescue
nil
end
def self.base_url
'https://api-dev.apientreprise.fr'
end
end

View file

@ -0,0 +1,40 @@
class SIADE::EntrepriseAdapter
def initialize(siren)
@siren = siren
end
def data_source
@data_source ||= JSON.parse(SIADE::Api.entreprise(@siren), symbolize_names: true)
rescue
@data_source = nil
end
def to_params
params = {}
data_source[:entreprise].each do |k,v|
if attr_to_fetch.include?(k)
params[k] = v
end
end
params
rescue
nil
end
def attr_to_fetch
[:siren,
:capital_social,
:numero_tva_intracommunautaire,
:forme_juridique,
:forme_juridique_code,
:nom_commercial,
:raison_sociale,
:siret_siege_social,
:code_effectif_entreprise,
:date_creation,
:nom,
:prenom]
end
end

View file

@ -0,0 +1,57 @@
class SIADE::EtablissementAdapter
def initialize(siret)
@siret = siret
end
def data_source
@data_source ||= JSON.parse(SIADE::Api.etablissement(@siret), symbolize_names: true)
rescue
@data_source = nil
end
def to_params
params = {}
data_source[:etablissement].each do |k,v|
if attr_to_fetch.include?(k)
params[k] = v
end
end
params[:adresse] = adresse
data_source[:etablissement][:adresse].each do |k,v|
if address_attribut_to_fetch.include?(k)
params[k] = v
end
end
params
rescue
raise "SIRET Non reconnu"
end
def attr_to_fetch
[:siret,
:siege_social,
:naf,
:libelle_naf,
]
end
def adresse
adresse = ''
[:l1, :l2, :l3, :l4, :l5].each do |line|
adresse = adresse + data_source[:etablissement][:adresse][line] + "\r\n" unless data_source[:etablissement][:adresse][line].nil?
end
adresse
end
def address_attribut_to_fetch
[:numero_voie,
:type_voie,
:nom_voie,
:complement_adresse,
:code_postal,
:localite,
:code_insee_localite]
end
end

0
lib/tasks/.keep Normal file
View file