Class: Barometer::WeatherBug

Inherits:
Object
  • Object
show all
Defined in:
lib/barometer/weather_bug.rb,
lib/barometer/weather_bug/query.rb,
lib/barometer/weather_bug/version.rb,
lib/barometer/weather_bug/oauth_api.rb,
lib/barometer/weather_bug/current_api.rb,
lib/barometer/weather_bug/oauth_token.rb,
lib/barometer/weather_bug/forecast_api.rb,
lib/barometer/weather_bug/current_response.rb,
lib/barometer/weather_bug/forecast_response.rb,
lib/barometer/weather_bug/response/current_weather.rb,
lib/barometer/weather_bug/response/forecasted_weather.rb

Defined Under Namespace

Classes: CurrentApi, CurrentResponse, ForecastApi, ForecastResponse, OauthApi, OauthToken, Query, Response

Constant Summary collapse

VERSION =
'0.1.0'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, config = {}) ⇒ WeatherBug

Returns a new instance of WeatherBug.



16
17
18
19
20
21
22
23
# File 'lib/barometer/weather_bug.rb', line 16

def initialize(query, config={})
  @query = query

  if config.has_key? :keys
    @api_client_id = config[:keys][:client_id]
    @api_client_secret = config[:keys][:client_secret]
  end
end

Class Method Details

.call(query, config = {}) ⇒ Object



12
13
14
# File 'lib/barometer/weather_bug.rb', line 12

def self.call(query, config={})
  WeatherBug.new(query, config).measure!
end

Instance Method Details

#measure!Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/barometer/weather_bug.rb', line 25

def measure!
  validate_keys!

  oauth_token_api = OauthApi.new(api_client_id, api_client_secret)
  oauth_token = OauthToken.new(oauth_token_api)

  current_weather_api = CurrentApi.new(query, oauth_token)
  response = CurrentResponse.new.parse(current_weather_api.get)

  forecast_weather_api = ForecastApi.new(current_weather_api.query, oauth_token)
  ForecastResponse.new(response).parse(forecast_weather_api.get)
end