Class: DarkSkyAPI
- Inherits:
-
Object
- Object
- DarkSkyAPI
- Defined in:
- lib/darksky-ruby/api.rb
Constant Summary collapse
- VERSION =
'1.0.2'- DARKSKY_URL =
'https://api.darksky.net/'- DARKSKY_PATH_TEMPLATE =
'/forecast/%{key}/%{loc}'- DARKSKY_BLOCK_NAMES =
[ :currently, :minutely, :hourly, :daily, :alerts, :flags ]
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#location ⇒ Object
Returns the value of attribute location.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
-
#options ⇒ Object
Returns the value of attribute options.
-
#time ⇒ Object
Returns the value of attribute time.
Instance Method Summary collapse
- #blocks ⇒ Object
- #blocks=(h) ⇒ Object
- #forecast(lat: @latitude, lon: @longitude, loc: @location, ts: @time) ⇒ Object
- #include_only(inc = [:currently]) ⇒ Object
-
#initialize(key:, options: {}) ⇒ DarkSkyAPI
constructor
A new instance of DarkSkyAPI.
- #timemachine(lat: @latitude, lon: @longitude, loc: @location, ts:) ⇒ Object
Constructor Details
#initialize(key:, options: {}) ⇒ DarkSkyAPI
Returns a new instance of DarkSkyAPI.
16 17 18 19 |
# File 'lib/darksky-ruby/api.rb', line 16 def initialize(key:, options: {}) @key = key = end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
14 15 16 |
# File 'lib/darksky-ruby/api.rb', line 14 def key @key end |
#latitude ⇒ Object
Returns the value of attribute latitude.
14 15 16 |
# File 'lib/darksky-ruby/api.rb', line 14 def latitude @latitude end |
#location ⇒ Object
Returns the value of attribute location.
14 15 16 |
# File 'lib/darksky-ruby/api.rb', line 14 def location @location end |
#longitude ⇒ Object
Returns the value of attribute longitude.
14 15 16 |
# File 'lib/darksky-ruby/api.rb', line 14 def longitude @longitude end |
#options ⇒ Object
Returns the value of attribute options.
14 15 16 |
# File 'lib/darksky-ruby/api.rb', line 14 def end |
#time ⇒ Object
Returns the value of attribute time.
14 15 16 |
# File 'lib/darksky-ruby/api.rb', line 14 def time @time end |
Instance Method Details
#blocks ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/darksky-ruby/api.rb', line 33 def blocks exc = [:exclude] exc = (exc.nil? ? [] : exc.split(',').map { |n| n.to_sym }) h = {} DARKSKY_BLOCK_NAMES.each { |n| h[n] = !exc.include?(n) } h end |
#blocks=(h) ⇒ Object
41 42 43 44 |
# File 'lib/darksky-ruby/api.rb', line 41 def blocks=(h) exc = DARKSKY_BLOCK_NAMES.select { |n| h[n] == false } [:exclude] = exc.join(',') end |
#forecast(lat: @latitude, lon: @longitude, loc: @location, ts: @time) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/darksky-ruby/api.rb', line 21 def forecast(lat: @latitude, lon: @longitude, loc: @location, ts: @time) loc = "#{lat},#{lon}" if lat && lon loc = loc.gsub(/\s+/, '') raise ArgumentError, 'No location given to forecast' if loc.nil? ts = ts.to_i if ts.class == Time request(loc, ts) end |
#include_only(inc = [:currently]) ⇒ Object
46 47 48 49 |
# File 'lib/darksky-ruby/api.rb', line 46 def include_only(inc = [:currently]) exc = DARKSKY_BLOCK_NAMES.select { |n| !inc.include?(n) } [:exclude] = exc.join(',') end |
#timemachine(lat: @latitude, lon: @longitude, loc: @location, ts:) ⇒ Object
29 30 31 |
# File 'lib/darksky-ruby/api.rb', line 29 def timemachine(lat: @latitude, lon: @longitude, loc: @location, ts:) forecast(lat: lat, lon: lon, loc: loc, ts: ts) end |