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
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.
7 8 9 10 11 12 |
# File 'lib/garage/strategy/access_token.rb', line 7 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.
5 6 7 |
# File 'lib/garage/strategy/access_token.rb', line 5 def raw_response @raw_response end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
5 6 7 |
# File 'lib/garage/strategy/access_token.rb', line 5 def scope @scope end |
#token ⇒ Object
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.
5 6 7 |
# File 'lib/garage/strategy/access_token.rb', line 5 def token_type @token_type end |
Instance Method Details
#acceptable?(required_scopes) ⇒ Boolean
38 39 40 |
# File 'lib/garage/strategy/access_token.rb', line 38 def acceptable?(required_scopes) accessible? && includes_scope?(required_scopes) end |
#accessible? ⇒ Boolean
42 43 44 |
# File 'lib/garage/strategy/access_token.rb', line 42 def accessible? !expired? && !revoked? end |
#application_id ⇒ Object
14 15 16 |
# File 'lib/garage/strategy/access_token.rb', line 14 def application_id @application_id.try(:to_i) end |
#expired? ⇒ Boolean
50 51 52 |
# File 'lib/garage/strategy/access_token.rb', line 50 def expired? !!expired_at.try(:past?) end |
#expired_at ⇒ Object
22 23 24 25 26 |
# File 'lib/garage/strategy/access_token.rb', line 22 def expired_at @expired_at.present? ? Time.zone.parse(@expired_at) : nil rescue ArgumentError, TypeError nil end |
#includes_scope?(required_scopes) ⇒ Boolean
54 55 56 |
# File 'lib/garage/strategy/access_token.rb', line 54 def includes_scope?(required_scopes) required_scopes.blank? || required_scopes.any? { |s| scopes.exists?(s) } end |
#resource_owner_id ⇒ Object
18 19 20 |
# File 'lib/garage/strategy/access_token.rb', line 18 def resource_owner_id @resource_owner_id.try(:to_i) end |
#revoked? ⇒ Boolean
46 47 48 |
# File 'lib/garage/strategy/access_token.rb', line 46 def revoked? !!revoked_at.try(:past?) end |
#revoked_at ⇒ Object
28 29 30 31 32 |
# File 'lib/garage/strategy/access_token.rb', line 28 def revoked_at @revoked_at.present? ? Time.zone.parse(@revoked_at) : nil rescue ArgumentError, TypeError nil end |
#scopes ⇒ Object
34 35 36 |
# File 'lib/garage/strategy/access_token.rb', line 34 def scopes scope.try(:split, ' ') end |