Class: Geocoder::Lookup::Geocodio

Inherits:
Base
  • Object
show all
Defined in:
lib/geocoder/lookups/geocodio.rb

Instance Method Summary collapse

Methods inherited from Base

#cache, #handle, #initialize, #map_link_url, #required_api_key_parts, #search

Constructor Details

This class inherits a constructor from Geocoder::Lookup::Base

Instance Method Details

#nameObject



7
8
9
# File 'lib/geocoder/lookups/geocodio.rb', line 7

def name
  "Geocodio"
end

#query_url(query) ⇒ Object



11
12
13
14
# File 'lib/geocoder/lookups/geocodio.rb', line 11

def query_url(query)
  path = query.reverse_geocode? ? "reverse" : "geocode"
  "#{protocol}://api.geocod.io/v1/#{path}?#{url_query_string(query)}"
end

#results(query) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/geocoder/lookups/geocodio.rb', line 16

def results(query)
  return [] unless doc = fetch_data(query)
  return doc["results"] if doc['error'].nil?
  
  if doc['error'] == 'Invalid API key'
    raise_error(Geocoder::InvalidApiKey) ||
      warn("Geocodio service error: invalid API key.")
  elsif doc['error'].match(/You have reached your daily maximum/)
    raise_error(Geocoder::OverQueryLimitError, doc['error']) ||
      warn("Geocodio service error: #{doc['error']}.")
  else
    raise_error(Geocoder::InvalidRequest, doc['error']) ||
      warn("Geocodio service error: #{doc['error']}.")
  end
  []
end