Class: Garage::Strategy::AccessToken
- Inherits:
-
Object
- Object
- Garage::Strategy::AccessToken
- Defined in:
- lib/garage/strategy/access_token.rb
Instance Attribute Summary collapse
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#token_type ⇒ Object
readonly
Returns the value of attribute token_type.
Instance Method Summary collapse
- #acceptable?(required_scopes) ⇒ Boolean
- #accessible? ⇒ Boolean
- #application_id ⇒ Object
- #expired? ⇒ Boolean
- #expired_at ⇒ Object
- #includes_scope?(required_scopes) ⇒ Boolean
-
#initialize(attrs) ⇒ AccessToken
constructor
A new instance of AccessToken.
- #resource_owner_id ⇒ Object
- #revoked? ⇒ Boolean
- #revoked_at ⇒ Object
- #scopes ⇒ Object
Constructor Details
#initialize(attrs) ⇒ AccessToken
Returns a new instance of AccessToken.
6 7 8 9 10 11 |
# File 'lib/garage/strategy/access_token.rb', line 6 def initialize(attrs) @raw_response = attrs @scope, @token, @token_type = attrs[:scope], attrs[:token], attrs[:token_type] @application_id, @resource_owner_id = attrs[:application_id], attrs[:resource_owner_id] @expired_at, @revoked_at = attrs[:expired_at], attrs[:revoked_at] end |
Instance Attribute Details
#raw_response ⇒ Object (readonly)
Returns the value of attribute raw_response.
4 5 6 |
# File 'lib/garage/strategy/access_token.rb', line 4 def raw_response @raw_response end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
4 5 6 |
# File 'lib/garage/strategy/access_token.rb', line 4 def scope @scope end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
4 5 6 |
# File 'lib/garage/strategy/access_token.rb', line 4 def token @token end |
#token_type ⇒ Object (readonly)
Returns the value of attribute token_type.
4 5 6 |
# File 'lib/garage/strategy/access_token.rb', line 4 def token_type @token_type end |
Instance Method Details
#acceptable?(required_scopes) ⇒ Boolean
37 38 39 |
# File 'lib/garage/strategy/access_token.rb', line 37 def acceptable?(required_scopes) accessible? && includes_scope?(required_scopes) end |
#accessible? ⇒ Boolean
41 42 43 |
# File 'lib/garage/strategy/access_token.rb', line 41 def accessible? !expired? && !revoked? end |
#application_id ⇒ Object
13 14 15 |
# File 'lib/garage/strategy/access_token.rb', line 13 def application_id @application_id.try(:to_i) end |
#expired? ⇒ Boolean
49 50 51 |
# File 'lib/garage/strategy/access_token.rb', line 49 def expired? !!expired_at.try(:past?) end |
#expired_at ⇒ Object
21 22 23 24 25 |
# File 'lib/garage/strategy/access_token.rb', line 21 def expired_at @expired_at.present? ? Time.zone.parse(@expired_at) : nil rescue ArgumentError, TypeError nil end |
#includes_scope?(required_scopes) ⇒ Boolean
53 54 55 |
# File 'lib/garage/strategy/access_token.rb', line 53 def includes_scope?(required_scopes) required_scopes.blank? || required_scopes.any? { |s| scopes.exists?(s) } end |
#resource_owner_id ⇒ Object
17 18 19 |
# File 'lib/garage/strategy/access_token.rb', line 17 def resource_owner_id @resource_owner_id.try(:to_i) end |
#revoked? ⇒ Boolean
45 46 47 |
# File 'lib/garage/strategy/access_token.rb', line 45 def revoked? !!revoked_at.try(:past?) end |
#revoked_at ⇒ Object
27 28 29 30 31 |
# File 'lib/garage/strategy/access_token.rb', line 27 def revoked_at @revoked_at.present? ? Time.zone.parse(@revoked_at) : nil rescue ArgumentError, TypeError nil end |
#scopes ⇒ Object
33 34 35 |
# File 'lib/garage/strategy/access_token.rb', line 33 def scopes scope.try(:split, ' ') end |