Skip to content

Commit

Permalink
Merge pull request #335 from dbartenstein/feature/opencage_language_p…
Browse files Browse the repository at this point in the history
…aram

Fix #334: Add language parameter for OpenCage
  • Loading branch information
DenisCarriere committed Feb 17, 2018
2 parents 0a932e7 + 713cb69 commit dfc268c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion geocoder/opencage.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,16 @@ class OpenCageQuery(MultipleResultsQuery):
_KEY = opencage_key

def _build_params(self, location, provider_key, **kwargs):
return {
base_params = {
'query': location,
'key': provider_key,
'limit': kwargs.get('maxRows', 1)
}
language = kwargs.get('language', None)
if language:
base_params['language'] = language

return base_params

def _catch_errors(self, json_response):
status = json_response.get('status')
Expand Down
13 changes: 13 additions & 0 deletions tests/test_opencage.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ def test_issue_292():
g = geocoder.opencage('AirportClinic M - MediCare Flughafen München Medizinisches Zentrum', countrycode='DE', language='de', no_annotations=1)
assert g.ok

def test_opencage_no_language_param():
""" Expected result :
https://api.opencagedata.com/geocode/v1/json=Ottawa,Ontario&key=YOUR-API-KEY
"""
g = geocoder.opencage(location)
assert 'language' not in g.url

def test_opencage_language_param():
""" Expected result :
https://api.opencagedata.com/geocode/v1/json=Ottawa,Ontario&key=YOUR-API-KEY&language=de
"""
g = geocoder.opencage(location, language='de')
assert 'language=de' in g.url.split('&')

def test_opencage_multi_result():
g = geocoder.opencage(location, maxRows=5)
Expand Down

0 comments on commit dfc268c

Please sign in to comment.