2018-03-15 16:56:21 +01:00
|
|
|
class ApiEntreprise::RNAAdapter
|
2018-03-15 12:02:45 +01:00
|
|
|
def initialize(siret, procedure_id)
|
2016-01-20 10:34:22 +01:00
|
|
|
@siret = siret
|
2018-03-15 12:02:45 +01:00
|
|
|
@procedure_id = procedure_id
|
2015-12-11 10:36:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_params
|
2018-03-19 22:25:15 +01:00
|
|
|
if data_source.present? && data_source[:association][:id].present?
|
2018-03-15 14:41:04 +01:00
|
|
|
params = data_source[:association].slice(*attr_to_fetch)
|
|
|
|
params[:rna] = data_source[:association][:id]
|
|
|
|
params
|
|
|
|
else
|
2018-03-19 14:47:56 +01:00
|
|
|
{}
|
2018-02-28 17:16:03 +01:00
|
|
|
end
|
2015-12-11 10:36:16 +01: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.rna(@siret, @procedure_id)
|
2018-03-19 14:43:47 +01:00
|
|
|
rescue
|
|
|
|
@data_source = nil
|
2018-03-15 14:30:10 +01:00
|
|
|
end
|
|
|
|
|
2015-12-11 10:36:16 +01:00
|
|
|
def attr_to_fetch
|
2018-01-15 14:42:48 +01:00
|
|
|
[
|
|
|
|
:titre,
|
|
|
|
:objet,
|
|
|
|
:date_creation,
|
|
|
|
:date_declaration,
|
|
|
|
:date_publication
|
2015-12-11 10:36:16 +01:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|