Sha256: b7759ab501255caa4c5adb64c9354fdfeb4de57710a9b911c3a4d2548cb28364

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 KB

Contents

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

module Geocoder::Lookup
  class Okf < Base

    def name
      "Okf"
    end

    def query_url(query)
      "#{protocol}://data.okf.fi/gis/1/geocode/json?" + url_query_string(query)
    end

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

    def valid_response?(response)
      status = parse_json(response.body)["status"]
      super(response) and ['OK', 'ZERO_RESULTS'].include?(status)
    end

    def results(query)
      return [] unless doc = fetch_data(query)
      case doc['status']; when "OK" # OK status implies >0 results
        return doc['results']
      end
      return []
    end

    def query_url_okf_params(query)
      params = {
        (query.reverse_geocode? ? :latlng : :address) => query.sanitized_text,
        :sensor => "false",
        :language => (query.language || configuration.language)
      }
      params
    end

    def query_url_params(query)
      query_url_okf_params(query).merge(super)
    end
  end
end

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
geocoder-kb-1.2.6 lib/geocoder/lookups/okf.rb
geocoder-1.2.6 lib/geocoder/lookups/okf.rb
bw-geocoder-1.2.6 lib/geocoder/lookups/okf.rb
bw-geocoder-1.2.5 lib/geocoder/lookups/okf.rb