2015-08-10 11:05:06 +02:00
|
|
|
class SIADE::EtablissementAdapter
|
|
|
|
def initialize(siret)
|
|
|
|
@siret = siret
|
|
|
|
end
|
|
|
|
|
|
|
|
def data_source
|
2015-08-17 15:53:35 +02:00
|
|
|
@data_source ||= JSON.parse(SIADE::API.etablissement(@siret), symbolize_names: true)
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_params
|
|
|
|
params = {}
|
|
|
|
|
2015-08-20 16:46:46 +02:00
|
|
|
data_source[:etablissement].each do |k, v|
|
|
|
|
params[k] = v if attr_to_fetch.include?(k)
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
params[:adresse] = adresse
|
2015-08-20 16:46:46 +02:00
|
|
|
data_source[:etablissement][:adresse].each do |k, v|
|
|
|
|
params[k] = v if address_attribut_to_fetch.include?(k)
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
params
|
2016-09-16 17:08:50 +02:00
|
|
|
rescue
|
|
|
|
nil
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def attr_to_fetch
|
2018-01-15 14:42:48 +01:00
|
|
|
[
|
|
|
|
:siret,
|
|
|
|
:siege_social,
|
|
|
|
:naf,
|
|
|
|
:libelle_naf
|
2015-08-20 16:46:46 +02:00
|
|
|
]
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def adresse
|
2018-01-30 15:16:02 +01:00
|
|
|
[:l1, :l2, :l3, :l4, :l5, :l6, :l7].map do |line|
|
|
|
|
data_source[:etablissement][:adresse][line]
|
|
|
|
end.compact.join("\r\n")
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def address_attribut_to_fetch
|
2018-01-15 14:42:48 +01:00
|
|
|
[
|
|
|
|
:numero_voie,
|
|
|
|
:type_voie,
|
|
|
|
:nom_voie,
|
|
|
|
:complement_adresse,
|
|
|
|
:code_postal,
|
|
|
|
:localite,
|
|
|
|
:code_insee_localite
|
|
|
|
]
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
end
|