Class: OpenWeatherMap::API
- Inherits:
-
Object
- Object
- OpenWeatherMap::API
- Defined in:
- lib/openweathermap/api.rb
Overview
The main API class.
Instance Attribute Summary collapse
-
#lang ⇒ String
Default lang to use.
-
#units ⇒ String
Default units to use.
Instance Method Summary collapse
-
#current(location) ⇒ OpenWeatherMap::CurrentWeather
Get current weather at a specific location.
-
#forecast(location) ⇒ OpenWeatherMap::Forecast
Get weather forecast for a specific location.
-
#initialize(api_key, lang = 'en', units = nil) ⇒ API
constructor
Initialize the API object.
Constructor Details
#initialize(api_key, lang = 'en', units = nil) ⇒ API
Initialize the API object
23 24 25 26 27 28 29 30 31 |
# File 'lib/openweathermap/api.rb', line 23 def initialize(api_key, lang = 'en', units = nil) @api_key = api_key raise OpenWeatherMap::Exceptions::UnknownLang, "[owm-ruby] error : unknown lang #{lang}" unless OpenWeatherMap::Constants::LANGS.include? lang @lang = lang raise OpenWeatherMap::Exceptions::UnknownUnits, "[owm-ruby] error : unknown units #{units}" unless OpenWeatherMap::Constants::UNITS.include? units @units = units end |
Instance Attribute Details
#lang ⇒ String
Returns Default lang to use.
5 6 7 |
# File 'lib/openweathermap/api.rb', line 5 def lang @lang end |
#units ⇒ String
Returns Default units to use.
8 9 10 |
# File 'lib/openweathermap/api.rb', line 8 def units @units end |
Instance Method Details
#current(location) ⇒ OpenWeatherMap::CurrentWeather
Get current weather at a specific location.
41 42 43 44 |
# File 'lib/openweathermap/api.rb', line 41 def current(location) data = make_request(OpenWeatherMap::Constants::URLS[:current], location) OpenWeatherMap::CurrentWeather.new(data) end |
#forecast(location) ⇒ OpenWeatherMap::Forecast
Get weather forecast for a specific location.
54 55 56 57 |
# File 'lib/openweathermap/api.rb', line 54 def forecast(location) data = make_request(OpenWeatherMap::Constants::URLS[:forecast], location) OpenWeatherMap::Forecast.new(data) end |