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
readonly
The default lang to use across the program.
-
#units ⇒ String
readonly
The default unit system to use across the program.
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 = 'default') ⇒ API
constructor
Initialize the API object.
Constructor Details
#initialize(api_key, lang = 'en', units = 'default') ⇒ API
Initialize the API object
35 36 37 38 39 40 41 42 43 |
# File 'lib/openweathermap/api.rb', line 35 def initialize(api_key, lang = 'en', units = 'default') @api_key = api_key raise OpenWeatherMap::Exceptions::UnknownLang, "unknown lang #{lang}" unless OpenWeatherMap::Constants::LANGS.include? lang @lang = lang raise OpenWeatherMap::Exceptions::UnknownUnits, "unknown units #{units}" unless OpenWeatherMap::Constants::UNITS.include? units @units = units end |
Instance Attribute Details
#lang ⇒ String (readonly)
The default lang to use across the program
12 13 14 |
# File 'lib/openweathermap/api.rb', line 12 def lang @lang end |
#units ⇒ String (readonly)
The default unit system to use across the program
18 19 20 |
# File 'lib/openweathermap/api.rb', line 18 def units @units end |
Instance Method Details
#current(location) ⇒ OpenWeatherMap::CurrentWeather
Get current weather at a specific location.
55 56 57 58 |
# File 'lib/openweathermap/api.rb', line 55 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.
70 71 72 73 |
# File 'lib/openweathermap/api.rb', line 70 def forecast(location) data = make_request(OpenWeatherMap::Constants::URLS[:forecast], location) OpenWeatherMap::Forecast.new(data) end |