Class: PrintStuffMail::Session
- Inherits:
-
Object
- Object
- PrintStuffMail::Session
- Defined in:
- lib/psm/session.rb
Instance Attribute Summary collapse
-
#expiration ⇒ Object
readonly
Returns the value of attribute expiration.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_response ⇒ Object
readonly
Returns the value of attribute last_response.
Instance Method Summary collapse
- #active? ⇒ Boolean (also: #valid?)
- #expired? ⇒ Boolean
-
#initialize(account_id) ⇒ Session
constructor
A new instance of Session.
- #renew! ⇒ Object
- #time_left ⇒ Object
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) @account_id = 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
#expiration ⇒ Object (readonly)
Returns the value of attribute expiration.
13 14 15 |
# File 'lib/psm/session.rb', line 13 def expiration @expiration end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
13 14 15 |
# File 'lib/psm/session.rb', line 13 def id @id end |
#last_response ⇒ Object (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?
36 37 38 |
# File 'lib/psm/session.rb', line 36 def active? not expired? end |
#expired? ⇒ 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_left ⇒ Object
20 21 22 |
# File 'lib/psm/session.rb', line 20 def time_left @expiration - DateTime.now # returns Rational. Wonder which units... end |