2015-08-10 11:05:06 +02:00
|
|
|
class SIADE::EntrepriseAdapter
|
|
|
|
def initialize(siren)
|
|
|
|
@siren = siren
|
|
|
|
end
|
|
|
|
|
|
|
|
def data_source
|
2016-11-01 22:56:58 +01:00
|
|
|
@data_source ||= JSON.parse(SIADE::API.entreprise(@siren), symbolize_names: true)
|
|
|
|
rescue
|
|
|
|
@data_source = nil
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
2018-02-21 16:29:22 +01:00
|
|
|
def success?
|
|
|
|
data_source
|
|
|
|
rescue
|
|
|
|
false
|
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2018-02-21 16:29:22 +01:00
|
|
|
def to_params
|
|
|
|
params = data_source[:entreprise].slice(*attr_to_fetch)
|
2016-01-28 11:29:44 +01:00
|
|
|
params[:date_creation] = Time.at(params[:date_creation]).to_datetime
|
2015-08-10 11:05:06 +02:00
|
|
|
params
|
|
|
|
rescue
|
2016-11-01 22:56:58 +01:00
|
|
|
nil
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
2018-02-21 16:29:22 +01:00
|
|
|
private
|
|
|
|
|
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,
|
2018-02-22 16:53:29 +01:00
|
|
|
:mandataires_sociaux,
|
2018-01-15 14:42:48 +01:00
|
|
|
:nom_commercial,
|
|
|
|
:raison_sociale,
|
|
|
|
:siret_siege_social,
|
|
|
|
:code_effectif_entreprise,
|
|
|
|
:date_creation,
|
|
|
|
:nom,
|
|
|
|
:prenom
|
|
|
|
]
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
end
|