Class: AccessTokenWrapper::Base
- Inherits:
-
Object
- Object
- AccessTokenWrapper::Base
- Defined in:
- lib/access_token_wrapper.rb
Constant Summary collapse
- NON_ERROR_CODES =
[402, 404, 422, 414, 429, 500, 503]
Instance Attribute Summary collapse
-
#raw_token ⇒ Object
readonly
Returns the value of attribute raw_token.
Instance Method Summary collapse
-
#initialize(raw_token, &callback) ⇒ Base
constructor
A new instance of Base.
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(raw_token, &callback) ⇒ Base
8 9 10 11 |
# File 'lib/access_token_wrapper.rb', line 8 def initialize(raw_token, &callback) @raw_token = raw_token @callback = callback end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/access_token_wrapper.rb', line 13 def method_missing(method, *args, &block) @raw_token.send(method, *args, &block) rescue OAuth2::Error => exception if NON_ERROR_CODES.include?(exception.response.status) raise exception else @raw_token = @raw_token.refresh! @callback.call(@raw_token, exception) @raw_token.send(method, *args, &block) end end |
Instance Attribute Details
#raw_token ⇒ Object (readonly)
Returns the value of attribute raw_token.
6 7 8 |
# File 'lib/access_token_wrapper.rb', line 6 def raw_token @raw_token end |
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
25 26 27 |
# File 'lib/access_token_wrapper.rb', line 25 def respond_to_missing?(method_name, include_private = false) @raw_token.respond_to?(method_name, include_private) || super end |