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, #query_url, #required_api_key_parts, #search, #supported_protocols

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

#results(query) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/geocoder/lookups/geocodio.rb', line 11

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) ||
      Geocoder.log(:warn, "Geocodio service error: invalid API key.")
  elsif doc['error'].match(/You have reached your daily maximum/)
    raise_error(Geocoder::OverQueryLimitError, doc['error']) ||
      Geocoder.log(:warn, "Geocodio service error: #{doc['error']}.")
  else
    raise_error(Geocoder::InvalidRequest, doc['error']) ||
      Geocoder.log(:warn, "Geocodio service error: #{doc['error']}.")
  end
  []
end