Class: OpenWeatherAPI::API

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

Constant Summary collapse

VERSION =
"2.5"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ API

Returns a new instance of API.



8
9
10
11
12
13
# 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

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



6
7
8
# File 'lib/open-weather-api/api.rb', line 6

def api_key
  @api_key
end

#default_country_codeObject

Returns the value of attribute default_country_code.



6
7
8
# File 'lib/open-weather-api/api.rb', line 6

def default_country_code
  @default_country_code
end

#default_languageObject

Returns the value of attribute default_language.



6
7
8
# File 'lib/open-weather-api/api.rb', line 6

def default_language
  @default_language
end

#default_unitsObject

Returns the value of attribute default_units.



6
7
8
# File 'lib/open-weather-api/api.rb', line 6

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



19
20
21
22
23
# 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) ⇒ Object



29
30
31
# 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) ⇒ Object



25
26
27
# File 'lib/open-weather-api/api.rb', line 25

def raw(path = "/", **args, &block)
  fetch_raw.execute(path, **args, &block)
end