Class: OpenWeatherAPI::API

Inherits:
Object
  • Object
show all
Defined in:
lib/open-weather-api/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = {})
  @options = options
  @api_key = options[:api_key] || options['api_key']
  @default_language = options[:language] || options['language'] || 'en'
  @default_country_code = options[:default_country_code] || options['default_country_code']
  @default_units =  options[:units] || options['units'] || 'metric'
end

Instance Attribute Details

#api_keyObject (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_codeObject

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_languageObject

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_unitsObject

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

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/open-weather-api/api.rb', line 4

def options
  @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

Raises:

  • (ArgumentError)


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