Class: Geocoder::Lookup::SensisBase
- Inherits:
-
Base
- Object
- Base
- Geocoder::Lookup::SensisBase
show all
- Defined in:
- lib/geocoder/sensis.rb
Overview
Instance Method Summary
collapse
Instance Method Details
#cache_key(query) ⇒ Object
33
34
35
|
# File 'lib/geocoder/sensis.rb', line 33
def cache_key(query)
query.to_s
end
|
#make_api_request(query) ⇒ Object
Override the base method because it’s hard-coded to use Get. TODO: Raise PR upstream to allow other request methods.
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/geocoder/sensis.rb', line 48
def make_api_request(query)
response = timeout(configuration.timeout) do
uri = URI.parse(query_url(query))
http_client.start(uri.host, uri.port, :use_ssl => true) do |client|
req = Net::HTTP::Post.new(uri.request_uri, configuration.)
req.basic_auth(uri.user, uri.password) if uri.user and uri.password
req.body = sensis_query_json(query)
req.content_type = 'application/json'
req['X-Auth-Token'] = configuration.api_key[0]
req['X-Auth-Password'] = configuration.api_key[1]
client.request(req)
end
end
case response.code.to_i
when 200
return response
when 400
raise_error ::Geocoder::InvalidRequest.new("Bad Request: #{response.body}")
else
raise_error ::Geocoder::Error.new("Unable to access Sensis API: #{response.code}. Body:\n#{response.body}")
end
response
end
|
#protocol ⇒ Object
29
30
31
|
# File 'lib/geocoder/sensis.rb', line 29
def protocol
"https"
end
|
#query_url(query) ⇒ Object
25
26
27
|
# File 'lib/geocoder/sensis.rb', line 25
def query_url(query)
"https://#{sensis_host}/v2/service/geocode/#{request_type}" + url_query_string(query)
end
|
#required_api_key_parts ⇒ Object
21
22
23
|
# File 'lib/geocoder/sensis.rb', line 21
def required_api_key_parts
["auth token", "auth password"]
end
|
#result_class ⇒ Object
72
73
74
|
# File 'lib/geocoder/sensis.rb', line 72
def result_class
::Geocoder::Result::Sensis
end
|
#results(query) ⇒ Object
37
38
39
40
41
42
|
# File 'lib/geocoder/sensis.rb', line 37
def results(query)
doc = fetch_data(query)
return [] unless doc
raise Exception.new('Incorrect API key') if doc["code"] == 401
doc["results"]
end
|