demarches-normaliennes/app/lib/api_carto/api.rb

24 lines
591 B
Ruby
Raw Normal View History

2018-10-15 16:54:38 +02:00
class ApiCarto::API
2020-03-05 13:50:38 +01:00
class ResourceNotFound < StandardError
end
def self.search_cadastre(geojson)
2018-05-22 17:38:33 +02:00
url = [API_CARTO_URL, "cadastre", "geometrie"].join("/")
2018-10-15 15:48:46 +02:00
call(url, geojson)
end
private
2018-10-15 15:48:46 +02:00
def self.call(url, geojson)
response = Typhoeus.post(url, body: geojson.to_s, headers: { 'content-type' => 'application/json' })
if response.success?
response.body
else
message = response.code == 0 ? response.return_message : response.code.to_s
Rails.logger.error "[ApiCarto] Error on #{url}: #{message}"
2020-03-05 13:50:38 +01:00
raise ResourceNotFound
end
end
end