class Barometer::WeatherBug

Constants

VERSION

Attributes

api_client_id[R]
api_client_secret[R]
query[R]

Public Class Methods

call(query, config={}) click to toggle source
# File lib/barometer/weather_bug.rb, line 12
def self.call(query, config={})
  WeatherBug.new(query, config).measure!
end
new(query, config={}) click to toggle source
# 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

Public Instance Methods

measure!() click to toggle source
# 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

Private Instance Methods

validate_keys!() click to toggle source
# File lib/barometer/weather_bug.rb, line 42
def validate_keys!
  unless api_client_id && api_client_secret
    raise Barometer::WeatherService::KeyRequired
  end
end