Class: PrintStuffMail::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/psm/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account_id) ⇒ Session

Returns a new instance of Session.



15
16
17
18
# File 'lib/psm/session.rb', line 15

def initialize()      
  @account_id = 
  raise "(PSM::Session) couldn't get a session token." unless renew! # We don't want to instantiate unless we can get a session
end

Instance Attribute Details

#expirationObject (readonly)

Returns the value of attribute expiration.



13
14
15
# File 'lib/psm/session.rb', line 13

def expiration
  @expiration
end

#idObject (readonly)

Returns the value of attribute id.



13
14
15
# File 'lib/psm/session.rb', line 13

def id
  @id
end

#last_responseObject (readonly)

Returns the value of attribute last_response.



13
14
15
# File 'lib/psm/session.rb', line 13

def last_response
  @last_response
end

Instance Method Details

#active?Boolean Also known as: valid?

Returns:

  • (Boolean)


36
37
38
# File 'lib/psm/session.rb', line 36

def active?
  not expired?
end

#expired?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/psm/session.rb', line 32

def expired?
  (@expiration - DateTime.now) < 0
end

#renew!Object



24
25
26
27
28
29
30
# File 'lib/psm/session.rb', line 24

def renew!
  @last_response = get_response
  return false unless @last_response['status'] == 201 # We don't have to error out if we can't renew
  @expiration = DateTime.parse(@last_response['expires'])
  @id = @last_response['id']
  true
end

#time_leftObject



20
21
22
# File 'lib/psm/session.rb', line 20

def time_left
  @expiration - DateTime.now # returns Rational. Wonder which units...
end