2018-03-15 16:56:21 +01:00
|
|
|
class ApiEntreprise::EntrepriseAdapter
|
2018-03-15 12:02:45 +01:00
|
|
|
def initialize(siren, procedure_id)
|
2015-08-10 11:05:06 +02:00
|
|
|
@siren = siren
|
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 to_params
|
2018-03-15 14:41:04 +01:00
|
|
|
if data_source.present?
|
|
|
|
params = data_source[:entreprise].slice(*attr_to_fetch)
|
|
|
|
params[:date_creation] = Time.at(params[:date_creation]).to_datetime
|
|
|
|
params
|
|
|
|
else
|
2018-03-19 14:47:56 +01:00
|
|
|
{}
|
2018-03-15 14:41:04 +01:00
|
|
|
end
|
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.entreprise(@siren, @procedure_id)
|
2018-03-15 14:30:10 +01:00
|
|
|
rescue
|
|
|
|
@data_source = nil
|
|
|
|
end
|
|
|
|
|
2015-08-10 11:05:06 +02:00
|
|
|
def attr_to_fetch
|
2018-01-15 14:42:48 +01:00
|
|
|
[
|
|
|
|
: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
|
|
|
|
]
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
end
|