2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
|
|
|
|
2018-03-19 15:05:56 +01:00
|
|
|
def get_resource
|
2022-07-20 14:52:17 +02:00
|
|
|
api(@procedure_id).exercices(@siret)
|
2018-03-15 14:30:10 +01:00
|
|
|
end
|
|
|
|
|
2018-03-19 15:45:55 +01:00
|
|
|
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)
|
2018-03-19 15:45:55 +01:00
|
|
|
|
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
|
2018-03-19 15:45:55 +01:00
|
|
|
|
2023-05-29 16:45:21 +02:00
|
|
|
if exercices_array.all? { |params| valid_params?(params) }
|
|
|
|
{ exercices_attributes: exercices_array }
|
|
|
|
else
|
|
|
|
{}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-11-16 11:23:29 +01:00
|
|
|
end
|
2017-04-04 15:27:04 +02:00
|
|
|
end
|