Class: MgTracker::WeatherService

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_keyObject (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

#cityObject

Returns the value of attribute city.



7
8
9
# File 'lib/mg_tracker/weather_service.rb', line 7

def city
  @city
end

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/mg_tracker/weather_service.rb', line 8

def data
  @data
end

#stateObject

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_dataObject



25
26
27
28
29
30
31
# File 'lib/mg_tracker/weather_service.rb', line 25

def barometer_data
  {
    in: barometer_in,
    mb: barometer_mb,
    trend: barometer_trend
  }
end