From c1173504ac3a4f3aea7c3c27515bbb1fcdccf92c Mon Sep 17 00:00:00 2001 From: Adrien Siami Date: Fri, 16 Sep 2022 13:40:10 +0200 Subject: [PATCH] Allow geoapify lookup to perform autocomplete query --- README_API_GUIDE.md | 11 ++++++----- lib/geocoder/lookups/geoapify.rb | 8 +++++++- test/unit/lookups/geoapify_test.rb | 11 +++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/README_API_GUIDE.md b/README_API_GUIDE.md index a76945913..6499280bd 100644 --- a/README_API_GUIDE.md +++ b/README_API_GUIDE.md @@ -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' }` @@ -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 diff --git a/lib/geocoder/lookups/geoapify.rb b/lib/geocoder/lookups/geoapify.rb index 56d84a9c4..c9d74e79d 100644 --- a/lib/geocoder/lookups/geoapify.rb +++ b/lib/geocoder/lookups/geoapify.rb @@ -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 diff --git a/test/unit/lookups/geoapify_test.rb b/test/unit/lookups/geoapify_test.rb index 492915207..c2563909a 100644 --- a/test/unit/lookups/geoapify_test.rb +++ b/test/unit/lookups/geoapify_test.rb @@ -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