Class: Fakturoid::Oauth::Credentials
- Inherits:
-
Object
- Object
- Fakturoid::Oauth::Credentials
- Defined in:
- lib/fakturoid/oauth/credentials.rb
Constant Summary collapse
- EXPIRY_BUFFER_IN_SECONDS =
10
- MAX_EXPIRY_IN_SECONDS =
2 hours
2 * 3600
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#expires_at ⇒ Object
Returns the value of attribute expires_at.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
-
#token_type ⇒ Object
Returns the value of attribute token_type.
Instance Method Summary collapse
- #access_token_expired? ⇒ Boolean
- #as_json ⇒ Object
- #expires_in=(value) ⇒ Object
-
#initialize(values = {}) ⇒ Credentials
constructor
A new instance of Credentials.
- #update(values) ⇒ Object
Constructor Details
#initialize(values = {}) ⇒ Credentials
Returns a new instance of Credentials.
12 13 14 |
# File 'lib/fakturoid/oauth/credentials.rb', line 12 def initialize(values = {}) update(values) end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
9 10 11 |
# File 'lib/fakturoid/oauth/credentials.rb', line 9 def access_token @access_token end |
#expires_at ⇒ Object
Returns the value of attribute expires_at.
10 11 12 |
# File 'lib/fakturoid/oauth/credentials.rb', line 10 def expires_at @expires_at end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
9 10 11 |
# File 'lib/fakturoid/oauth/credentials.rb', line 9 def refresh_token @refresh_token end |
#token_type ⇒ Object
Returns the value of attribute token_type.
9 10 11 |
# File 'lib/fakturoid/oauth/credentials.rb', line 9 def token_type @token_type end |
Instance Method Details
#access_token_expired? ⇒ Boolean
33 34 35 |
# File 'lib/fakturoid/oauth/credentials.rb', line 33 def access_token_expired? Time.now > (expires_at - EXPIRY_BUFFER_IN_SECONDS) end |
#as_json ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/fakturoid/oauth/credentials.rb', line 37 def as_json { access_token: access_token, refresh_token: refresh_token, expires_at: expires_at.to_datetime, # `DateTime` serializes into is8601, `Time` doesn't, so it can be saved as JSON safely. token_type: token_type } end |
#expires_in=(value) ⇒ Object
29 30 31 |
# File 'lib/fakturoid/oauth/credentials.rb', line 29 def expires_in=(value) self.expires_at = value end |
#update(values) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/fakturoid/oauth/credentials.rb', line 16 def update(values) values = values.transform_keys(&:to_sym) self.access_token = values[:access_token] self.refresh_token = values[:refresh_token] unless Utils.empty?(values[:refresh_token]) self.expires_at = values[:expires_at] || values[:expires_in] self.token_type ||= values[:token_type] end |