Skip to content

Commit

Permalink
Add town as preferred city fallback for OpenCage
Browse files Browse the repository at this point in the history
  • Loading branch information
dsantosmerino committed Jan 27, 2020
1 parent 59a88f3 commit 732b1b9
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
47 changes: 47 additions & 0 deletions fixtures/vcr_cassettes/opencage_reverse_cerdanyola.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/geokit/geocoders/opencage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def self.set_address_components(address_data, loc)
loc.state_name = address_data['state']
loc.county = address_data['county']
loc.city = address_data['city']
loc.city = address_data['town'] if loc.city.nil? && address_data['town']
loc.city = address_data['county'] if loc.city.nil? && address_data['county']
loc.zip = address_data['postcode']
loc.district = address_data['city_district']
Expand Down
24 changes: 24 additions & 0 deletions test/test_opencage_geocoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,30 @@ def test_opencage_reverse2
assert_equal 'Прилепски Бранители', res.street_address
end

def test_opencage_cerdanyola
location = Geokit::GeoLoc.new
location.lat, location.lng = '41.493588', '2.141879'

url = "#{@base_url}?key=someopencageapikey&query=41.493588%2C2.141879&no_annotations=1"
TestHelper.expects(:last_url).with(url)
res = geocode(location.ll, :opencage_reverse_cerdanyola)

assert_equal 'ES', res.country_code
assert_equal 'opencage', res.provider

assert_equal 'Sant Martí', res.neighborhood
assert_equal 'Catalonia', res.state
assert_equal 'Vallès Occidental', res.county
assert_equal 'Cerdanyola Del Vallès', res.city

assert_equal 'Spain', res.country
assert_equal 9, res.precision
assert_equal true, res.success

assert_equal 'Passeig De La Riera, Cerdanyola Del Vallès, Catalonia, 08290, ES', res.full_address
assert_equal 'Passeig De La Riera', res.street_address
end

# check if the results are in Spanish if &language=es
def test_language_response
url = "#{@base_url}?key=someopencageapikey&language=es&query=London&no_annotations=1"
Expand Down

0 comments on commit 732b1b9

Please sign in to comment.