Class: GoogleTimezone::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/google_timezone/base.rb

Constant Summary collapse

ALLOWED_PARAMS =
[:language, :sensor, :timestamp, :client, :signature, :key]

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Base



11
12
13
14
15
16
17
18
19
20
# File 'lib/google_timezone/base.rb', line 11

def initialize(*args)
  @lat, @lon = if args.first.is_a? Array
                 args.first
               else
                 args[0..1]
               end

  @options = extract_options!(args)
  @options.reject! { |key, _| !ALLOWED_PARAMS.include?(key) }
end

Instance Method Details

#fetchObject



22
23
24
25
26
27
# File 'lib/google_timezone/base.rb', line 22

def fetch
  location = [@lat, @lon].join(',')
  params = { location: location, sensor: false, timestamp: Time.now.to_i }.merge(@options)
  result = get_result(params)
  Result.new(result)
end

#fetch!Object



29
30
31
32
33
# File 'lib/google_timezone/base.rb', line 29

def fetch!
  result = fetch
  raise(GoogleTimezone::Error.new(result.result)) unless result.success?
  result
end