Class: MgTracker::WeatherService
- Inherits:
-
Object
- Object
- MgTracker::WeatherService
- Defined in:
- lib/mg_tracker/weather_service.rb
Overview
‘WeatherService` connects to the weather service to make various weather data available.
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#city ⇒ Object
Returns the value of attribute city.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
- #barometer_data ⇒ Object
-
#initialize(city = 'Kennesaw', state = 'GA') ⇒ WeatherService
constructor
A new instance of WeatherService.
Constructor Details
#initialize(city = 'Kennesaw', state = 'GA') ⇒ WeatherService
Returns a new instance of WeatherService.
10 11 12 13 14 15 16 17 |
# File 'lib/mg_tracker/weather_service.rb', line 10 def initialize(city = 'Kennesaw', state = 'GA') @city = city @state = state @api_key = YAML.load_file(Dir.pwd + '/config/ws_api_key.yml')['WS_API_KEY'] url = "http://api.wunderground.com/api/#{api_key}/conditions/q/#{state}/#{city}.json" @data = ::HTTParty.get(url) @current_observation = @data['current_observation'] end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/mg_tracker/weather_service.rb', line 8 def api_key @api_key end |
#city ⇒ Object
Returns the value of attribute city.
7 8 9 |
# File 'lib/mg_tracker/weather_service.rb', line 7 def city @city end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/mg_tracker/weather_service.rb', line 8 def data @data end |
#state ⇒ Object
Returns the value of attribute state.
7 8 9 |
# File 'lib/mg_tracker/weather_service.rb', line 7 def state @state end |
Instance Method Details
#barometer_data ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/mg_tracker/weather_service.rb', line 25 def { in: , mb: , trend: } end |