Change organisation sources for lib apicarto quartiersprioritaires
This commit is contained in:
parent
9f9e8ca176
commit
e9145b031f
6 changed files with 8 additions and 8 deletions
22
lib/carto/sgmap/quartiers_prioritaires/adapter.rb
Normal file
22
lib/carto/sgmap/quartiers_prioritaires/adapter.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
class CARTO::SGMAP::QuartiersPrioritaires::Adapter
|
||||
def initialize(coordinates)
|
||||
@coordinates = GeojsonService.to_json_polygon(coordinates)
|
||||
end
|
||||
|
||||
def data_source
|
||||
@data_source ||= JSON.parse(CARTO::SGMAP::QuartiersPrioritaires::API.search_qp(@coordinates), symbolize_names: true)
|
||||
end
|
||||
|
||||
def to_params
|
||||
params = {}
|
||||
|
||||
data_source[:features].each do |feature|
|
||||
qp_code = feature[:properties][:code]
|
||||
|
||||
params[qp_code] = feature[:properties]
|
||||
params[qp_code][:geometry] = feature[:geometry]
|
||||
end
|
||||
|
||||
params
|
||||
end
|
||||
end
|
24
lib/carto/sgmap/quartiers_prioritaires/api.rb
Normal file
24
lib/carto/sgmap/quartiers_prioritaires/api.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
class CARTO::SGMAP::QuartiersPrioritaires::API
|
||||
def initialize
|
||||
end
|
||||
|
||||
def self.search_qp(geojson)
|
||||
endpoint = "/quartiers-prioritaires/search"
|
||||
call(base_url + endpoint, {geojson: geojson.to_s})
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.call(url, params = {})
|
||||
verify_ssl_mode = OpenSSL::SSL::VERIFY_NONE
|
||||
|
||||
RestClient::Resource.new(
|
||||
url,
|
||||
verify_ssl: verify_ssl_mode,
|
||||
).post params[:geojson], content_type: 'application/json'
|
||||
end
|
||||
|
||||
def self.base_url
|
||||
'https://apicarto.sgmap.fr'
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue