require "net/https" require "uri" module GmapsTz class Client include TimeZone FORMAT = "/json" HOST = "maps.googleapis.com" BASE_PATH = "/maps/api" def initialize(options = {}) @key = options[:key] @basic_params = { sensor: false } @basic_params[:key] = options[:key] if options[:key] @basic_params[:client] = options[:client] if options[:client] @basic_params[:signature] = options[:signature] if options[:signature] end def get(path, query_params) uri = generate_uri(path, query_params) response = Net::HTTP.get_response(uri) ResponseParser.new(uri, response).execute end private def generate_uri(path, query_params) URI::HTTPS.build( :host => HOST, :path => BASE_PATH + path + FORMAT, :query => generate_query(@basic_params.merge(query_params)) ) end def generate_query(query_params) query_params.map do |k,v| [CGI.escape(k.to_s), "=", CGI.escape(v.to_s)] end.map(&:join) .join("&") end end end