Method: OpenWeatherMap::API#initialize

Defined in:
lib/openweathermap/api.rb

#initialize(api_key, lang = 'en', units = 'default') ⇒ API

Initialize the API object

Parameters:

  • api_key (String)

    your OpenWeatherMap’s API key For further information, go to openweathermap.org/price

  • lang (String) (defaults to: 'en')

    the default lang Refer to OpenWeatherMap::Constants::LANGS for accepted values

  • units (String) (defaults to: 'default')

    the units system to use Accepted values :

    • none (temperatures in Kelvin)

    • metric (temperatures in Celsius)

    • imperial (temperatures in Fahrenheit)

Raises:



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