class OpenWeatherAPI::API
Constants
- VALID_FORECAST_TYPES
- VERSION
Attributes
api_key[RW]
default_country_code[RW]
default_language[RW]
default_units[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/open-weather-api/api.rb, line 8 def initialize(options = {}) @api_key = options[:api_key] || options['api_key'] @default_language = options[:default_language] || options['default_language'] || 'en' @default_country_code = options[:default_country_code] || options['default_country_code'] @default_units = options[:default_units] || options['default_units'] || 'metric' end
Public Instance Methods
current(**args, &block)
click to toggle source
# File lib/open-weather-api/api.rb, line 15 def current(**args, &block) fetch_current.execute(**args, &block) end
forecast(type = :hourly, **args, &block)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/open-weather-api/api.rb, line 25 def raw(path = "/", **args, &block) fetch_raw.execute(path, **args, &block) end
Private Instance Methods
fetch_current()
click to toggle source
# File lib/open-weather-api/api.rb, line 45 def fetch_current @current ||= Resources::Current.new self end
fetch_forecast_daily()
click to toggle source
# File lib/open-weather-api/api.rb, line 53 def fetch_forecast_daily @forecast_daily ||= Resources::ForecastHourly.new self end
fetch_forecast_hourly()
click to toggle source
# File lib/open-weather-api/api.rb, line 49 def fetch_forecast_hourly @forecast_hourly ||= Resources::ForecastHourly.new self end
fetch_raw()
click to toggle source
# File lib/open-weather-api/api.rb, line 41 def fetch_raw @current ||= Resources::Raw.new self end
valid_forecast_type?(type)
click to toggle source
# File lib/open-weather-api/api.rb, line 37 def valid_forecast_type?(type) VALID_FORECAST_TYPES.include? type.to_sym end