lib/geocoder/lookups/here.rb in geocoder-1.7.5 vs lib/geocoder/lookups/here.rb in geocoder-1.8.0
- old
+ new
@@ -17,52 +17,57 @@
end
private # ---------------------------------------------------------------
def base_query_url(query)
- "#{protocol}://#{if query.reverse_geocode? then 'reverse.' end}geocoder.ls.hereapi.com/6.2/#{if query.reverse_geocode? then 'reverse' end}geocode.json?"
+ service = query.reverse_geocode? ? "revgeocode" : "geocode"
+
+ "#{protocol}://#{service}.search.hereapi.com/v1/#{service}?"
end
def results(query)
- return [] unless doc = fetch_data(query)
- return [] unless doc['Response'] && doc['Response']['View']
- if r=doc['Response']['View']
- return [] if r.nil? || !r.is_a?(Array) || r.empty?
- return r.first['Result']
+ unless configuration.api_key.is_a?(String)
+ api_key_not_string!
+ return []
end
- []
+ return [] unless doc = fetch_data(query)
+ return [] if doc["items"].nil?
+
+ doc["items"]
end
def query_url_here_options(query, reverse_geocode)
options = {
- gen: 9,
- apikey: configuration.api_key,
- language: (query.language || configuration.language)
+ apiKey: configuration.api_key,
+ lang: (query.language || configuration.language)
}
- if reverse_geocode
- options[:mode] = :retrieveAddresses
- return options
- end
+ return options if reverse_geocode
unless (country = query.options[:country]).nil?
- options[:country] = country
+ options[:in] = "countryCode:#{country}"
end
- unless (mapview = query.options[:bounds]).nil?
- options[:mapview] = mapview.map{ |point| "%f,%f" % point }.join(';')
- end
options
end
def query_url_params(query)
if query.reverse_geocode?
super.merge(query_url_here_options(query, true)).merge(
- prox: query.sanitized_text
+ at: query.sanitized_text
)
else
super.merge(query_url_here_options(query, false)).merge(
- searchtext: query.sanitized_text
+ q: query.sanitized_text
)
end
+ end
+
+ def api_key_not_string!
+ msg = <<~MSG
+ API key for HERE Geocoding and Search API should be a string.
+ For more info on how to obtain it, please see https://developer.here.com/documentation/identity-access-management/dev_guide/topics/plat-using-apikeys.html
+ MSG
+
+ raise_error(Geocoder::ConfigurationError, msg) || Geocoder.log(:warn, msg)
end
end
end