Carto::GeoAPI → ApiGeo
This commit is contained in:
parent
366928e803
commit
4903a6b189
9 changed files with 32 additions and 34 deletions
25
app/lib/api_geo/driver.rb
Normal file
25
app/lib/api_geo/driver.rb
Normal file
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in a new issue