class Geocoder::Lookup::Ipstack

def base_query_url(query)

def base_query_url(query)
  "#{protocol}://#{host}/#{query.sanitized_text}?"
end

def host

def host
  configuration[:host] || "api.ipstack.com"
end

def name

def name
  "Ipstack"
end

def query_url_params(query)

def query_url_params(query)
  {
    access_key: configuration.api_key
  }.merge(super)
end

def reserved_result(ip)

def reserved_result(ip)
  {
    "ip"           => ip,
    "country_name" => "Reserved",
    "country_code" => "RD"
  }
end

def results(query)

def results(query)
  # don't look up a loopback or private address, just return the stored result
  return [reserved_result(query.text)] if query.internal_ip_address?
  return [] unless doc = fetch_data(query)
  if error = doc['error']
    code = error['code']
    msg = error['info']
    raise_error(ERROR_CODES[code], msg ) || Geocoder.log(:warn, "Ipstack Geocoding API error: #{msg}")
    return []
  end
  [doc]
end