demarches-normaliennes/app/lib/api_entreprise/rna_adapter.rb

39 lines
946 B
Ruby
Raw Normal View History

2020-08-05 18:40:47 +02:00
class APIEntreprise::RNAAdapter < APIEntreprise::Adapter
private
def get_resource
api(@procedure_id).rna(@siret)
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.
if !data_source.key?(:association)
{}
else
association_id = data_source[:association][:id]
params = data_source[:association].slice(*attr_to_fetch)
if association_id.present? && valid_params?(params)
params[:rna] = association_id
params.transform_keys { |k| :"association_#{k}" }
else
{}
end
2018-02-28 17:16:03 +01:00
end
2015-12-11 10:36:16 +01:00
end
def attr_to_fetch
[
:titre,
:objet,
:date_creation,
:date_declaration,
:date_publication
2015-12-11 10:36:16 +01:00
]
end
end