class Koine::GoogleMapsClient

Constants

BASE_URL
VERSION

Attributes

api_key[R]
http_client[R]

Public Class Methods

new(api_key: nil, http_client: RestClient) click to toggle source
# File lib/koine/google_maps_client.rb, line 9
def initialize(api_key: nil, http_client: RestClient)
  @http_client = http_client
  @api_key = api_key
end

Public Instance Methods

geocode(address:) click to toggle source
# File lib/koine/google_maps_client.rb, line 14
def geocode(address:)
  get('/geocode/json', address: address)
end
get(uri, params = {}) click to toggle source
# File lib/koine/google_maps_client.rb, line 18
def get(uri, params = {})
  to_hash do
    http_client.get(url_for(uri), params: params.merge(key: api_key))
  end
end

Private Instance Methods

to_hash() { || ... } click to toggle source
# File lib/koine/google_maps_client.rb, line 30
def to_hash
  response = yield
  JSON.parse(response.body)
end
url_for(uri) click to toggle source
# File lib/koine/google_maps_client.rb, line 26
def url_for(uri)
  "#{BASE_URL}#{uri}"
end