class GogoMaps::GoogleMapClient

Constants

ENDPOINT

Public Class Methods

call(params, sym) click to toggle source
# File lib/gogo_maps.rb, line 36
def self.call(params, sym)
  response = @@_conn.get do |req|
    req.url '/maps/api/geocode/json'
    req.params = params
  end

  unless location = JSON.parse(response.body)['results'][0]
    fail 'Something wrong with Google API or your params'
  end

  case sym
    when :to_latlng
      location['geometry']['location'].each_with_object({}) do | (k, v), rslt |
        rslt[k.to_s.to_sym] = v
      end
    when :to_address
      location['formatted_address']
  end
end