amelioration(api-entreprise.rna): passe a la v3 pour le endpoint RNA_RESOURCE_NAME
This commit is contained in:
parent
a20ec44841
commit
ef82149a3b
8 changed files with 190 additions and 90 deletions
|
@ -4,7 +4,7 @@ class APIEntreprise::API
|
|||
EXTRAIT_KBIS_NAME = "v3/infogreffe/rcs/unites_legales/%{id}/extrait_kbis"
|
||||
TVA_NAME = "v3/european_commission/unites_legales/%{id}/numero_tva"
|
||||
EXERCICES_RESOURCE_NAME = "v3/dgfip/etablissements/%{id}/chiffres_affaires"
|
||||
RNA_RESOURCE_NAME = "v2/associations/%{id}"
|
||||
RNA_RESOURCE_NAME = "v4/djepva/api-association/associations/open_data/%{id}"
|
||||
EFFECTIFS_RESOURCE_NAME = "v2/effectifs_mensuels_acoss_covid"
|
||||
EFFECTIFS_ANNUELS_RESOURCE_NAME = "v2/effectifs_annuels_acoss_covid/%{id}"
|
||||
ATTESTATION_SOCIALE_RESOURCE_NAME = "v4/urssaf/unites_legales/%{id}/attestation_vigilance"
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
require 'json_schemer'
|
||||
|
||||
class APIEntreprise::RNAAdapter < APIEntreprise::Adapter
|
||||
class InvalidSchemaError < ::StandardError
|
||||
def initialize(errors)
|
||||
super(errors.map(&:to_json).join("\n"))
|
||||
end
|
||||
end
|
||||
# Doc métier : https://entreprise.api.gouv.fr/catalogue/djepva/associations_open_data
|
||||
# Swagger : https://entreprise.api.gouv.fr/developpeurs/openapi#tag/Informations-generales/paths/~1v4~1djepva~1api-association~1associations~1open_data~1%7Bsiren_or_rna%7D/get
|
||||
|
||||
private
|
||||
|
||||
|
@ -14,39 +9,21 @@ class APIEntreprise::RNAAdapter < APIEntreprise::Adapter
|
|||
end
|
||||
|
||||
def process_params
|
||||
params = data_source[:association]
|
||||
return {} if params.nil?
|
||||
data = data_source[:data]
|
||||
return {} if data.nil?
|
||||
|
||||
Sentry.with_scope do |scope|
|
||||
scope.set_tags(siret: @siret)
|
||||
scope.set_extras(source: params)
|
||||
scope.set_extras(source: data)
|
||||
|
||||
params = params.slice(*attr_to_fetch) if @depreciated
|
||||
params[:rna] = data_source.dig(:association, :id)
|
||||
|
||||
if params[:rna].present? && valid_params?(params)
|
||||
params = params.transform_keys { |k| :"association_#{k}" }.deep_stringify_keys
|
||||
|
||||
raise InvalidSchemaError.new(schemer.validate(params).to_a) unless schemer.valid?(params)
|
||||
|
||||
params
|
||||
else
|
||||
{}
|
||||
end
|
||||
{
|
||||
"association_rna" => data[:rna],
|
||||
"association_titre" => data[:nom],
|
||||
"association_objet" => data[:activites][:objet],
|
||||
"association_date_creation" => data[:date_creation],
|
||||
"association_date_declaration" => data[:date_publication_journal_officiel],
|
||||
"association_date_publication" => data[:date_publication_journal_officiel]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def schemer
|
||||
@schemer ||= JSONSchemer.schema(Rails.root.join('app/schemas/association.json'))
|
||||
end
|
||||
|
||||
def attr_to_fetch
|
||||
[
|
||||
:titre,
|
||||
:objet,
|
||||
:date_creation,
|
||||
:date_declaration,
|
||||
:date_publication
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue