From 4903a6b189d753e3d5808063c6135ec244821856 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Oct 2018 16:30:27 +0200 Subject: [PATCH 01/13] =?UTF-8?q?Carto::GeoAPI=20=E2=86=92=20ApiGeo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/lib/api_geo/driver.rb | 25 +++++++++++++++++ app/lib/{carto/geo_api => api_geo}/pays.json | 0 app/lib/carto/geo_api/driver.rb | 27 ------------------- app/models/champs/departement_champ.rb | 2 +- app/models/champs/pays_champ.rb | 2 +- app/models/champs/region_champ.rb | 2 +- ...artements.yml => api_geo_departements.yml} | 0 ...geoapi_regions.yml => api_geo_regions.yml} | 0 .../{carto/geo_api => api_geo}/driver_spec.rb | 8 +++--- 9 files changed, 32 insertions(+), 34 deletions(-) create mode 100644 app/lib/api_geo/driver.rb rename app/lib/{carto/geo_api => api_geo}/pays.json (100%) delete mode 100644 app/lib/carto/geo_api/driver.rb rename spec/fixtures/cassettes/{geoapi_departements.yml => api_geo_departements.yml} (100%) rename spec/fixtures/cassettes/{geoapi_regions.yml => api_geo_regions.yml} (100%) rename spec/lib/{carto/geo_api => api_geo}/driver_spec.rb (51%) diff --git a/app/lib/api_geo/driver.rb b/app/lib/api_geo/driver.rb new file mode 100644 index 000000000..529d4332f --- /dev/null +++ b/app/lib/api_geo/driver.rb @@ -0,0 +1,25 @@ +module ApiGeo + class Driver + def self.regions + url = [API_GEO_URL, "regions"].join("/") + call(url) + end + + def self.departements + url = [API_GEO_URL, "departements"].join("/") + call(url) + end + + def self.pays + File.open('app/lib/api_geo/pays.json').read + end + + private + + def self.call(api_url) + RestClient.get api_url, params: { fields: :nom } + rescue RestClient::ServiceUnavailable + nil + end + end +end diff --git a/app/lib/carto/geo_api/pays.json b/app/lib/api_geo/pays.json similarity index 100% rename from app/lib/carto/geo_api/pays.json rename to app/lib/api_geo/pays.json diff --git a/app/lib/carto/geo_api/driver.rb b/app/lib/carto/geo_api/driver.rb deleted file mode 100644 index 8f580cf9c..000000000 --- a/app/lib/carto/geo_api/driver.rb +++ /dev/null @@ -1,27 +0,0 @@ -module Carto - module GeoAPI - class Driver - def self.regions - url = [API_GEO_URL, "regions"].join("/") - call(url) - end - - def self.departements - url = [API_GEO_URL, "departements"].join("/") - call(url) - end - - def self.pays - File.open('app/lib/carto/geo_api/pays.json').read - end - - private - - def self.call(api_url) - RestClient.get api_url, params: { fields: :nom } - rescue RestClient::ServiceUnavailable - nil - end - end - end -end diff --git a/app/models/champs/departement_champ.rb b/app/models/champs/departement_champ.rb index 0cb4a8e68..7abf86011 100644 --- a/app/models/champs/departement_champ.rb +++ b/app/models/champs/departement_champ.rb @@ -1,5 +1,5 @@ class Champs::DepartementChamp < Champs::TextChamp def self.departements - JSON.parse(Carto::GeoAPI::Driver.departements).map { |liste| "#{liste['code']} - #{liste['nom']}" }.push('99 - Étranger') + JSON.parse(ApiGeo::Driver.departements).map { |liste| "#{liste['code']} - #{liste['nom']}" }.push('99 - Étranger') end end diff --git a/app/models/champs/pays_champ.rb b/app/models/champs/pays_champ.rb index f8204f4d0..da495e0f5 100644 --- a/app/models/champs/pays_champ.rb +++ b/app/models/champs/pays_champ.rb @@ -1,5 +1,5 @@ class Champs::PaysChamp < Champs::TextChamp def self.pays - JSON.parse(Carto::GeoAPI::Driver.pays).pluck("nom") + JSON.parse(ApiGeo::Driver.pays).pluck("nom") end end diff --git a/app/models/champs/region_champ.rb b/app/models/champs/region_champ.rb index 8c5320c29..2415a63d0 100644 --- a/app/models/champs/region_champ.rb +++ b/app/models/champs/region_champ.rb @@ -1,5 +1,5 @@ class Champs::RegionChamp < Champs::TextChamp def self.regions - JSON.parse(Carto::GeoAPI::Driver.regions).sort_by { |e| e['nom'] }.pluck("nom") + JSON.parse(ApiGeo::Driver.regions).sort_by { |e| e['nom'] }.pluck("nom") end end diff --git a/spec/fixtures/cassettes/geoapi_departements.yml b/spec/fixtures/cassettes/api_geo_departements.yml similarity index 100% rename from spec/fixtures/cassettes/geoapi_departements.yml rename to spec/fixtures/cassettes/api_geo_departements.yml diff --git a/spec/fixtures/cassettes/geoapi_regions.yml b/spec/fixtures/cassettes/api_geo_regions.yml similarity index 100% rename from spec/fixtures/cassettes/geoapi_regions.yml rename to spec/fixtures/cassettes/api_geo_regions.yml diff --git a/spec/lib/carto/geo_api/driver_spec.rb b/spec/lib/api_geo/driver_spec.rb similarity index 51% rename from spec/lib/carto/geo_api/driver_spec.rb rename to spec/lib/api_geo/driver_spec.rb index 67cd7da7c..1c8e35517 100644 --- a/spec/lib/carto/geo_api/driver_spec.rb +++ b/spec/lib/api_geo/driver_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' -describe Carto::GeoAPI::Driver do - describe '.regions', vcr: { cassette_name: 'geoapi_regions' } do +describe ApiGeo::Driver do + describe '.regions', vcr: { cassette_name: 'api_geo_regions' } do subject { described_class.regions } it { expect(subject.code).to eq 200 } end - describe '.departements', vcr: { cassette_name: 'geoapi_departements' } do + describe '.departements', vcr: { cassette_name: 'api_geo_departements' } do subject { described_class.departements } it { expect(subject.code).to eq 200 } @@ -16,6 +16,6 @@ describe Carto::GeoAPI::Driver do describe '.pays' do subject { described_class.pays } - it { is_expected.to eq File.open('app/lib/carto/geo_api/pays.json').read } + it { is_expected.to eq File.open('app/lib/api_geo/pays.json').read } end end From a7019719c2a9eae30ef6710f51177fe4db1fe949 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Oct 2018 18:18:13 +0200 Subject: [PATCH 02/13] Use parentheses --- app/lib/api_geo/driver.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/api_geo/driver.rb b/app/lib/api_geo/driver.rb index 529d4332f..c3b0c4786 100644 --- a/app/lib/api_geo/driver.rb +++ b/app/lib/api_geo/driver.rb @@ -17,7 +17,7 @@ module ApiGeo private def self.call(api_url) - RestClient.get api_url, params: { fields: :nom } + RestClient.get(api_url, params: { fields: :nom }) rescue RestClient::ServiceUnavailable nil end From d749d20bb3c53f30aa8722e610df59b6a0e14bb0 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Oct 2018 16:31:02 +0200 Subject: [PATCH 03/13] =?UTF-8?q?api=5Furl=20=E2=86=92=20url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/lib/api_geo/driver.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/lib/api_geo/driver.rb b/app/lib/api_geo/driver.rb index c3b0c4786..9f5d36077 100644 --- a/app/lib/api_geo/driver.rb +++ b/app/lib/api_geo/driver.rb @@ -16,8 +16,8 @@ module ApiGeo private - def self.call(api_url) - RestClient.get(api_url, params: { fields: :nom }) + def self.call(url) + RestClient.get(url, params: { fields: :nom }) rescue RestClient::ServiceUnavailable nil end From dac201967575ca2d49a5b8925702b9ebc2aecbf1 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Oct 2018 16:33:42 +0200 Subject: [PATCH 04/13] =?UTF-8?q?Carto::Bano=20=E2=86=92=20ApiAdresse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/ban/search_controller.rb | 2 +- app/lib/api_adresse/address_retriever.rb | 34 ++++++++++++++++++ app/lib/api_adresse/driver.rb | 20 +++++++++++ app/lib/api_adresse/point_retriever.rb | 28 +++++++++++++++ app/lib/carto/bano/address_retriever.rb | 36 ------------------- app/lib/carto/bano/driver.rb | 22 ------------ app/lib/carto/bano/point_retriever.rb | 30 ---------------- app/lib/carto/geocodeur.rb | 2 +- .../controllers/ban/search_controller_spec.rb | 8 ++--- spec/features/users/dossier_creation_spec.rb | 2 +- .../{bano_octo.yml => api_adresse_octo.yml} | 0 ...ing.yml => api_adresse_search_nothing.yml} | 0 ...g.yml => api_adresse_search_nothing_2.yml} | 0 ...paris.yml => api_adresse_search_paris.yml} | 0 ...ris.yml => api_adresse_search_paris_2.yml} | 0 ...ris.yml => api_adresse_search_paris_3.yml} | 0 .../address_retriever_spec.rb | 2 +- spec/lib/carto/geocodeur_spec.rb | 6 ++-- 18 files changed, 93 insertions(+), 99 deletions(-) create mode 100644 app/lib/api_adresse/address_retriever.rb create mode 100644 app/lib/api_adresse/driver.rb create mode 100644 app/lib/api_adresse/point_retriever.rb delete mode 100644 app/lib/carto/bano/address_retriever.rb delete mode 100644 app/lib/carto/bano/driver.rb delete mode 100644 app/lib/carto/bano/point_retriever.rb rename spec/fixtures/cassettes/{bano_octo.yml => api_adresse_octo.yml} (100%) rename spec/fixtures/cassettes/{ban_search_nothing.yml => api_adresse_search_nothing.yml} (100%) rename spec/fixtures/cassettes/{bano_search_nothing.yml => api_adresse_search_nothing_2.yml} (100%) rename spec/fixtures/cassettes/{ban_search_paris.yml => api_adresse_search_paris.yml} (100%) rename spec/fixtures/cassettes/{bano_search_paris.yml => api_adresse_search_paris_2.yml} (100%) rename spec/fixtures/cassettes/{search_ban_paris.yml => api_adresse_search_paris_3.yml} (100%) rename spec/lib/{carto/bano => api_adresse}/address_retriever_spec.rb (96%) diff --git a/app/controllers/ban/search_controller.rb b/app/controllers/ban/search_controller.rb index aee81b301..70cc7d9c7 100644 --- a/app/controllers/ban/search_controller.rb +++ b/app/controllers/ban/search_controller.rb @@ -2,7 +2,7 @@ class Ban::SearchController < ApplicationController def get request = params[:request] - json = Carto::Bano::AddressRetriever.new(request).list.map do |value| + json = ApiAdresse::AddressRetriever.new(request).list.map do |value| { label: value } end.to_json diff --git a/app/lib/api_adresse/address_retriever.rb b/app/lib/api_adresse/address_retriever.rb new file mode 100644 index 000000000..20ca589e1 --- /dev/null +++ b/app/lib/api_adresse/address_retriever.rb @@ -0,0 +1,34 @@ +module ApiAdresse + # input : address + # output : Array List label address + class AddressRetriever + def initialize(address) + @address = address + end + + def list + @list ||= convert_driver_result_to_full_address + end + + private + + def driver + @driver ||= ApiAdresse::Driver.new @address, 5 + end + + def convert_driver_result_to_full_address + result = JSON.parse(driver.call) + + if result['features'].empty? + Rails.logger.error "unable to find location for address #{@address}" + return [] + end + + result['features'].map do |feature| + feature['properties']['label'] + end + rescue TypeError, JSON::ParserError + [] + end + end +end diff --git a/app/lib/api_adresse/driver.rb b/app/lib/api_adresse/driver.rb new file mode 100644 index 000000000..71c15a18b --- /dev/null +++ b/app/lib/api_adresse/driver.rb @@ -0,0 +1,20 @@ +module ApiAdresse + # input : string (address) + # output : json + class Driver + def initialize(address, limit = 1) + @address = address + @limit = limit + end + + def call + RestClient.get api_url, params: { q: @address, limit: @limit } + rescue RestClient::ServiceUnavailable + nil + end + + def api_url + 'http://api-adresse.data.gouv.fr/search' + end + end +end diff --git a/app/lib/api_adresse/point_retriever.rb b/app/lib/api_adresse/point_retriever.rb new file mode 100644 index 000000000..71b10565f --- /dev/null +++ b/app/lib/api_adresse/point_retriever.rb @@ -0,0 +1,28 @@ +module ApiAdresse + # input : address + # output : point RGeo::Cartesian::PointImpl + class PointRetriever + def initialize(address) + @address = address + end + + def point + @point ||= convert_driver_result_to_point + end + + private + + def driver + @driver ||= ApiAdresse::Driver.new @address + end + + def convert_driver_result_to_point + result = JSON.parse(driver.call) + if result['features'].empty? + Rails.logger.error "unable to find location for address #{@address}" + return nil + end + RGeo::GeoJSON.decode(result['features'][0]['geometry'], json_parser: :json) + end + end +end diff --git a/app/lib/carto/bano/address_retriever.rb b/app/lib/carto/bano/address_retriever.rb deleted file mode 100644 index 9b29e02c2..000000000 --- a/app/lib/carto/bano/address_retriever.rb +++ /dev/null @@ -1,36 +0,0 @@ -module Carto - module Bano - # input : address - # output : Array List label address - class AddressRetriever - def initialize(address) - @address = address - end - - def list - @list ||= convert_driver_result_to_full_address - end - - private - - def driver - @driver ||= Carto::Bano::Driver.new @address, 5 - end - - def convert_driver_result_to_full_address - result = JSON.parse(driver.call) - - if result['features'].empty? - Rails.logger.error "unable to find location for address #{@address}" - return [] - end - - result['features'].map do |feature| - feature['properties']['label'] - end - rescue TypeError, JSON::ParserError - [] - end - end - end -end diff --git a/app/lib/carto/bano/driver.rb b/app/lib/carto/bano/driver.rb deleted file mode 100644 index 5d18382fb..000000000 --- a/app/lib/carto/bano/driver.rb +++ /dev/null @@ -1,22 +0,0 @@ -module Carto - module Bano - # input : string (address) - # output : json - class Driver - def initialize(address, limit = 1) - @address = address - @limit = limit - end - - def call - RestClient.get api_url, params: { q: @address, limit: @limit } - rescue RestClient::ServiceUnavailable - nil - end - - def api_url - 'http://api-adresse.data.gouv.fr/search' - end - end - end -end diff --git a/app/lib/carto/bano/point_retriever.rb b/app/lib/carto/bano/point_retriever.rb deleted file mode 100644 index 274e264e2..000000000 --- a/app/lib/carto/bano/point_retriever.rb +++ /dev/null @@ -1,30 +0,0 @@ -module Carto - module Bano - # input : address - # output : point RGeo::Cartesian::PointImpl - class PointRetriever - def initialize(address) - @address = address - end - - def point - @point ||= convert_driver_result_to_point - end - - private - - def driver - @driver ||= Carto::Bano::Driver.new @address - end - - def convert_driver_result_to_point - result = JSON.parse(driver.call) - if result['features'].empty? - Rails.logger.error "unable to find location for address #{@address}" - return nil - end - RGeo::GeoJSON.decode(result['features'][0]['geometry'], json_parser: :json) - end - end - end -end diff --git a/app/lib/carto/geocodeur.rb b/app/lib/carto/geocodeur.rb index 0d9e4f3ed..33ddf7548 100644 --- a/app/lib/carto/geocodeur.rb +++ b/app/lib/carto/geocodeur.rb @@ -2,7 +2,7 @@ module Carto # this class take a string in input and return a point class Geocodeur def self.convert_adresse_to_point(address) - Carto::Bano::PointRetriever.new(address).point + ApiAdresse::PointRetriever.new(address).point rescue RestClient::Exception, JSON::ParserError => e Rails.logger.error e.message nil diff --git a/spec/controllers/ban/search_controller_spec.rb b/spec/controllers/ban/search_controller_spec.rb index 76dfeee43..f0e381ec8 100644 --- a/spec/controllers/ban/search_controller_spec.rb +++ b/spec/controllers/ban/search_controller_spec.rb @@ -8,14 +8,14 @@ describe Ban::SearchController, type: :controller do subject end - context 'when request return result', vcr: { cassette_name: 'bano_search_paris' } do + context 'when request return result', vcr: { cassette_name: 'api_adresse_search_paris_2' } do let (:request) { 'Paris' } it { expect(response.status).to eq 200 } it { expect(response.body).to eq '[{"label":"Paris"},{"label":"Paris 63120 Courpière"},{"label":"PARIS (Vaillac) 46240 Cœur de Causse"},{"label":"Paris 40500 Saint-Sever"},{"label":"Paris Buton 37140 Bourgueil"}]' } end - context 'when request return nothing', vcr: { cassette_name: 'bano_search_nothing' } do + context 'when request return nothing', vcr: { cassette_name: 'api_adresse_search_nothing_2' } do let (:request) { 'je recherche pas grand chose' } it { expect(response.status).to eq 200 } @@ -31,13 +31,13 @@ describe Ban::SearchController, type: :controller do subject end - context 'when request return result', vcr: { cassette_name: 'ban_search_paris' } do + context 'when request return result', vcr: { cassette_name: 'api_adresse_search_paris' } do let(:request) { 'Paris' } it { expect(response.body).to eq ({ lon: '2.3469', lat: '48.8589', zoom: '14', dossier_id: dossier_id }).to_json } end - context 'when request return nothing', vcr: { cassette_name: 'ban_search_nothing' } do + context 'when request return nothing', vcr: { cassette_name: 'api_adresse_search_nothing' } do let(:request) { 'je recherche pas grand chose' } it { expect(response.body).to eq ({ lon: nil, lat: nil, zoom: '14', dossier_id: dossier_id }).to_json } diff --git a/spec/features/users/dossier_creation_spec.rb b/spec/features/users/dossier_creation_spec.rb index a1fa282c8..0784c57f2 100644 --- a/spec/features/users/dossier_creation_spec.rb +++ b/spec/features/users/dossier_creation_spec.rb @@ -61,7 +61,7 @@ feature 'As a User I wanna create a dossier' do end end - scenario 'Identification through siret', vcr: { cassette_name: 'search_ban_paris' }, js: true do + scenario 'Identification through siret', vcr: { cassette_name: 'api_adresse_search_paris_3' }, js: true do login_as user, scope: :user visit commencer_path(procedure_path: procedure_with_siret.path) expect(page).to have_current_path(users_dossier_path(procedure_with_siret.dossiers.last.id.to_s)) diff --git a/spec/fixtures/cassettes/bano_octo.yml b/spec/fixtures/cassettes/api_adresse_octo.yml similarity index 100% rename from spec/fixtures/cassettes/bano_octo.yml rename to spec/fixtures/cassettes/api_adresse_octo.yml diff --git a/spec/fixtures/cassettes/ban_search_nothing.yml b/spec/fixtures/cassettes/api_adresse_search_nothing.yml similarity index 100% rename from spec/fixtures/cassettes/ban_search_nothing.yml rename to spec/fixtures/cassettes/api_adresse_search_nothing.yml diff --git a/spec/fixtures/cassettes/bano_search_nothing.yml b/spec/fixtures/cassettes/api_adresse_search_nothing_2.yml similarity index 100% rename from spec/fixtures/cassettes/bano_search_nothing.yml rename to spec/fixtures/cassettes/api_adresse_search_nothing_2.yml diff --git a/spec/fixtures/cassettes/ban_search_paris.yml b/spec/fixtures/cassettes/api_adresse_search_paris.yml similarity index 100% rename from spec/fixtures/cassettes/ban_search_paris.yml rename to spec/fixtures/cassettes/api_adresse_search_paris.yml diff --git a/spec/fixtures/cassettes/bano_search_paris.yml b/spec/fixtures/cassettes/api_adresse_search_paris_2.yml similarity index 100% rename from spec/fixtures/cassettes/bano_search_paris.yml rename to spec/fixtures/cassettes/api_adresse_search_paris_2.yml diff --git a/spec/fixtures/cassettes/search_ban_paris.yml b/spec/fixtures/cassettes/api_adresse_search_paris_3.yml similarity index 100% rename from spec/fixtures/cassettes/search_ban_paris.yml rename to spec/fixtures/cassettes/api_adresse_search_paris_3.yml diff --git a/spec/lib/carto/bano/address_retriever_spec.rb b/spec/lib/api_adresse/address_retriever_spec.rb similarity index 96% rename from spec/lib/carto/bano/address_retriever_spec.rb rename to spec/lib/api_adresse/address_retriever_spec.rb index 8ace473f0..63b9d099b 100644 --- a/spec/lib/carto/bano/address_retriever_spec.rb +++ b/spec/lib/api_adresse/address_retriever_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Carto::Bano::AddressRetriever do +describe ApiAdresse::AddressRetriever do describe '#list' do let(:request) { 'Paris' } let(:response) { File.open('spec/support/files/ban_address_search.json') } diff --git a/spec/lib/carto/geocodeur_spec.rb b/spec/lib/carto/geocodeur_spec.rb index a9a071010..1df8adad8 100644 --- a/spec/lib/carto/geocodeur_spec.rb +++ b/spec/lib/carto/geocodeur_spec.rb @@ -2,13 +2,13 @@ require 'spec_helper' describe Carto::Geocodeur do let(:address) { '50 av des champs elysees' } - describe '.convert_adresse_to_point', vcr: { cassette_name: 'bano_octo' } do + describe '.convert_adresse_to_point', vcr: { cassette_name: 'api_adresse_octo' } do it 'return a point' do expect(described_class.convert_adresse_to_point(address).class).to eq(RGeo::Cartesian::PointImpl) end context 'when RestClient::Exception' do before do - allow_any_instance_of(Carto::Bano::Driver).to receive(:call).and_raise(RestClient::Exception) + allow_any_instance_of(ApiAdresse::Driver).to receive(:call).and_raise(RestClient::Exception) end it 'return nil' do expect(described_class.convert_adresse_to_point(address)).to be_nil @@ -16,7 +16,7 @@ describe Carto::Geocodeur do end context 'when JSON::ParserError' do before do - allow_any_instance_of(Carto::Bano::PointRetriever).to receive(:point).and_raise(JSON::ParserError) + allow_any_instance_of(ApiAdresse::PointRetriever).to receive(:point).and_raise(JSON::ParserError) end it 'return nil' do expect(described_class.convert_adresse_to_point(address)).to be_nil From ca8af0e9041e5189ed931d601ad44f4fa9a2056b Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Oct 2018 16:35:24 +0200 Subject: [PATCH 05/13] Use parentheses --- app/lib/api_adresse/address_retriever.rb | 2 +- app/lib/api_adresse/driver.rb | 2 +- app/lib/api_adresse/point_retriever.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/lib/api_adresse/address_retriever.rb b/app/lib/api_adresse/address_retriever.rb index 20ca589e1..8bbd9ab38 100644 --- a/app/lib/api_adresse/address_retriever.rb +++ b/app/lib/api_adresse/address_retriever.rb @@ -13,7 +13,7 @@ module ApiAdresse private def driver - @driver ||= ApiAdresse::Driver.new @address, 5 + @driver ||= ApiAdresse::Driver.new(@address, 5) end def convert_driver_result_to_full_address diff --git a/app/lib/api_adresse/driver.rb b/app/lib/api_adresse/driver.rb index 71c15a18b..47b8a755d 100644 --- a/app/lib/api_adresse/driver.rb +++ b/app/lib/api_adresse/driver.rb @@ -8,7 +8,7 @@ module ApiAdresse end def call - RestClient.get api_url, params: { q: @address, limit: @limit } + RestClient.get(api_url, params: { q: @address, limit: @limit }) rescue RestClient::ServiceUnavailable nil end diff --git a/app/lib/api_adresse/point_retriever.rb b/app/lib/api_adresse/point_retriever.rb index 71b10565f..a788f70ab 100644 --- a/app/lib/api_adresse/point_retriever.rb +++ b/app/lib/api_adresse/point_retriever.rb @@ -13,7 +13,7 @@ module ApiAdresse private def driver - @driver ||= ApiAdresse::Driver.new @address + @driver ||= ApiAdresse::Driver.new(@address) end def convert_driver_result_to_point From a7a6898ce3ca7c0e539919e68d61a2170ff92a90 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Oct 2018 16:36:16 +0200 Subject: [PATCH 06/13] Constantize the API Adresse URL --- app/lib/api_adresse/driver.rb | 6 +----- config/initializers/urls.rb | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/app/lib/api_adresse/driver.rb b/app/lib/api_adresse/driver.rb index 47b8a755d..37c8ed00b 100644 --- a/app/lib/api_adresse/driver.rb +++ b/app/lib/api_adresse/driver.rb @@ -8,13 +8,9 @@ module ApiAdresse end def call - RestClient.get(api_url, params: { q: @address, limit: @limit }) + RestClient.get(API_ADRESSE_URL, params: { q: @address, limit: @limit }) rescue RestClient::ServiceUnavailable nil end - - def api_url - 'http://api-adresse.data.gouv.fr/search' - end end end diff --git a/config/initializers/urls.rb b/config/initializers/urls.rb index e2b5e1e80..76d93db0b 100644 --- a/config/initializers/urls.rb +++ b/config/initializers/urls.rb @@ -1,4 +1,5 @@ # API URLs +API_ADRESSE_URL = "http://api-adresse.data.gouv.fr/search" API_CARTO_URL = "https://apicarto.sgmap.fr" API_ENTREPRISE_URL = "https://entreprise.api.gouv.fr/v2" API_GEO_URL = "https://geo.api.gouv.fr" From bf63e7d6abdbd51c8461413c43b4d7aab8ed129b Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Oct 2018 16:36:34 +0200 Subject: [PATCH 07/13] Use HTTPS for the API Adresse URL --- config/initializers/urls.rb | 2 +- spec/fixtures/cassettes/api_adresse_octo.yml | 2 +- spec/fixtures/cassettes/api_adresse_search_nothing.yml | 2 +- spec/fixtures/cassettes/api_adresse_search_nothing_2.yml | 2 +- spec/fixtures/cassettes/api_adresse_search_paris.yml | 2 +- spec/fixtures/cassettes/api_adresse_search_paris_2.yml | 2 +- spec/fixtures/cassettes/api_adresse_search_paris_3.yml | 2 +- spec/lib/api_adresse/address_retriever_spec.rb | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/config/initializers/urls.rb b/config/initializers/urls.rb index 76d93db0b..52fceb1d3 100644 --- a/config/initializers/urls.rb +++ b/config/initializers/urls.rb @@ -1,5 +1,5 @@ # API URLs -API_ADRESSE_URL = "http://api-adresse.data.gouv.fr/search" +API_ADRESSE_URL = "https://api-adresse.data.gouv.fr/search" API_CARTO_URL = "https://apicarto.sgmap.fr" API_ENTREPRISE_URL = "https://entreprise.api.gouv.fr/v2" API_GEO_URL = "https://geo.api.gouv.fr" diff --git a/spec/fixtures/cassettes/api_adresse_octo.yml b/spec/fixtures/cassettes/api_adresse_octo.yml index 9f8ac6c40..28ed2accb 100644 --- a/spec/fixtures/cassettes/api_adresse_octo.yml +++ b/spec/fixtures/cassettes/api_adresse_octo.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: http://api-adresse.data.gouv.fr/search?limit=1&q=50%20av%20des%20champs%20elysees + uri: https://api-adresse.data.gouv.fr/search?limit=1&q=50%20av%20des%20champs%20elysees body: encoding: US-ASCII string: '' diff --git a/spec/fixtures/cassettes/api_adresse_search_nothing.yml b/spec/fixtures/cassettes/api_adresse_search_nothing.yml index b2f2c63a5..d951adbfc 100644 --- a/spec/fixtures/cassettes/api_adresse_search_nothing.yml +++ b/spec/fixtures/cassettes/api_adresse_search_nothing.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: http://api-adresse.data.gouv.fr/search?limit=1&q=je%20recherche%20pas%20grand%20chose + uri: https://api-adresse.data.gouv.fr/search?limit=1&q=je%20recherche%20pas%20grand%20chose body: encoding: US-ASCII string: '' diff --git a/spec/fixtures/cassettes/api_adresse_search_nothing_2.yml b/spec/fixtures/cassettes/api_adresse_search_nothing_2.yml index 8eb0b3adf..cbb4a0f66 100644 --- a/spec/fixtures/cassettes/api_adresse_search_nothing_2.yml +++ b/spec/fixtures/cassettes/api_adresse_search_nothing_2.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: http://api-adresse.data.gouv.fr/search?limit=5&q=je%20recherche%20pas%20grand%20chose + uri: https://api-adresse.data.gouv.fr/search?limit=5&q=je%20recherche%20pas%20grand%20chose body: encoding: US-ASCII string: '' diff --git a/spec/fixtures/cassettes/api_adresse_search_paris.yml b/spec/fixtures/cassettes/api_adresse_search_paris.yml index 8de476502..ced667e17 100644 --- a/spec/fixtures/cassettes/api_adresse_search_paris.yml +++ b/spec/fixtures/cassettes/api_adresse_search_paris.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: http://api-adresse.data.gouv.fr/search?limit=1&q=Paris + uri: https://api-adresse.data.gouv.fr/search?limit=1&q=Paris body: encoding: US-ASCII string: '' diff --git a/spec/fixtures/cassettes/api_adresse_search_paris_2.yml b/spec/fixtures/cassettes/api_adresse_search_paris_2.yml index dd4aee086..5faf1cd88 100644 --- a/spec/fixtures/cassettes/api_adresse_search_paris_2.yml +++ b/spec/fixtures/cassettes/api_adresse_search_paris_2.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: http://api-adresse.data.gouv.fr/search?limit=5&q=Paris + uri: https://api-adresse.data.gouv.fr/search?limit=5&q=Paris body: encoding: US-ASCII string: '' diff --git a/spec/fixtures/cassettes/api_adresse_search_paris_3.yml b/spec/fixtures/cassettes/api_adresse_search_paris_3.yml index 40973bfb0..22eca3306 100644 --- a/spec/fixtures/cassettes/api_adresse_search_paris_3.yml +++ b/spec/fixtures/cassettes/api_adresse_search_paris_3.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: http://api-adresse.data.gouv.fr/search?limit=1&q=50%20AV%20DES%20CHAMPS%20ELYSEES%20complement_adresse%2075008%20PARIS%208 + uri: https://api-adresse.data.gouv.fr/search?limit=1&q=50%20AV%20DES%20CHAMPS%20ELYSEES%20complement_adresse%2075008%20PARIS%208 body: encoding: US-ASCII string: '' diff --git a/spec/lib/api_adresse/address_retriever_spec.rb b/spec/lib/api_adresse/address_retriever_spec.rb index 63b9d099b..80bb61a85 100644 --- a/spec/lib/api_adresse/address_retriever_spec.rb +++ b/spec/lib/api_adresse/address_retriever_spec.rb @@ -9,7 +9,7 @@ describe ApiAdresse::AddressRetriever do subject { described_class.new(request).list } before do - stub_request(:get, "http://api-adresse.data.gouv.fr/search?&q=#{request}&limit=5") + stub_request(:get, "https://api-adresse.data.gouv.fr/search?&q=#{request}&limit=5") .to_return(status: status, body: response, headers: {}) end From 9156acb839cb1dc7f7133f9ef46920272e174d9c Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Oct 2018 16:36:45 +0200 Subject: [PATCH 08/13] Use double quotes in urls.rb --- config/initializers/urls.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/initializers/urls.rb b/config/initializers/urls.rb index 52fceb1d3..c8a8e0900 100644 --- a/config/initializers/urls.rb +++ b/config/initializers/urls.rb @@ -3,11 +3,11 @@ API_ADRESSE_URL = "https://api-adresse.data.gouv.fr/search" API_CARTO_URL = "https://apicarto.sgmap.fr" API_ENTREPRISE_URL = "https://entreprise.api.gouv.fr/v2" API_GEO_URL = "https://geo.api.gouv.fr" -HELPSCOUT_API_URL = 'https://api.helpscout.net/v2' -PIPEDRIVE_API_URL = 'https://api.pipedrive.com/v1' +HELPSCOUT_API_URL = "https://api.helpscout.net/v2" +PIPEDRIVE_API_URL = "https://api.pipedrive.com/v1" # Internal URLs -FOG_BASE_URL = 'https://storage.apientreprise.fr' +FOG_BASE_URL = "https://storage.apientreprise.fr" # External services URLs DOC_URL = "https://doc.demarches-simplifiees.fr" From 442b4a241bf03a8e96fd6395fec2e1d64d65e869 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Oct 2018 16:38:17 +0200 Subject: [PATCH 09/13] Make API_ADRRESSE_URL canonical --- app/lib/api_adresse/driver.rb | 4 +++- config/initializers/urls.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/lib/api_adresse/driver.rb b/app/lib/api_adresse/driver.rb index 37c8ed00b..fadcfb2af 100644 --- a/app/lib/api_adresse/driver.rb +++ b/app/lib/api_adresse/driver.rb @@ -8,7 +8,9 @@ module ApiAdresse end def call - RestClient.get(API_ADRESSE_URL, params: { q: @address, limit: @limit }) + search_url = [API_ADRESSE_URL, "search"].join("/") + + RestClient.get(search_url, params: { q: @address, limit: @limit }) rescue RestClient::ServiceUnavailable nil end diff --git a/config/initializers/urls.rb b/config/initializers/urls.rb index c8a8e0900..c5d3c2703 100644 --- a/config/initializers/urls.rb +++ b/config/initializers/urls.rb @@ -1,5 +1,5 @@ # API URLs -API_ADRESSE_URL = "https://api-adresse.data.gouv.fr/search" +API_ADRESSE_URL = "https://api-adresse.data.gouv.fr" API_CARTO_URL = "https://apicarto.sgmap.fr" API_ENTREPRISE_URL = "https://entreprise.api.gouv.fr/v2" API_GEO_URL = "https://geo.api.gouv.fr" From d726fbf698682fb4b5659a36f8a667e2604f0bd7 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Oct 2018 16:54:38 +0200 Subject: [PATCH 10/13] =?UTF-8?q?CARTO::SGMAP=20=E2=86=92=20ApiCarto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/lib/{carto/sgmap => api_carto}/api.rb | 2 +- app/lib/{carto/sgmap => api_carto}/cadastre/adapter.rb | 4 ++-- .../sgmap => api_carto}/quartiers_prioritaires/adapter.rb | 4 ++-- app/services/module_api_carto_service.rb | 4 ++-- spec/controllers/users/carte_controller_shared_example.rb | 6 +++--- spec/lib/{carto/sgmap => api_carto}/api_spec.rb | 2 +- .../lib/{carto/sgmap => api_carto}/cadastre/adapter_spec.rb | 2 +- .../quartiers_prioritaires/adapter_spec.rb | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) rename app/lib/{carto/sgmap => api_carto}/api.rb (96%) rename app/lib/{carto/sgmap => api_carto}/cadastre/adapter.rb (79%) rename app/lib/{carto/sgmap => api_carto}/quartiers_prioritaires/adapter.rb (64%) rename spec/lib/{carto/sgmap => api_carto}/api_spec.rb (98%) rename spec/lib/{carto/sgmap => api_carto}/cadastre/adapter_spec.rb (97%) rename spec/lib/{carto/sgmap => api_carto}/quartiers_prioritaires/adapter_spec.rb (95%) diff --git a/app/lib/carto/sgmap/api.rb b/app/lib/api_carto/api.rb similarity index 96% rename from app/lib/carto/sgmap/api.rb rename to app/lib/api_carto/api.rb index 0489068f1..230fed038 100644 --- a/app/lib/carto/sgmap/api.rb +++ b/app/lib/api_carto/api.rb @@ -1,4 +1,4 @@ -class CARTO::SGMAP::API +class ApiCarto::API def initialize end diff --git a/app/lib/carto/sgmap/cadastre/adapter.rb b/app/lib/api_carto/cadastre/adapter.rb similarity index 79% rename from app/lib/carto/sgmap/cadastre/adapter.rb rename to app/lib/api_carto/cadastre/adapter.rb index 494600267..2fa40f4bc 100644 --- a/app/lib/carto/sgmap/cadastre/adapter.rb +++ b/app/lib/api_carto/cadastre/adapter.rb @@ -1,10 +1,10 @@ -class CARTO::SGMAP::Cadastre::Adapter +class ApiCarto::Cadastre::Adapter def initialize(coordinates) @coordinates = GeojsonService.to_json_polygon_for_cadastre(coordinates) end def data_source - @data_source ||= JSON.parse(CARTO::SGMAP::API.search_cadastre(@coordinates), symbolize_names: true) + @data_source ||= JSON.parse(ApiCarto::API.search_cadastre(@coordinates), symbolize_names: true) end def results diff --git a/app/lib/carto/sgmap/quartiers_prioritaires/adapter.rb b/app/lib/api_carto/quartiers_prioritaires/adapter.rb similarity index 64% rename from app/lib/carto/sgmap/quartiers_prioritaires/adapter.rb rename to app/lib/api_carto/quartiers_prioritaires/adapter.rb index ae1b7a762..9d5e62ee1 100644 --- a/app/lib/carto/sgmap/quartiers_prioritaires/adapter.rb +++ b/app/lib/api_carto/quartiers_prioritaires/adapter.rb @@ -1,10 +1,10 @@ -class CARTO::SGMAP::QuartiersPrioritaires::Adapter +class ApiCarto::QuartiersPrioritaires::Adapter def initialize(coordinates) @coordinates = GeojsonService.to_json_polygon_for_qp(coordinates) end def data_source - @data_source ||= JSON.parse(CARTO::SGMAP::API.search_qp(@coordinates), symbolize_names: true) + @data_source ||= JSON.parse(ApiCarto::API.search_qp(@coordinates), symbolize_names: true) end def results diff --git a/app/services/module_api_carto_service.rb b/app/services/module_api_carto_service.rb index 1d94e16e3..d3d920e3b 100644 --- a/app/services/module_api_carto_service.rb +++ b/app/services/module_api_carto_service.rb @@ -25,7 +25,7 @@ class ModuleApiCartoService def self.generate_qp(coordinates) coordinates.flat_map do |coordinate| - CARTO::SGMAP::QuartiersPrioritaires::Adapter.new( + ApiCarto::QuartiersPrioritaires::Adapter.new( coordinate.map { |element| [element['lng'], element['lat']] } ).results end @@ -33,7 +33,7 @@ class ModuleApiCartoService def self.generate_cadastre(coordinates) coordinates.flat_map do |coordinate| - CARTO::SGMAP::Cadastre::Adapter.new( + ApiCarto::Cadastre::Adapter.new( coordinate.map { |element| [element['lng'], element['lat']] } ).results end diff --git a/spec/controllers/users/carte_controller_shared_example.rb b/spec/controllers/users/carte_controller_shared_example.rb index 8538bc0a7..cfdf9e0e7 100644 --- a/spec/controllers/users/carte_controller_shared_example.rb +++ b/spec/controllers/users/carte_controller_shared_example.rb @@ -113,7 +113,7 @@ shared_examples 'carte_controller_spec' do let(:module_api_carto) { create(:module_api_carto, :with_quartiers_prioritaires) } before do - allow_any_instance_of(CARTO::SGMAP::QuartiersPrioritaires::Adapter) + allow_any_instance_of(ApiCarto::QuartiersPrioritaires::Adapter) .to receive(:results) .and_return([{ :code => "QPCODE1234", :nom => "QP de test", :commune => "Paris", :geometry => { :type => "MultiPolygon", :coordinates => [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]] } }]) @@ -160,7 +160,7 @@ shared_examples 'carte_controller_spec' do let(:module_api_carto) { create(:module_api_carto, :with_cadastre) } before do - allow_any_instance_of(CARTO::SGMAP::Cadastre::Adapter) + allow_any_instance_of(ApiCarto::Cadastre::Adapter) .to receive(:results) .and_return([{ :surface_intersection => "0.0006", :surface_parcelle => 11252.692583090324, :numero => "0013", :feuille => 1, :section => "CD", :code_dep => "30", :nom_com => "Le Grau-du-Roi", :code_com => "133", :code_arr => "000", :geometry => { :type => "MultiPolygon", :coordinates => [[[[4.134084, 43.5209193], [4.1346615, 43.5212035], [4.1346984, 43.521189], [4.135096, 43.5213848], [4.1350839, 43.5214122], [4.1352697, 43.521505], [4.1356278, 43.5211065], [4.1357402, 43.5207188], [4.1350935, 43.5203936], [4.135002, 43.5204366], [4.1346051, 43.5202412], [4.134584, 43.5202472], [4.1345572, 43.5202551], [4.134356, 43.5203137], [4.1342488, 43.5203448], [4.134084, 43.5209193]]]] } }]) @@ -215,7 +215,7 @@ shared_examples 'carte_controller_spec' do render_views before do - allow_any_instance_of(CARTO::SGMAP::QuartiersPrioritaires::Adapter) + allow_any_instance_of(ApiCarto::QuartiersPrioritaires::Adapter) .to receive(:results) .and_return([{ :code => "QPCODE1234", :geometry => { :type => "MultiPolygon", :coordinates => [[[[2.38715792094576, 48.8723062632126], [2.38724851642619, 48.8721392348061]]]] } }]) diff --git a/spec/lib/carto/sgmap/api_spec.rb b/spec/lib/api_carto/api_spec.rb similarity index 98% rename from spec/lib/carto/sgmap/api_spec.rb rename to spec/lib/api_carto/api_spec.rb index a13a7a571..ad3f11c95 100644 --- a/spec/lib/carto/sgmap/api_spec.rb +++ b/spec/lib/api_carto/api_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe CARTO::SGMAP::API do +describe ApiCarto::API do describe '.search_qp' do subject { described_class.search_qp(geojson) } diff --git a/spec/lib/carto/sgmap/cadastre/adapter_spec.rb b/spec/lib/api_carto/cadastre/adapter_spec.rb similarity index 97% rename from spec/lib/carto/sgmap/cadastre/adapter_spec.rb rename to spec/lib/api_carto/cadastre/adapter_spec.rb index d4e522abd..6ceab2ca9 100644 --- a/spec/lib/carto/sgmap/cadastre/adapter_spec.rb +++ b/spec/lib/api_carto/cadastre/adapter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe CARTO::SGMAP::Cadastre::Adapter do +describe ApiCarto::Cadastre::Adapter do subject { described_class.new(coordinates).results } before do diff --git a/spec/lib/carto/sgmap/quartiers_prioritaires/adapter_spec.rb b/spec/lib/api_carto/quartiers_prioritaires/adapter_spec.rb similarity index 95% rename from spec/lib/carto/sgmap/quartiers_prioritaires/adapter_spec.rb rename to spec/lib/api_carto/quartiers_prioritaires/adapter_spec.rb index e98cc3294..471be4b2b 100644 --- a/spec/lib/carto/sgmap/quartiers_prioritaires/adapter_spec.rb +++ b/spec/lib/api_carto/quartiers_prioritaires/adapter_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe CARTO::SGMAP::QuartiersPrioritaires::Adapter do +describe ApiCarto::QuartiersPrioritaires::Adapter do subject { described_class.new(coordinates).results } before do From 5e9e913dce8bb3704c9f04af1b51e3e3b2b95c52 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Oct 2018 16:56:20 +0200 Subject: [PATCH 11/13] =?UTF-8?q?Carto::Geocodeur=20=E2=86=92=20ApiAdresse?= =?UTF-8?q?::Geocodeur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/ban/search_controller.rb | 2 +- app/lib/{carto => api_adresse}/geocodeur.rb | 2 +- app/models/dossier.rb | 2 +- spec/lib/{carto => api_adresse}/geocodeur_spec.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename app/lib/{carto => api_adresse}/geocodeur.rb (94%) rename spec/lib/{carto => api_adresse}/geocodeur_spec.rb (96%) diff --git a/app/controllers/ban/search_controller.rb b/app/controllers/ban/search_controller.rb index 70cc7d9c7..1476ec9fe 100644 --- a/app/controllers/ban/search_controller.rb +++ b/app/controllers/ban/search_controller.rb @@ -10,7 +10,7 @@ class Ban::SearchController < ApplicationController end def get_address_point - point = Carto::Geocodeur.convert_adresse_to_point(params[:request]) + point = ApiAdresse::Geocodeur.convert_adresse_to_point(params[:request]) if point.present? lon = point.x.to_s diff --git a/app/lib/carto/geocodeur.rb b/app/lib/api_adresse/geocodeur.rb similarity index 94% rename from app/lib/carto/geocodeur.rb rename to app/lib/api_adresse/geocodeur.rb index 33ddf7548..04b7c5cb2 100644 --- a/app/lib/carto/geocodeur.rb +++ b/app/lib/api_adresse/geocodeur.rb @@ -1,4 +1,4 @@ -module Carto +module ApiAdresse # this class take a string in input and return a point class Geocodeur def self.convert_adresse_to_point(address) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index e5d832151..c7678231b 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -243,7 +243,7 @@ class Dossier < ApplicationRecord def geo_position if etablissement.present? - point = Carto::Geocodeur.convert_adresse_to_point(etablissement.geo_adresse) + point = ApiAdresse::Geocodeur.convert_adresse_to_point(etablissement.geo_adresse) end lon = "2.428462" diff --git a/spec/lib/carto/geocodeur_spec.rb b/spec/lib/api_adresse/geocodeur_spec.rb similarity index 96% rename from spec/lib/carto/geocodeur_spec.rb rename to spec/lib/api_adresse/geocodeur_spec.rb index 1df8adad8..39a2f724a 100644 --- a/spec/lib/carto/geocodeur_spec.rb +++ b/spec/lib/api_adresse/geocodeur_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Carto::Geocodeur do +describe ApiAdresse::Geocodeur do let(:address) { '50 av des champs elysees' } describe '.convert_adresse_to_point', vcr: { cassette_name: 'api_adresse_octo' } do it 'return a point' do From 6be26af7dbca020d4a7e99ac5bd1342e388b196f Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Oct 2018 16:57:06 +0200 Subject: [PATCH 12/13] Use parentheses --- app/lib/api_adresse/geocodeur.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/api_adresse/geocodeur.rb b/app/lib/api_adresse/geocodeur.rb index 04b7c5cb2..37953ad91 100644 --- a/app/lib/api_adresse/geocodeur.rb +++ b/app/lib/api_adresse/geocodeur.rb @@ -4,7 +4,7 @@ module ApiAdresse def self.convert_adresse_to_point(address) ApiAdresse::PointRetriever.new(address).point rescue RestClient::Exception, JSON::ParserError => e - Rails.logger.error e.message + Rails.logger.error(e.message) nil end end From 2a57c093c0e9fbfe2714080e830c4b95f5bc401e Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 15 Oct 2018 19:53:11 +0200 Subject: [PATCH 13/13] Remove a duplicated cassette --- .../cassettes/call_geo_api_departements.yml | 70 ------------------- spec/models/champ_shared_example.rb | 2 +- 2 files changed, 1 insertion(+), 71 deletions(-) delete mode 100644 spec/fixtures/cassettes/call_geo_api_departements.yml diff --git a/spec/fixtures/cassettes/call_geo_api_departements.yml b/spec/fixtures/cassettes/call_geo_api_departements.yml deleted file mode 100644 index a1ff74c3c..000000000 --- a/spec/fixtures/cassettes/call_geo_api_departements.yml +++ /dev/null @@ -1,70 +0,0 @@ ---- -http_interactions: -- request: - method: get - uri: https://geo.api.gouv.fr/departements?fields=nom - body: - encoding: US-ASCII - string: '' - headers: - Accept: - - "*/*; q=0.5, application/xml" - Accept-Encoding: - - gzip, deflate - User-Agent: - - Ruby - response: - status: - code: 200 - message: OK - headers: - Server: - - nginx - Date: - - Wed, 19 Oct 2016 09:31:34 GMT - Content-Type: - - application/json; charset=utf-8 - Transfer-Encoding: - - chunked - Connection: - - keep-alive - Vary: - - Accept-Encoding - - Accept-Encoding - X-Powered-By: - - Express - Access-Control-Allow-Origin: - - "*" - Etag: - - W/"cc1-lXUcIlpPmDfvrGONl0WWsQ" - Strict-Transport-Security: - - max-age=15552000 - Content-Encoding: - - gzip - body: - encoding: ASCII-8BIT - string: !binary |- - H4sIAAAAAAAAA22Wy27bMBBFfyXwJpsKqF96dOfYrZsibow4MFAUXTARGxOQ - xZYSjbpF/yfZ5w/0YyVlpDq0sxTmajg8vJzh1z+9Um9773oTVfbe9O51Lt3H - 237v75suUpUSsQFjRaGkQXAYBH/IKspl9FHYWkZLo3eyvGeqEdStqIomhfsJ - CccnCRfCqFptA1VMlcmbx/sN10nCsCzL4O80CKvm8YE/Z4zaO4T6b4OQQ/ef - YD8guJN7o8G3T4YX2rpqHSgb3WyaZ7LuE+dUFDuRa8Dpk99UlLUoUAHJTTfC - yLJmgUT2Eo5e2CIN2U03POw+uU21Mc3jb65AcC5cSb/Flc275IPJsQGiVgjF - BRTT5tn5KD+/huMGBN0KHMnzidlqish7aqQNliDkmTa5fuAZDAh5pu0dDmBA - xjPTPG9ZOgm/t4YhQvWhSNbRlVYsmXA/qFJVdfMY5CDeuTDAOqQvD5fPCbRz - fQd2SG5zabCrIWnNlfuRzh4S18fmyQhb1MhLXJdF0W5trQqhgtUJ7rLMubEh - ubWxFzosnwQvqxDNkOw+WSNQHqldCbczbHxEbv44/MKh50fE5iWoaURuB+zH - CrJrY9GkLtzFVT8tE5FhKwPgEdFdaUYIzkV89SfnPiK4K/07JDciuYU/s1fY - j8hwIcqg147J0LUTnvqY8A6AjhVEuBB736m7wxsT30JaU2/a+ha6ks5pEBKg - E/K6j8lvoc2d2gi05jEhniYmvc9uUuxogDHpfXadBBWR2bViQTGJXQfAYgJb - inaYujEgFEwbE9nS7r1mFnaimNyWe9M8lc2Tn7X/vcd8rwzl7p9uRzE5Ium1 - UW7SiIIXKybUC7ePmw2fGzGpel8cx8n1eEbGJHsw1UqEYzQh4UPwFVsnhL0S - 3lzdbhNSXomdVgwGLbF97JxISHXpXjAgnpDkSvpLdzqHEyI8iLzzwwuWEOSX - nSxcLi5EjjNpf0Wr1sGUkOZKbznQUmK8dSt3eFKy86FXe09KiGuBaZeS4FrY - +yK4synprWWZO/ticfJbO/exZ6TkdrDHiYTU1rp6IJCUzL6EMzQlrFtp3LvU - N+uzXJ5dyOK7NmjOGeG9r6owU3bcGdur3h5zt88s8GDrk5Vr0XU0k+55AF0I - s/CpjoySBUCFk5yHTSkj07kVuSy0/cFiguvi0tfujRJMsSy4M3O7F8FmkmAW - irOb5smWiq/kLAnauNjrmi/YzF+Jb/8A5ygzwMEMAAA= - http_version: - recorded_at: Wed, 19 Oct 2016 09:31:33 GMT -recorded_with: VCR 3.0.1 diff --git a/spec/models/champ_shared_example.rb b/spec/models/champ_shared_example.rb index 24d150196..91eeb2438 100644 --- a/spec/models/champ_shared_example.rb +++ b/spec/models/champ_shared_example.rb @@ -26,7 +26,7 @@ shared_examples 'champ_spec' do end end - describe '.departement', vcr: { cassette_name: 'call_geo_api_departements' } do + describe '.departement', vcr: { cassette_name: 'api_geo_departements' } do subject { Champs::DepartementChamp.departements } it { expect(subject).to include '99 - Étranger' }