2018-03-15 16:56:21 +01:00
|
|
|
class ApiEntreprise::EtablissementAdapter
|
2018-03-15 12:02:45 +01:00
|
|
|
def initialize(siret, procedure_id)
|
2015-08-10 11:05:06 +02:00
|
|
|
@siret = siret
|
2018-03-15 12:02:45 +01:00
|
|
|
@procedure_id = procedure_id
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
2018-02-21 16:29:22 +01:00
|
|
|
def success?
|
|
|
|
data_source
|
2018-02-28 17:16:03 +01:00
|
|
|
rescue
|
2018-02-21 16:29:22 +01:00
|
|
|
false
|
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2018-02-21 16:29:22 +01:00
|
|
|
def to_params
|
|
|
|
params = data_source[:etablissement].slice(*attr_to_fetch)
|
|
|
|
adresse_line = params[:adresse].slice(*address_lines_to_fetch).values.compact.join("\r\n")
|
|
|
|
params.merge!(params[:adresse].slice(*address_attr_to_fetch))
|
|
|
|
params[:adresse] = adresse_line
|
2015-08-10 11:05:06 +02:00
|
|
|
params
|
2016-09-16 17:08:50 +02:00
|
|
|
rescue
|
|
|
|
nil
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
2018-02-21 16:29:22 +01:00
|
|
|
private
|
|
|
|
|
2018-03-15 14:30:10 +01:00
|
|
|
def data_source
|
2018-03-15 16:56:21 +01:00
|
|
|
@data_source ||= ApiEntreprise::API.etablissement(@siret, @procedure_id)
|
2018-03-15 14:30:10 +01:00
|
|
|
end
|
|
|
|
|
2015-08-10 11:05:06 +02:00
|
|
|
def attr_to_fetch
|
2018-01-15 14:42:48 +01:00
|
|
|
[
|
2018-02-21 16:29:22 +01:00
|
|
|
:adresse,
|
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
|
|
|
|
|
2018-02-21 16:29:22 +01:00
|
|
|
def address_attr_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
|
2018-02-21 16:29:22 +01:00
|
|
|
|
|
|
|
def address_lines_to_fetch
|
|
|
|
[:l1, :l2, :l3, :l4, :l5, :l6, :l7]
|
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|