demarches-normaliennes/app/lib/api_carto/api.rb
Pierre de La Morinerie 150ddab660 zeitwerk: Api -> API
2021-02-09 13:07:30 +01:00

23 lines
591 B
Ruby

class APICarto::API
class ResourceNotFound < StandardError
end
def self.search_cadastre(geojson)
url = [API_CARTO_URL, "cadastre", "geometrie"].join("/")
call(url, geojson)
end
private
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}"
raise ResourceNotFound
end
end
end