2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-08-05 18:40:47 +02:00
|
|
|
class APIEducation::API
|
2021-01-13 18:58:59 +01:00
|
|
|
class ResourceNotFound < StandardError
|
|
|
|
end
|
|
|
|
|
2021-01-14 23:55:34 +01:00
|
|
|
def self.get_annuaire_education(id)
|
|
|
|
call([API_EDUCATION_URL, 'search'].join('/'), 'fr-en-annuaire-education', { 'refine.identifiant_de_l_etablissement': id })
|
2021-01-13 18:58:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def self.call(url, dataset, params)
|
|
|
|
response = Typhoeus.get(url, params: { rows: 1, dataset: dataset }.merge(params))
|
|
|
|
|
|
|
|
if response.success?
|
|
|
|
response.body
|
|
|
|
else
|
|
|
|
message = response.code == 0 ? response.return_message : response.code.to_s
|
2020-08-05 18:40:47 +02:00
|
|
|
Rails.logger.error "[APIEducation] Error on #{url}: #{message}"
|
2021-01-13 18:58:59 +01:00
|
|
|
raise ResourceNotFound
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|