2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-08-05 18:40:47 +02:00
|
|
|
class APIEntreprise::EtablissementAdapter < APIEntreprise::Adapter
|
2023-05-30 16:27:20 +02:00
|
|
|
# Doc Métier : https://entreprise.api.gouv.fr/catalogue/insee/etablissements
|
|
|
|
# Swagger : https://entreprise.api.gouv.fr/developpeurs/openapi#tag/Informations-generales/paths/~1v3~1insee~1sirene~1etablissements~1%7Bsiret%7D/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).etablissement(@siret)
|
2018-03-15 14:30:10 +01:00
|
|
|
end
|
|
|
|
|
2018-03-19 15:45:55 +01:00
|
|
|
def process_params
|
2023-05-30 16:27:20 +02:00
|
|
|
raw_data = data_source[:data]
|
|
|
|
Sentry.with_scope do |scope|
|
|
|
|
scope.set_tags(siret: @siret)
|
|
|
|
scope.set_extras(source: raw_data)
|
|
|
|
|
|
|
|
params = raw_data.slice(*attr_to_fetch)
|
|
|
|
params[:naf] = raw_data.dig(:activite_principale, :code)
|
|
|
|
params[:libelle_naf] = raw_data.dig(:activite_principale, :libelle)
|
|
|
|
|
|
|
|
if valid_params?(params)
|
|
|
|
adresse_line = raw_data[:adresse][:acheminement_postal].slice(*address_lines_to_fetch).values.compact.join("\r\n")
|
|
|
|
params.merge!(params[:adresse].slice(*address_attr_to_fetch))
|
|
|
|
params[:nom_voie] = raw_data[:adresse][:libelle_voie]
|
|
|
|
params[:code_insee_localite] = raw_data[:adresse][:code_commune]
|
|
|
|
params[:localite] = raw_data[:adresse][:libelle_commune]
|
|
|
|
params[:adresse] = adresse_line
|
|
|
|
params
|
|
|
|
else
|
|
|
|
{}
|
|
|
|
end
|
2018-10-04 16:22:19 +02:00
|
|
|
end
|
2018-03-19 15:45:55 +01:00
|
|
|
end
|
|
|
|
|
2015-08-10 11:05:06 +02:00
|
|
|
def attr_to_fetch
|
2018-01-15 14:42:48 +01:00
|
|
|
[
|
2018-02-21 16:29:22 +01:00
|
|
|
:adresse,
|
2018-01-15 14:42:48 +01:00
|
|
|
:siret,
|
|
|
|
:siege_social,
|
2020-08-20 10:21:34 +02:00
|
|
|
:enseigne,
|
2020-03-04 17:12:50 +01:00
|
|
|
:diffusable_commercialement
|
2015-08-20 16:46:46 +02:00
|
|
|
]
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
|
|
|
|
2018-02-21 16:29:22 +01:00
|
|
|
def address_attr_to_fetch
|
2018-01-15 14:42:48 +01:00
|
|
|
[
|
|
|
|
:numero_voie,
|
|
|
|
:type_voie,
|
|
|
|
:complement_adresse,
|
2023-05-30 16:27:20 +02:00
|
|
|
:code_postal
|
2018-01-15 14:42:48 +01:00
|
|
|
]
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
2018-02-21 16:29:22 +01:00
|
|
|
|
|
|
|
def address_lines_to_fetch
|
|
|
|
[:l1, :l2, :l3, :l4, :l5, :l6, :l7]
|
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|