Class: OpenWeatherAPI::API
- Inherits:
-
Object
- Object
- OpenWeatherAPI::API
- Defined in:
- lib/open-weather-api/api.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
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.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #current(**args, &block) ⇒ Object
-
#forecast(type = :hourly, **args, &block) ⇒ Object
Not yet implemented.
- #icon_url(icon_code) ⇒ Object
-
#initialize(options = {}) ⇒ API
constructor
A new instance of API.
Constructor Details
#initialize(options = {}) ⇒ API
Returns a new instance of API.
7 8 9 10 11 12 13 |
# File 'lib/open-weather-api/api.rb', line 7 def initialize( = {}) @options = @api_key = [:api_key] || ['api_key'] @default_language = [:language] || ['language'] || 'en' @default_country_code = [:default_country_code] || ['default_country_code'] @default_units = [:units] || ['units'] || 'metric' end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
4 5 6 |
# File 'lib/open-weather-api/api.rb', line 4 def api_key @api_key end |
#default_country_code ⇒ Object
Returns the value of attribute default_country_code.
5 6 7 |
# File 'lib/open-weather-api/api.rb', line 5 def default_country_code @default_country_code end |
#default_language ⇒ Object
Returns the value of attribute default_language.
5 6 7 |
# File 'lib/open-weather-api/api.rb', line 5 def default_language @default_language end |
#default_units ⇒ Object
Returns the value of attribute default_units.
5 6 7 |
# File 'lib/open-weather-api/api.rb', line 5 def default_units @default_units end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/open-weather-api/api.rb', line 4 def @options 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
Not yet implemented
20 21 22 23 24 |
# File 'lib/open-weather-api/api.rb', line 20 def forecast(type = :hourly, **args, &block) raise ArgumentError, "Invalid #{type} forecast type." self.send("fetch_forecast_#{type}").execute(**args, &block) end |
#icon_url(icon_code) ⇒ Object
26 27 28 |
# File 'lib/open-weather-api/api.rb', line 26 def icon_url(icon_code) "http://openweathermap.org/img/w/#{icon_code}.png" end |