fix(api_geo): include Paris, Lyon and Marseille code INSEE in local data
This commit is contained in:
parent
f0053af54f
commit
378e15e083
3 changed files with 18 additions and 4 deletions
|
@ -70,6 +70,7 @@ class APIGeoService
|
||||||
|
|
||||||
def communes_by_postal_code(postal_code)
|
def communes_by_postal_code(postal_code)
|
||||||
communes_by_postal_code_map.fetch(postal_code, [])
|
communes_by_postal_code_map.fetch(postal_code, [])
|
||||||
|
.filter { !_1[:code].in?(['75056', '13055', '69123']) }
|
||||||
.sort_by { I18n.transliterate([_1[:name], _1[:postal_code]].join(' ')) }
|
.sort_by { I18n.transliterate([_1[:name], _1[:postal_code]].join(' ')) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,7 @@ namespace :api_geo_data do
|
||||||
data = []
|
data = []
|
||||||
PATH.join("#{filename}.json").open('w') do |f|
|
PATH.join("#{filename}.json").open('w') do |f|
|
||||||
response = Typhoeus.get("#{API_GEO_URL}/#{query}")
|
response = Typhoeus.get("#{API_GEO_URL}/#{query}")
|
||||||
json = JSON.parse(response.body).map(&:symbolize_keys).filter do |result|
|
json = JSON.parse(response.body).map(&:symbolize_keys).flat_map do |result|
|
||||||
!result[:code].in?(['75056', '13055', '69123'])
|
|
||||||
end.flat_map do |result|
|
|
||||||
item = {
|
item = {
|
||||||
name: result[:nom].tr("'", '’'),
|
name: result[:nom].tr("'", '’'),
|
||||||
code: result[:code],
|
code: result[:code],
|
||||||
|
@ -42,7 +40,7 @@ namespace :api_geo_data do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
data = json
|
data = json
|
||||||
f << JSON.dump(json)
|
f << JSON.pretty_generate(json.sort_by { _1[:code] })
|
||||||
end
|
end
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,6 +59,21 @@ describe APIGeoService do
|
||||||
describe 'commune_name' do
|
describe 'commune_name' do
|
||||||
subject { APIGeoService.commune_name('01', '01457') }
|
subject { APIGeoService.commune_name('01', '01457') }
|
||||||
it { is_expected.to eq('Vonnas') }
|
it { is_expected.to eq('Vonnas') }
|
||||||
|
|
||||||
|
context 'Paris' do
|
||||||
|
subject { APIGeoService.commune_name('75', '75056') }
|
||||||
|
it { is_expected.to eq('Paris') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'Lyon' do
|
||||||
|
subject { APIGeoService.commune_name('69', '69123') }
|
||||||
|
it { is_expected.to eq('Lyon') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'Marseille' do
|
||||||
|
subject { APIGeoService.commune_name('13', '13055') }
|
||||||
|
it { is_expected.to eq('Marseille') }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'commune_code' do
|
describe 'commune_code' do
|
||||||
|
|
Loading…
Add table
Reference in a new issue