I'm using Rubys rest-client gem to make a call to Google API and want to shorten the url part.
Current code:
class GoogleTimezoneGetter
def initialize(lat:, lon:)
@lat = lat
@lon = lon
@time_stamp = Time.new.to_i
end
def response
response = RestClient.get "https://maps.googleapis.com/maps/api/timezone/json?location=#{@lat},#{@lon}×tamp=#{@time_stamp}&key=#{GOOGLE_TIME_ZONE_KEY}"
JSON.parse(response)
end
def time_zone
response["timeZoneId"]
end
end
I would like to be able to do something like:
def response
response = RestClient.get (uri, params)
JSON.parse(response)
end
But I'm struggling to find out how to do so.
To make the class a bit tidier, I'd like to break the url down into 'uri' and 'params'. I think the rest-client gem allows you to do this but I can't find specific examples.
I want to put the
{@lat},#{@lon}×tamp=#{@time_stamp}&key=#{GOOGLE_TIME_ZONE_KEY}"
in to a 'params' method and pass that to the RestClient.get
method.