2018-10-15 16:54:38 +02:00
|
|
|
class ApiCarto::API
|
2020-03-05 13:50:38 +01:00
|
|
|
class ResourceNotFound < StandardError
|
|
|
|
end
|
|
|
|
|
2016-01-12 17:24:42 +01:00
|
|
|
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)
|
2016-01-12 17:24:42 +01:00
|
|
|
end
|
|
|
|
|
2015-11-23 18:41:24 +01:00
|
|
|
private
|
|
|
|
|
2018-10-15 15:48:46 +02:00
|
|
|
def self.call(url, geojson)
|
2019-11-05 14:18:58 +01:00
|
|
|
response = Typhoeus.post(url, body: geojson.to_s, headers: { 'content-type' => 'application/json' })
|
2016-12-20 12:27:53 +01:00
|
|
|
|
2019-11-05 14:18:58 +01:00
|
|
|
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
|
2019-11-05 14:18:58 +01:00
|
|
|
end
|
2015-11-23 18:41:24 +01:00
|
|
|
end
|
|
|
|
end
|