Class: Zaptec::Credentials
- Inherits:
-
Object
- Object
- Zaptec::Credentials
- Defined in:
- lib/zaptec/credentials.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#expires_at ⇒ Object
Returns the value of attribute expires_at.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #expired?(at = Time.zone.now) ⇒ Boolean
-
#initialize(access_token, expires_at) ⇒ Credentials
constructor
A new instance of Credentials.
Constructor Details
#initialize(access_token, expires_at) ⇒ Credentials
Returns a new instance of Credentials.
5 6 7 8 |
# File 'lib/zaptec/credentials.rb', line 5 def initialize(access_token, expires_at) @access_token = access_token @expires_at = expires_at end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
3 4 5 |
# File 'lib/zaptec/credentials.rb', line 3 def access_token @access_token end |
#expires_at ⇒ Object
Returns the value of attribute expires_at.
3 4 5 |
# File 'lib/zaptec/credentials.rb', line 3 def expires_at @expires_at end |
Class Method Details
.parse(data) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/zaptec/credentials.rb', line 14 def self.parse(data) new( data.fetch("access_token"), Time.zone.at(data.fetch("expires_at")), ) end |
Instance Method Details
#as_json ⇒ Object
21 22 23 |
# File 'lib/zaptec/credentials.rb', line 21 def as_json(*) super.merge("expires_at" => expires_at.to_i) end |
#expired?(at = Time.zone.now) ⇒ Boolean
10 11 12 |
# File 'lib/zaptec/credentials.rb', line 10 def expired?(at = Time.zone.now) expires_at.nil? || at >= expires_at end |