class Barometer::WeatherBug::OauthToken

Public Class Methods

new(oauth_token_api) click to toggle source
# File lib/barometer/weather_bug/oauth_token.rb, line 7
def initialize(oauth_token_api)
  @oauth_token_api = oauth_token_api
  @access_token = nil
  @expires_at = nil
end

Public Instance Methods

access_token() click to toggle source
# File lib/barometer/weather_bug/oauth_token.rb, line 13
def access_token
  refresh_token if stale_token?
  @access_token
end

Private Instance Methods

refresh_token() click to toggle source
# File lib/barometer/weather_bug/oauth_token.rb, line 25
def refresh_token
  response = @oauth_token_api.get
  @access_token = response.fetch(:token)
  @expires_at = Time.now.utc + response.fetch(:expires_in)
end
stale_token?() click to toggle source
# File lib/barometer/weather_bug/oauth_token.rb, line 20
def stale_token?
  @access_token == nil || @expires_at == nil ||
    @expires_at < Time.now.utc
end