class Geocoder::Lookup::Yandex

def map_link_url(coordinates)

def map_link_url(coordinates)
  "http://maps.yandex.ru/?ll=#{coordinates.reverse.join(',')}"
end

def name

def name
  "Yandex"
end

def query_url(query)

def query_url(query)
  "#{protocol}://geocode-maps.yandex.ru/1.x/?" + url_query_string(query)
end

def query_url_params(query)

def query_url_params(query)
  if query.reverse_geocode?
    q = query.coordinates.reverse.join(",")
  else
    q = query.sanitized_text
  end
  {
    :geocode => q,
    :format => "json",
    :plng => "#{query.language || configuration.language}", # supports ru, uk, be
    :key => configuration.api_key
  }.merge(super)
end

def results(query)

def results(query)
  return [] unless doc = fetch_data(query)
  if err = doc['error']
    if err["status"] == 401 and err["message"] == "invalid key"
      raise_error(Geocoder::InvalidApiKey) || Geocoder.log(:warn, "Invalid API key.")
    else
      Geocoder.log(:warn, "Yandex Geocoding API error: #{err['status']} (#{err['message']}).")
    end
    return []
  end
  if doc = doc['response']['GeoObjectCollection']
    meta = doc['metaDataProperty']['GeocoderResponseMetaData']
    return meta['found'].to_i > 0 ? doc['featureMember'] : []
  else
    Geocoder.log(:warn, "Yandex Geocoding API error: unexpected response format.")
    return []
  end
end

def supported_protocols

def supported_protocols
  [:https]
end