2018-03-28 15:24:43 +02:00
|
|
|
class ApiEntreprise::RNAAdapter < ApiEntreprise::Adapter
|
2018-03-19 15:45:55 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
def get_resource
|
2018-03-29 12:16:46 +02:00
|
|
|
ApiEntreprise::API.rna(@siret, @procedure_id)
|
2018-03-19 15:45:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def process_params
|
2018-10-04 18:50:19 +02:00
|
|
|
# Sometimes the associations endpoints responses with a 206,
|
|
|
|
# and these response are often useable as the they only
|
|
|
|
# contain an error message.
|
|
|
|
# Therefore here we make sure that our response seems valid
|
|
|
|
# by checking that there is an association attribute.
|
2018-10-04 16:22:19 +02:00
|
|
|
if !data_source.key?(:association)
|
2018-03-19 14:47:56 +01:00
|
|
|
{}
|
2018-10-04 16:22:19 +02:00
|
|
|
else
|
2018-10-04 18:48:33 +02:00
|
|
|
association_id = data_source[:association][:id]
|
2018-10-04 16:22:19 +02:00
|
|
|
params = data_source[:association].slice(*attr_to_fetch)
|
|
|
|
|
2018-10-04 18:48:33 +02:00
|
|
|
if association_id.present? && valid_params?(params)
|
|
|
|
params[:rna] = association_id
|
|
|
|
params.transform_keys { |k| :"association_#{k}" }
|
2018-10-04 16:22:19 +02:00
|
|
|
else
|
|
|
|
{}
|
|
|
|
end
|
2018-02-28 17:16:03 +01:00
|
|
|
end
|
2015-12-11 10:36:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
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
|