Sha256: 4b8a1daa8ec8a977f786df90af75b43cf60a56476fa790e1ce001daff115bb6f

Contents?: true

Size: 1.13 KB

Versions: 11

Compression:

Stored size: 1.13 KB

Contents

require 'geocoder/lookups/base'
require 'geocoder/results/uk_ordnance_survey_names'

module Geocoder::Lookup
  class UkOrdnanceSurveyNames < Base

    def name
      'Ordance Survey Names'
    end

    def supported_protocols
      [:https]
    end

    def base_query_url(query)
      "#{protocol}://api.os.uk/search/names/v1/find?"
    end

    def required_api_key_parts
      ["key"]
    end

    def query_url(query)
      base_query_url(query) + url_query_string(query)
    end

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

    def results(query)
      return [] unless doc = fetch_data(query)
      return [] if doc['header']['totalresults'].zero?
      return doc['results'].map { |r| r['GAZETTEER_ENTRY'] }
    end

    def query_url_params(query)
      {
        query: query.sanitized_text,
        key: configuration.api_key,
        fq: filter
      }.merge(super)
    end

    def local_types
      %w[
        City
        Hamlet
        Other_Settlement
        Town
        Village
        Postcode
      ]
    end

    def filter
      local_types.map { |t| "local_type:#{t}" }.join(' ')
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
geocoder-1.8.3 lib/geocoder/lookups/uk_ordnance_survey_names.rb
geocoder-1.8.2 lib/geocoder/lookups/uk_ordnance_survey_names.rb
geocoder-1.8.1 lib/geocoder/lookups/uk_ordnance_survey_names.rb
geocoder-1.8.0 lib/geocoder/lookups/uk_ordnance_survey_names.rb
geocoder-1.7.5 lib/geocoder/lookups/uk_ordnance_survey_names.rb
geocoder-1.7.4 lib/geocoder/lookups/uk_ordnance_survey_names.rb
geocoder-1.7.3 lib/geocoder/lookups/uk_ordnance_survey_names.rb
geocoder-1.7.2 lib/geocoder/lookups/uk_ordnance_survey_names.rb
geocoder-1.7.1 lib/geocoder/lookups/uk_ordnance_survey_names.rb
geocoder-1.7.0 lib/geocoder/lookups/uk_ordnance_survey_names.rb
geocoder-1.6.7 lib/geocoder/lookups/uk_ordnance_survey_names.rb