demarches-normaliennes/app/lib/api_entreprise/adapter.rb

37 lines
611 B
Ruby
Raw Normal View History

2020-08-05 18:40:47 +02:00
class APIEntreprise::Adapter
UNAVAILABLE = 'Donnée indisponible'
def initialize(siret, procedure_id)
@siret = siret
@procedure_id = procedure_id
end
def api(procedure_id = nil)
APIEntreprise::API.new(procedure_id)
end
def data_source
2019-04-30 16:36:40 +02:00
begin
@data_source ||= get_resource
2020-08-05 18:40:47 +02:00
rescue APIEntreprise::API::Error::ResourceNotFound
2019-04-30 16:36:40 +02:00
@data_source = nil
end
end
def to_params
if data_source.present?
process_params
else
{}
end
end
def valid_params?(params)
!params.has_value?(UNAVAILABLE)
end
def siren
@siret[0..8]
end
end