Remove API GEO legacy adapter
This commit is contained in:
parent
6bb9c5fc20
commit
01c558953b
6 changed files with 0 additions and 180 deletions
|
@ -1,23 +0,0 @@
|
|||
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
|
|
@ -1,29 +0,0 @@
|
|||
class APICarto::CadastreAdapter
|
||||
def initialize(coordinates)
|
||||
@coordinates = GeojsonService.to_json_polygon_for_cadastre(coordinates)
|
||||
end
|
||||
|
||||
def data_source
|
||||
@data_source ||= JSON.parse(APICarto::API.search_cadastre(@coordinates), symbolize_names: true)
|
||||
end
|
||||
|
||||
def results
|
||||
data_source[:features].map do |feature|
|
||||
filter_properties(feature[:properties]).merge({ geometry: feature[:geometry] })
|
||||
end
|
||||
end
|
||||
|
||||
def filter_properties(properties)
|
||||
properties.slice(
|
||||
:surface_intersection,
|
||||
:surface_parcelle,
|
||||
:numero,
|
||||
:feuille,
|
||||
:section,
|
||||
:code_dep,
|
||||
:nom_com,
|
||||
:code_com,
|
||||
:code_arr
|
||||
)
|
||||
end
|
||||
end
|
|
@ -1,25 +0,0 @@
|
|||
class APICartoService
|
||||
def self.generate_qp(coordinates)
|
||||
coordinates.flat_map do |coordinate|
|
||||
APICarto::QuartiersPrioritairesAdapter.new(
|
||||
coordinate.map { |element| [element['lng'], element['lat']] }
|
||||
).results
|
||||
end
|
||||
end
|
||||
|
||||
def self.generate_cadastre(coordinates)
|
||||
coordinates.flat_map do |coordinate|
|
||||
APICarto::CadastreAdapter.new(
|
||||
coordinate.map { |element| [element['lng'], element['lat']] }
|
||||
).results
|
||||
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
|
|
@ -1,6 +1,5 @@
|
|||
# rubocop:disable DS/ApplicationName
|
||||
# API URLs
|
||||
API_CARTO_URL = ENV.fetch("API_CARTO_URL", "https://sandbox.geo.api.gouv.fr/apicarto")
|
||||
API_ENTREPRISE_URL = ENV.fetch("API_ENTREPRISE_URL", "https://entreprise.api.gouv.fr/v2")
|
||||
API_EDUCATION_URL = ENV.fetch("API_EDUCATION_URL", "https://data.education.gouv.fr/api/records/1.0")
|
||||
HELPSCOUT_API_URL = ENV.fetch("HELPSCOUT_API_URL", "https://api.helpscout.net/v2")
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
describe APICarto::API do
|
||||
describe '.search_cadastre' do
|
||||
subject { described_class.search_cadastre(geojson) }
|
||||
|
||||
before do
|
||||
stub_request(:post, "https://sandbox.geo.api.gouv.fr/apicarto/cadastre/geometrie")
|
||||
.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 APICarto::API::ResourceNotFound' do
|
||||
expect { subject }.to raise_error(APICarto::API::ResourceNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when geojson exist' do
|
||||
let(:geojson) { File.read('spec/fixtures/files/api_carto/request_cadastre.json') }
|
||||
let(:status) { 200 }
|
||||
let(:body) { 'toto' }
|
||||
|
||||
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/fixtures/files/api_carto/request_cadastre.json')) }
|
||||
|
||||
it 'returns response body' do
|
||||
expect(subject).to eq(body)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,63 +0,0 @@
|
|||
describe APICarto::CadastreAdapter do
|
||||
subject { described_class.new(coordinates).results }
|
||||
|
||||
before do
|
||||
stub_request(:post, "https://sandbox.geo.api.gouv.fr/apicarto/cadastre/geometrie")
|
||||
.with(:body => /.*/,
|
||||
:headers => { 'Content-Type' => 'application/json' })
|
||||
.to_return(status: status, body: body)
|
||||
end
|
||||
|
||||
context 'coordinates are filled' do
|
||||
let(:coordinates) { '[[2.252728, 43.27151][2.323223, 32.835332]]' }
|
||||
let(:status) { 200 }
|
||||
let(:body) { File.read('spec/fixtures/files/api_carto/response_cadastre.json') }
|
||||
|
||||
it { expect(subject).to be_a_instance_of(Array) }
|
||||
it { expect(subject.size).to eq(16) }
|
||||
|
||||
describe 'Attribut filter' do
|
||||
let(:adapter) { described_class.new(coordinates) }
|
||||
subject { adapter.filter_properties(adapter.data_source[:features].first[:properties]) }
|
||||
|
||||
it { expect(subject.size).to eq(9) }
|
||||
it do
|
||||
expect(subject.keys).to eq([
|
||||
:surface_intersection,
|
||||
:surface_parcelle,
|
||||
:numero,
|
||||
:feuille,
|
||||
:section,
|
||||
:code_dep,
|
||||
:nom_com,
|
||||
:code_com,
|
||||
:code_arr
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Attributes' do
|
||||
subject { super().first }
|
||||
|
||||
it { expect(subject[:surface_intersection]).to eq('0.0202') }
|
||||
it { expect(subject[:surface_parcelle]).to eq(220.0664659755941) }
|
||||
it { expect(subject[:numero]).to eq('0082') }
|
||||
it { expect(subject[:feuille]).to eq(1) }
|
||||
it { expect(subject[:section]).to eq('0J') }
|
||||
it { expect(subject[:code_dep]).to eq('94') }
|
||||
it { expect(subject[:nom_com]).to eq('Maisons-Alfort') }
|
||||
it { expect(subject[:code_com]).to eq('046') }
|
||||
it { expect(subject[:code_arr]).to eq('000') }
|
||||
|
||||
it { expect(subject[:geometry]).to eq({ type: "MultiPolygon", coordinates: [[[[2.4362443, 48.8092078], [2.436384, 48.8092043], [2.4363802, 48.8091414]]]] }) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'coordinates are empty' do
|
||||
let(:coordinates) { '' }
|
||||
let(:status) { 404 }
|
||||
let(:body) { '' }
|
||||
|
||||
it { expect { subject }.to raise_error(APICarto::API::ResourceNotFound) }
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue