Class: SimpleOpenWeatherMap::Weather

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_open_weather_map/weather.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#icon_pathObject

Returns the value of attribute icon_path.



7
8
9
# File 'lib/simple_open_weather_map/weather.rb', line 7

def icon_path
  @icon_path
end

Instance Method Details

#current(config) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/simple_open_weather_map/weather.rb', line 9

def current(config)
  raise "SimpleOpenWeatherMap::Config only!" unless config.is_a?(SimpleOpenWeatherMap::Config)

  responseJson = http_connection(SimpleOpenWeatherMap::PATH_CURRENT).get_contents(current_params(config))
  return nil if responseJson.nil? || responseJson.empty?

  @current = ::JSON.parse(responseJson)

  if config.save_icon? then
    save_current_icon(@current["weather"][0]["icon"], config.save_icon_dir)
  end

  return @current
end

#forecast(config) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/simple_open_weather_map/weather.rb', line 24

def forecast(config)
  raise "SimpleOpenWeatherMap::Config only!" unless config.is_a?(SimpleOpenWeatherMap::Config)

  responseJson = http_connection(SimpleOpenWeatherMap::PATH_FORECAST).get_contents(forecast_params(config))
  return nil if responseJson.nil? || responseJson.empty?

  ::JSON.parse(responseJson)
end