Skip to content

Commit

Permalink
Merge pull request #1591 from Intrepidd/geoapify-autocomplete
Browse files Browse the repository at this point in the history
Allow geoapify lookup to perform autocomplete query
  • Loading branch information
alexreisner committed Sep 18, 2022
2 parents c3e3a8d + c117350 commit 9e91043
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
11 changes: 6 additions & 5 deletions README_API_GUIDE.md
Expand Up @@ -107,6 +107,7 @@ Data Science Toolkit provides an API whose response format is like Google's but
* **Languages**: The preferred language of address elements in the result. Language code must be provided according to ISO 639-1 2-character language codes.
* **Extra query options**:
* `:limit` - restrict the maximum amount of returned results, e.g. `limit: 5`
* `:autocomplete` - Use the automplete API, only when doing forward geocoding e.g. `autocomplete: true`
* **Extra params** (see [Geoapify documentation](https://apidocs.geoapify.com/docs/geocoding) for more information)
* `:type` - restricts the type of the results, see API documentation for
available types, e.g. `params: { type: 'amenity' }`
Expand Down Expand Up @@ -711,14 +712,14 @@ IP Address Lookups
### 2GIS (`:twogis`)

* **API key**: required
* **Key signup**:
* **Quota**:
* **Region**:
* **Key signup**:
* **Quota**:
* **Region**:
* **SSL support**: required
* **Languages**: ru_RU, ru_KG, ru_UZ, uk_UA, en_AE, it_RU, es_RU, ar_AE, cs_CZ, az_AZ, en_SA, en_EG, en_OM, en_QA, en_BH
* **Documentation**: https://docs.2gis.com/en/api/search/geocoder/overview
* **Terms of Service**:
* **Limitations**:
* **Terms of Service**:
* **Limitations**:


Local IP Address Lookups
Expand Down
8 changes: 7 additions & 1 deletion lib/geocoder/lookups/geoapify.rb
Expand Up @@ -22,7 +22,13 @@ def supported_protocols
private

def base_query_url(query)
method = query.reverse_geocode? ? 'reverse' : 'search'
method = if query.reverse_geocode?
'reverse'
elsif query.options[:autocomplete]
'autocomplete'
else
'search'
end
"https://api.geoapify.com/v1/geocode/#{method}?"
end

Expand Down
11 changes: 11 additions & 0 deletions test/unit/lookups/geoapify_test.rb
Expand Up @@ -150,6 +150,17 @@ def test_geoapify_reverse_query_url_contains_lat_lon
assert_match(/lon=-75\.676333/, url)
end

def test_geoapify_query_url_contains_autocomplete
lookup = Geocoder::Lookup::Geoapify.new
url = lookup.query_url(
Geocoder::Query.new(
'Test Query',
autocomplete: true
)
)
assert_match(/\/geocode\/autocomplete/, url)
end

def test_geoapify_invalid_request
Geocoder.configure(always_raise: [Geocoder::InvalidRequest])
assert_raises Geocoder::InvalidRequest do
Expand Down

0 comments on commit 9e91043

Please sign in to comment.