Class: Darksky::API
- Inherits:
-
Object
- Object
- Darksky::API
- Defined in:
- lib/darksky/api.rb
Constant Summary collapse
- DARKSKY_API_URL =
'https://api.darkskyapp.com/v1'
- DEFAULT_OPTIONS =
{ }
Instance Method Summary collapse
-
#brief_forecast(latitude, longitude, options = {}) ⇒ Object
Returns a brief forecast for the next hour at a given location.
-
#forecast(latitude, longitude, options = {}) ⇒ Object
Returns a forecast for the next hour at a given location.
-
#initialize(api_key) ⇒ API
constructor
Create a new instance of the Darksky::API using your API key.
-
#interesting(options = {}) ⇒ Object
Returns a list of interesting storms happening right now.
-
#precipitation(latitudes_longitudes_times, options = {}) ⇒ Object
Returns forecasts for a collection of arbitrary points.
Constructor Details
#initialize(api_key) ⇒ API
Create a new instance of the Darksky::API using your API key.
13 14 15 |
# File 'lib/darksky/api.rb', line 13 def initialize(api_key) @api_key = api_key end |
Instance Method Details
#brief_forecast(latitude, longitude, options = {}) ⇒ Object
Returns a brief forecast for the next hour at a given location.
32 33 34 35 |
# File 'lib/darksky/api.rb', line 32 def brief_forecast(latitude, longitude, = {}) response = Typhoeus::Request.get("#{DARKSKY_API_URL}/brief_forecast/#{@api_key}/#{latitude},#{longitude}", DEFAULT_OPTIONS.dup.merge()) JSON.parse(response.body) if response.code == 200 end |
#forecast(latitude, longitude, options = {}) ⇒ Object
Returns a forecast for the next hour at a given location.
22 23 24 25 |
# File 'lib/darksky/api.rb', line 22 def forecast(latitude, longitude, = {}) response = Typhoeus::Request.get("#{DARKSKY_API_URL}/forecast/#{@api_key}/#{latitude},#{longitude}", DEFAULT_OPTIONS.dup.merge()) JSON.parse(response.body) if response.code == 200 end |
#interesting(options = {}) ⇒ Object
Returns a list of interesting storms happening right now.
54 55 56 57 |
# File 'lib/darksky/api.rb', line 54 def interesting( = {}) response = Typhoeus::Request.get("#{DARKSKY_API_URL}/interesting/#{@api_key}", DEFAULT_OPTIONS.dup.merge()) JSON.parse(response.body) if response.code == 200 end |
#precipitation(latitudes_longitudes_times, options = {}) ⇒ Object
Returns forecasts for a collection of arbitrary points.
41 42 43 44 45 46 47 48 49 |
# File 'lib/darksky/api.rb', line 41 def precipitation(latitudes_longitudes_times, = {}) return if latitudes_longitudes_times.size % 3 != 0 params = [] latitudes_longitudes_times.each_slice(3) do |data| params << data.join(',') end response = Typhoeus::Request.get("#{DARKSKY_API_URL}/precipitation/#{@api_key}/#{params.join(';')}", DEFAULT_OPTIONS.dup.merge()) JSON.parse(response.body) if response.code == 200 end |