Add ApiGeo RPG adapter

This commit is contained in:
Paul Chavard 2018-10-23 15:37:13 +02:00
parent ed46e2c3be
commit 7ffbe417f9
5 changed files with 49 additions and 0 deletions

View file

@ -15,6 +15,11 @@ class ApiGeo::API
parse(File.open('app/lib/api_geo/pays.json').read) parse(File.open('app/lib/api_geo/pays.json').read)
end end
def self.search_rpg(geojson)
url = [API_GEO_SANDBOX_URL, "rpg", "parcelles", "search"].join("/")
call(url, geojson, :post)
end
private private
def self.parse(body) def self.parse(body)

View file

@ -0,0 +1,24 @@
class ApiGeo::RPGAdapter
def initialize(coordinates)
@coordinates = GeojsonService.to_json_polygon_for_rpg(coordinates)
end
def data_source
@data_source ||= ApiGeo::API.search_rpg(@coordinates)
end
def results
data_source[:features].map do |feature|
feature[:properties]
.stringify_keys
.transform_keys(&:underscore)
.symbolize_keys
.slice(
:culture,
:code_culture,
:surface,
:bio
).merge({ geometry: feature[:geometry] })
end
end
end

View file

@ -25,4 +25,15 @@ class GeojsonService
polygon.to_json polygon.to_json
end end
def self.to_json_polygon_for_rpg(coordinates)
polygon = {
polygonIntersects: {
type: "Polygon",
coordinates: [coordinates]
}
}
polygon.to_json
end
end end

View file

@ -38,4 +38,12 @@ class ModuleApiCartoService
).results ).results
end end
end end
def self.generate_rpg(coordinates)
coordinates.flat_map do |coordinate|
ApiGeo::RPGAdapter.new(
coordinate.map { |element| [element['lng'], element['lat']] }
).results
end
end
end end

View file

@ -3,6 +3,7 @@ API_ADRESSE_URL = "https://api-adresse.data.gouv.fr"
API_CARTO_URL = "https://apicarto.sgmap.fr" API_CARTO_URL = "https://apicarto.sgmap.fr"
API_ENTREPRISE_URL = "https://entreprise.api.gouv.fr/v2" API_ENTREPRISE_URL = "https://entreprise.api.gouv.fr/v2"
API_GEO_URL = "https://geo.api.gouv.fr" API_GEO_URL = "https://geo.api.gouv.fr"
API_GEO_SANDBOX_URL = "https://sandbox.geo.api.gouv.fr"
HELPSCOUT_API_URL = "https://api.helpscout.net/v2" HELPSCOUT_API_URL = "https://api.helpscout.net/v2"
PIPEDRIVE_API_URL = "https://api.pipedrive.com/v1" PIPEDRIVE_API_URL = "https://api.pipedrive.com/v1"