class Geocoder::Lookup::SensisBase

Actual implementation

Public Instance Methods

cache_key(query) click to toggle source
# File lib/geocoder/sensis.rb, line 33
def cache_key(query)
  query.to_s
end
make_api_request(query) click to toggle source

Override the base method because it's hard-coded to use Get. TODO: Raise PR upstream to allow other request methods.

# 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.http_headers)
      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, "Bad Request: #{response.body}"
  else
    raise_error ::Geocoder::Error, "Unable to access Sensis API: #{response.code}. Body:\n#{response.body}"
  end
  response
end
protocol() click to toggle source
# File lib/geocoder/sensis.rb, line 29
def protocol
  "https"
end
query_url(query) click to toggle source
# 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() click to toggle source
# File lib/geocoder/sensis.rb, line 21
def required_api_key_parts
  ["auth token", "auth password"]
end
result_class() click to toggle source
# File lib/geocoder/sensis.rb, line 72
def result_class
  ::Geocoder::Result::Sensis
end
results(query) click to toggle source
# 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

Private Instance Methods

request_type() click to toggle source

Structured or unstructured

# File lib/geocoder/sensis.rb, line 83
def request_type
  fail
end
sensis_host() click to toggle source
# File lib/geocoder/sensis.rb, line 78
def sensis_host
  ENV["SENSIS_GEOCODE_HOST"] || "api-ems-stage.ext.sensis.com.au"
end
sensis_query_json(query) click to toggle source

A json hash

# File lib/geocoder/sensis.rb, line 88
def sensis_query_json(query)
  fail
end