2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-08-05 18:40:47 +02:00
|
|
|
class APIEntreprise::EffectifsAnnuelsAdapter < APIEntreprise::Adapter
|
2023-10-17 13:26:21 +02:00
|
|
|
def initialize(siret, procedure_id, year = default_year)
|
2020-05-14 14:41:54 +02:00
|
|
|
@siret = siret
|
2020-04-22 17:53:45 +02:00
|
|
|
@procedure_id = procedure_id
|
2023-10-17 13:26:21 +02:00
|
|
|
@year = year
|
2020-04-22 17:53:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2023-10-17 13:26:21 +02:00
|
|
|
def default_year
|
|
|
|
Date.current.year - 1
|
|
|
|
end
|
|
|
|
|
2020-04-22 17:53:45 +02:00
|
|
|
def get_resource
|
2023-10-17 13:26:21 +02:00
|
|
|
api(@procedure_id).effectifs_annuels(siren, @year)
|
2020-04-22 17:53:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def process_params
|
2023-10-17 13:26:21 +02:00
|
|
|
data = data_source.fetch(:data, nil)
|
|
|
|
Sentry.with_scope do |scope|
|
|
|
|
scope.set_tags(siret: @siret)
|
|
|
|
scope.set_extras(source: data)
|
|
|
|
effectifs = data&.fetch(:effectifs_annuel, nil)&.first
|
|
|
|
if effectifs.present?
|
|
|
|
{
|
|
|
|
entreprise_effectif_annuel: effectifs[:value],
|
2024-02-29 12:58:31 +01:00
|
|
|
entreprise_effectif_annuel_annee: data[:annee]
|
2023-10-17 13:26:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{}
|
|
|
|
end
|
2020-04-22 17:53:45 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|