Class: OpenWeatherAPI::API
- Inherits:
-
Object
- Object
- OpenWeatherAPI::API
- Defined in:
- lib/open-weather-api/api.rb
Constant Summary collapse
- VERSION =
"2.5"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#default_country_code ⇒ Object
Returns the value of attribute default_country_code.
-
#default_language ⇒ Object
Returns the value of attribute default_language.
-
#default_units ⇒ Object
Returns the value of attribute default_units.
Instance Method Summary collapse
- #current(**args, &block) ⇒ Object
- #forecast(type = :hourly, **args, &block) ⇒ Object
- #icon_url(icon_code) ⇒ Object
-
#initialize(options = {}) ⇒ API
constructor
A new instance of API.
- #raw(path = "/", **args, &block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ API
Returns a new instance of API.
8 9 10 11 12 13 |
# File 'lib/open-weather-api/api.rb', line 8 def initialize( = {}) @api_key = [:api_key] || ['api_key'] @default_language = [:default_language] || ['default_language'] || 'en' @default_country_code = [:default_country_code] || ['default_country_code'] @default_units = [:default_units] || ['default_units'] || 'metric' end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/open-weather-api/api.rb', line 6 def api_key @api_key end |
#default_country_code ⇒ Object
Returns the value of attribute default_country_code.
6 7 8 |
# File 'lib/open-weather-api/api.rb', line 6 def default_country_code @default_country_code end |
#default_language ⇒ Object
Returns the value of attribute default_language.
6 7 8 |
# File 'lib/open-weather-api/api.rb', line 6 def default_language @default_language end |
#default_units ⇒ Object
Returns the value of attribute default_units.
6 7 8 |
# File 'lib/open-weather-api/api.rb', line 6 def default_units @default_units end |
Instance Method Details
#current(**args, &block) ⇒ Object
15 16 17 |
# File 'lib/open-weather-api/api.rb', line 15 def current(**args, &block) fetch_current.execute(**args, &block) end |
#forecast(type = :hourly, **args, &block) ⇒ Object
19 20 21 22 23 |
# File 'lib/open-weather-api/api.rb', line 19 def forecast(type = :hourly, **args, &block) raise "Invalid '#type' forecast type" unless valid_forecast_type?(type) self.send("fetch_forecast_#{type}").execute(**args, &block) end |
#icon_url(icon_code) ⇒ Object
29 30 31 |
# File 'lib/open-weather-api/api.rb', line 29 def icon_url(icon_code) "http://openweathermap.org/img/w/#{icon_code}.png" end |
#raw(path = "/", **args, &block) ⇒ Object
25 26 27 |
# File 'lib/open-weather-api/api.rb', line 25 def raw(path = "/", **args, &block) fetch_raw.execute(path, **args, &block) end |