Class: GoogleTimezone::Base

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

Constant Summary collapse

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

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Base

Returns a new instance of Base.



15
16
17
18
19
20
21
22
23
24
# File 'lib/google_timezone/base.rb', line 15

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

Class Attribute Details

.default_stubObject

Returns the value of attribute default_stub.



12
13
14
# File 'lib/google_timezone/base.rb', line 12

def default_stub
  @default_stub
end

Instance Method Details

#fetchObject



26
27
28
29
30
31
# File 'lib/google_timezone/base.rb', line 26

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

#fetch!Object



33
34
35
36
37
# File 'lib/google_timezone/base.rb', line 33

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