demarches-normaliennes/app/lib/api_tchap/api.rb
Christophe Robillard 53dd2955e4 add tchap hs adapter
2023-05-16 09:40:53 +02:00

22 lines
489 B
Ruby

class APITchap::API
class ResourceNotFound < StandardError
end
def self.get_hs(email)
call([API_TCHAP_URL, "info?medium=email&address=#{email}"].join('/'))
end
private
def self.call(url)
response = Typhoeus.get(url)
if response.success?
response.body
else
message = response.code == 0 ? response.return_message : response.code.to_s
Rails.logger.error "[APITchap] Error on #{url}: #{message}"
raise ResourceNotFound
end
end
end