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

34 lines
969 B
Ruby
Raw Normal View History

2020-08-05 18:40:47 +02:00
class APIEntreprise::ExercicesAdapter < APIEntreprise::Adapter
2023-05-29 16:45:21 +02:00
# Doc métier : https://entreprise.api.gouv.fr/catalogue/dgfip/chiffres_affaires
# Swagger : https://entreprise.api.gouv.fr/developpeurs/openapi#tag/Informations-financieres/paths/~1v3~1dgfip~1etablissements~1%7Bsiret%7D~1chiffres_affaires/get
2018-02-21 16:29:22 +01:00
private
def get_resource
api(@procedure_id).exercices(@siret)
2018-03-15 14:30:10 +01:00
end
def process_params
2023-05-29 16:45:21 +02:00
data = data_source[:data]
Sentry.with_scope do |scope|
scope.set_tags(siret: @siret)
scope.set_extras(source: data)
2023-05-29 16:45:21 +02:00
if data
exercices_array = data.map do |exercice|
{
ca: exercice[:data][:chiffre_affaires].to_s,
date_fin_exercice: Date.parse(exercice[:data][:date_fin_exercice])
}
end
2023-05-29 16:45:21 +02:00
if exercices_array.all? { |params| valid_params?(params) }
{ exercices_attributes: exercices_array }
else
{}
end
end
end
end
2017-04-04 15:27:04 +02:00
end