Sha256: c4cded71f9eb7e5ff6779d93ce203cf6dc480447081087deddd6c8fa9c81f62b

Contents?: true

Size: 1.11 KB

Versions: 10

Compression:

Stored size: 1.11 KB

Contents

require 'geocoder/lookups/base'
require "geocoder/results/geocoder_ca"

module Geocoder::Lookup
  class GeocoderCa < Base

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

    def results(query, reverse = false)
      return [] unless doc = fetch_data(query, reverse)
      if doc['error'].nil?
        return [doc]
      elsif doc['error']['code'] == "005"
        # "Postal Code is not in the proper Format" => no results, just shut up
      else
        warn "Geocoder.ca service error: #{doc['error']['code']} (#{doc['error']['description']})."
      end
      return []
    end

    def query_url(query, reverse = false)
      params = {
        :geoit    => "xml",
        :jsonp    => 1,
        :callback => "test"
      }
      if reverse
        lat,lon = query.split(',')
        params[:latt] = lat
        params[:longt] = lon
        params[:corner] = 1
        params[:reverse] = 1
      else
        params[:locate] = query
      end
      "http://geocoder.ca/?" + hash_to_query(params)
    end

    def parse_raw_data(raw_data)
      super raw_data[/^test\((.*)\)\;\s*$/, 1]
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
geocoder-1.0.5 lib/geocoder/lookups/geocoder_ca.rb
geocoder-1.0.4 lib/geocoder/lookups/geocoder_ca.rb
geocoder-1.0.3 lib/geocoder/lookups/geocoder_ca.rb
geocoder-1.0.2 lib/geocoder/lookups/geocoder_ca.rb
geocoder-1.0.1 lib/geocoder/lookups/geocoder_ca.rb
geocoder-1.0.0 lib/geocoder/lookups/geocoder_ca.rb
geocoder-0.9.13 lib/geocoder/lookups/geocoder_ca.rb
geocoder-0.9.12 lib/geocoder/lookups/geocoder_ca.rb
rails-geocoder-0.9.11 lib/geocoder/lookups/geocoder_ca.rb
geocoder-0.9.11 lib/geocoder/lookups/geocoder_ca.rb