class Geocoder::Lookup::IpinfoIo

def empty_result?(doc)

def empty_result?(doc)
  !doc.is_a?(Hash) or doc.keys == ["ip"]
end

def name

def name
  "Ipinfo.io"
end

def query_url(query)

def query_url(query)
  if configuration.api_key
    "#{protocol}://ipinfo.io/#{query.sanitized_text}/geo?" + url_query_string(query)
  else
    "#{protocol}://ipinfo.io/#{query.sanitized_text}/geo"
  end
end

def query_url_params(query)

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

def reserved_result(ip)

def reserved_result(ip)
  {
    "ip"           => ip,
    "city"         => "",
    "region"       => "",
    "country"      => "",
    "loc"          => "0,0",
    "postal"       => ""
  }
end

def results(query)

def results(query)
  # don't look up a loopback address, just return the stored result
  return [reserved_result(query.text)] if query.loopback_ip_address?
  if (doc = fetch_data(query)).nil? or doc['code'] == 401 or empty_result?(doc)
    []
  else
    [doc]
  end
end

def supported_protocols

HTTPS available only for paid plans
def supported_protocols
  if configuration.api_key
    [:http, :https]
  else
    [:http]
  end
end