2022-09-22 17:13:53 +02:00
|
|
|
require 'json_schemer'
|
|
|
|
|
2020-08-05 18:40:47 +02:00
|
|
|
class APIEntreprise::RNAAdapter < APIEntreprise::Adapter
|
2022-09-22 17:13:53 +02:00
|
|
|
class InvalidSchemaError < ::StandardError
|
|
|
|
def initialize(errors)
|
|
|
|
super(errors.map(&:to_json).join("\n"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-19 15:45:55 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
def get_resource
|
2022-07-20 14:52:17 +02:00
|
|
|
api(@procedure_id).rna(@siret)
|
2018-03-19 15:45:55 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def process_params
|
2022-10-04 19:59:39 +02:00
|
|
|
params = data_source[:association]
|
2023-01-11 12:12:24 +01:00
|
|
|
|
|
|
|
Sentry.with_scope do |scope|
|
|
|
|
scope.set_tags(siret: @siret)
|
|
|
|
scope.set_extras(source: params)
|
|
|
|
|
|
|
|
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
|
2018-02-28 17:16:03 +01:00
|
|
|
end
|
2015-12-11 10:36:16 +01:00
|
|
|
end
|
|
|
|
|
2022-09-22 17:13:53 +02:00
|
|
|
def schemer
|
|
|
|
@schemer ||= JSONSchemer.schema(Rails.root.join('app/schemas/association.json'))
|
|
|
|
end
|
|
|
|
|
2015-12-11 10:36:16 +01:00
|
|
|
def attr_to_fetch
|
2018-01-15 14:42:48 +01:00
|
|
|
[
|
|
|
|
:titre,
|
|
|
|
:objet,
|
|
|
|
:date_creation,
|
|
|
|
:date_declaration,
|
|
|
|
:date_publication
|
2015-12-11 10:36:16 +01:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|