Class: GoogleTimezone::Base
- Inherits:
-
Object
- Object
- GoogleTimezone::Base
- Defined in:
- lib/google_timezone/base.rb
Constant Summary collapse
- ALLOWED_PARAMS =
[:language, :timestamp, :client, :signature, :key]
Class Attribute Summary collapse
-
.default_stub ⇒ Object
Returns the value of attribute default_stub.
Instance Method Summary collapse
- #fetch ⇒ Object
- #fetch! ⇒ Object
-
#initialize(*args) ⇒ Base
constructor
A new instance of Base.
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 = (args) @options.reject! { |key, _| !ALLOWED_PARAMS.include?(key) } end |
Class Attribute Details
.default_stub ⇒ Object
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
#fetch ⇒ Object
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 |