Add sgmap api carto driver to search qp

This commit is contained in:
Xavier J 2015-11-23 18:41:24 +01:00
parent 9b28a3f766
commit e6cc95fc5f
2 changed files with 69 additions and 0 deletions

28
lib/carto/sgmap/api.rb Normal file
View file

@ -0,0 +1,28 @@
class CARTO::SGMAP::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
if Rails.env.production?
'https://apicarto.sgmap.fr'
else
'https://apicarto.sgmap.fr'
end
end
end

View file

@ -0,0 +1,41 @@
require 'spec_helper'
describe CARTO::SGMAP::API do
describe '.search_qp' do
subject { described_class.search_qp(geojson) }
before do
stub_request(:post, "https://apicarto.sgmap.fr/quartiers-prioritaires/search").
with(:body => /.*/,
:headers => {'Content-Type'=>'application/json'}).
to_return(status: status, body: body)
end
context 'when geojson is empty' do
let(:geojson) { '' }
let(:status) { 404 }
let(:body) { '' }
it 'raises RestClient::ResourceNotFound' do
expect { subject }.to raise_error(RestClient::ResourceNotFound)
end
end
context 'when geojson exist' do
let(:geojson) { File.read('spec/support/files/geojson/request.json') }
let(:status) { 200 }
let(:body) { File.read('spec/support/files/geojson/response.json') }
it 'returns response body' do
expect(subject).to eq(body)
end
context 'when geojson is at format JSON' do
let(:geojson) { JSON.parse(File.read('spec/support/files/geojson/request.json')) }
it 'returns response body' do
expect(subject).to eq(body)
end
end
end
end
end