Class: Pickpoint::GeocodingService

Inherits:
Object
  • Object
show all
Defined in:
lib/pickpoint/geocoding.rb

Instance Method Summary collapse

Constructor Details

#initialize(transport, concurrency) ⇒ GeocodingService

Returns a new instance of GeocodingService.



8
9
10
11
# File 'lib/pickpoint/geocoding.rb', line 8

def initialize(transport, concurrency)
  @t = transport
  @concurrency = concurrency
end

Instance Method Details

#forward(query) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pickpoint/geocoding.rb', line 13

def forward(query)
  raw = @t.do(
    Transport::RequestOpts.new(
      method: "GET",
      path: "/v2/geocode/forward",
      query: stringify_query(query),
      on_client_error: Transport::ON_EMPTY,
      empty: "[]"
    )
  )
  decode_json_array(raw)
end

#forward_batch(queries) ⇒ Object



54
55
56
# File 'lib/pickpoint/geocoding.rb', line 54

def forward_batch(queries)
  run_batch(queries) { |q| forward(q) }
end

#lookup(query) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pickpoint/geocoding.rb', line 41

def lookup(query)
  raw = @t.do(
    Transport::RequestOpts.new(
      method: "GET",
      path: "/v2/address/lookup",
      query: stringify_query(query),
      on_client_error: Transport::ON_EMPTY,
      empty: "[]"
    )
  )
  decode_json_array(raw)
end

#lookup_batch(queries) ⇒ Object



62
63
64
# File 'lib/pickpoint/geocoding.rb', line 62

def lookup_batch(queries)
  run_batch(queries) { |q| lookup(q) }
end

#reverse(query) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pickpoint/geocoding.rb', line 26

def reverse(query)
  raw = @t.do(
    Transport::RequestOpts.new(
      method: "GET",
      path: "/v2/geocode/reverse",
      query: stringify_query(query),
      on_client_error: Transport::ON_EMPTY,
      empty: "null"
    )
  )
  return nil if raw.nil? || raw.empty? || raw == "null"

  JSON.parse(raw)
end

#reverse_batch(queries) ⇒ Object



58
59
60
# File 'lib/pickpoint/geocoding.rb', line 58

def reverse_batch(queries)
  run_batch(queries) { |q| reverse(q) }
end