class SparkApi::Authentication::OAuthSession

Representation of a session with the api using oauth2

Constants

SESSION_ATTRIBUTES

Public Class Methods

new(o={}) click to toggle source
# File lib/spark_api/authentication/oauth2.rb, line 158
def initialize(o={})

  options = OptionsHash.new(o)

  @access_token = options["access_token"]
  @expires_in = options["expires_in"]
  @scope = options["scope"]
  @refresh_token = options["refresh_token"]
  @start_time = options.fetch("start_time", DateTime.now)
  @refresh_timeout = options.fetch("refresh_timeout", 43200)
  if @start_time.is_a? String
    @start_time = DateTime.parse(@start_time)
  end
end

Public Instance Methods

expired?() click to toggle source

Is the user session token expired?

# File lib/spark_api/authentication/oauth2.rb, line 173
def expired?
  return false if @expires_in.nil?
  @start_time + Rational(@expires_in - @refresh_timeout, 86400) < DateTime.now
end
to_hash() click to toggle source
# File lib/spark_api/authentication/oauth2.rb, line 182
def to_hash
  hash = {}
  SESSION_ATTRIBUTES.each do |k|
    value = self.send(k)
    hash[k.to_s] = value unless value.nil?
  end
  hash 
end
to_json(*a) click to toggle source
# File lib/spark_api/authentication/oauth2.rb, line 178
def to_json(*a)
  to_hash.to_json(*a)
end