Class: AbsorbApi::Authorize
- Inherits:
-
Object
- Object
- AbsorbApi::Authorize
- Defined in:
- lib/absorb_api/authorize.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
Instance Method Summary collapse
- #expired? ⇒ Boolean
-
#initialize ⇒ Authorize
constructor
A new instance of Authorize.
- #token ⇒ Object
Constructor Details
#initialize ⇒ Authorize
7 8 9 |
# File 'lib/absorb_api/authorize.rb', line 7 def initialize token end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
5 6 7 |
# File 'lib/absorb_api/authorize.rb', line 5 def created_at @created_at end |
Instance Method Details
#expired? ⇒ Boolean
11 12 13 14 15 |
# File 'lib/absorb_api/authorize.rb', line 11 def expired? return true if created_at.blank? DateTime.now >= created_at + 4.hours end |
#token ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/absorb_api/authorize.rb', line 17 def token return @token unless expired? @token = ActiveSupport::JSON.decode(connection.post do |req| req.url "Authenticate" req.headers["Content-Type"] = "application/json" req.headers["accept"] = "json" req.body = payload.to_json end.body) @created_at = DateTime.now end |