File: pdok_nl.rb

package info (click to toggle)
ruby-geocoder 1.8.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 900 kB
  • sloc: ruby: 8,419; makefile: 3
file content (43 lines) | stat: -rw-r--r-- 865 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'geocoder/lookups/base'
require "geocoder/results/pdok_nl"

module Geocoder::Lookup
  class PdokNl < Base

    def name
      'pdok NL'
    end

    def supported_protocols
      [:https]
    end

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

    def cache_key(query)
      base_query_url(query) + hash_to_query(query_url_params(query))
    end

    def base_query_url(query)
      "#{protocol}://api.pdok.nl/bzk/locatieserver/search/v3_1/free?"
    end

    def valid_response?(response)
      json   = parse_json(response.body)
      super(response) if json
    end

    def results(query)
      return [] unless doc = fetch_data(query)
      return doc['response']['docs']
    end

    def query_url_params(query)
      {
        fl: '*',
        q:  query.text,
        wt: 'json'
      }.merge(super)
    end
  end
end