class Locotimezone::Timezone
Attributes
location[R]
Public Class Methods
new(location)
click to toggle source
# File lib/locotimezone/timezone.rb, line 5 def initialize(location) @location = location end
Public Instance Methods
call()
click to toggle source
# File lib/locotimezone/timezone.rb, line 9 def call return {} if location_invalid? ResultsFormatter.build_timezone_hash_for timezone_response rescue OpenURI::HTTPError => e ErrorLogger.stdout_log_for(e, severity: :error) {} end
comma_delimited_location()
click to toggle source
# File lib/locotimezone/timezone.rb, line 32 def comma_delimited_location location.values.join(',') end
location_invalid?()
click to toggle source
# File lib/locotimezone/timezone.rb, line 21 def location_invalid? return true unless location.respond_to? :has_key? location.empty? end
timestamp()
click to toggle source
# File lib/locotimezone/timezone.rb, line 36 def timestamp Time.now.to_i.to_s end
timezone_query_url()
click to toggle source
# File lib/locotimezone/timezone.rb, line 26 def timezone_query_url "https://maps.googleapis.com/maps/api/timezone/json?key="\ "#{Locotimezone.configuration.google_api_key}&location="\ "#{comma_delimited_location}×tamp=#{timestamp}" end
timezone_response()
click to toggle source
# File lib/locotimezone/timezone.rb, line 17 def timezone_response open(timezone_query_url) { |response| JSON.parse response.read } end