Sha256: 34567a0d21b2aac56fc0178e270dcf9aca02824d325ca2f63a8edd24b7977bfe

Contents?: true

Size: 894 Bytes

Versions: 1

Compression:

Stored size: 894 Bytes

Contents

require 'cgi'
require 'geocoder/lookups/base'
require "geocoder/results/mapquest"

module Geocoder::Lookup
  class Mapquest < Base

    private # ---------------------------------------------------------------

    def query_url(query)
      key = Geocoder::Configuration.api_key
      domain = key ? "www" : "open"
      url = "#{protocol}://#{domain}.mapquestapi.com/geocoding/v1/#{search_type(query)}?"
      url + url_query_string(query)
    end

    def search_type(query)
      query.reverse_geocode? ? "reverse" : "address"
    end

    def query_url_params(query)
      key = Geocoder::Configuration.api_key
      params = { :location => query.sanitized_text }
      if key
        params[:key] = CGI.unescape(key)
      end
      super.merge(params)
    end

    def results(query)
      return [] unless doc = fetch_data(query)
      doc["results"][0]['locations']
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
geocoder-1.1.5 lib/geocoder/lookups/mapquest.rb