Class: AccessTokenWrapper::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/access_token_wrapper/base.rb

Direct Known Subclasses

FromRecord

Constant Summary collapse

EXPIRY_GRACE_SEC =
30

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_token, &callback) ⇒ AccessTokenWrapper::Base

This is the core functionality

Examples:

AccessTokenWrapper::Base.new(token) do |new_token, exception|
  update_user_from_access_token(new_token)
end

Parameters:

  • <OAuth2::AccessToken] (<OAuth2::AccessToken] raw_token An instance of an OAuth2::AccessToken object)

    raw_token An instance of an OAuth2::AccessToken object

  • callback (&block)

    A callback that gets called when a token is refreshed, the callback is provided ‘new_token` and optional `exception` parameters



27
28
29
30
# File 'lib/access_token_wrapper/base.rb', line 27

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_name, *args, &block) ⇒ Object (private)



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/access_token_wrapper/base.rb', line 34

def method_missing(method_name, *args, &block)
  refresh_token! if token_expiring?
  @raw_token.send(method_name, *args, &block)
rescue OAuth2::Error => exception
  if non_refreshable_exception?(exception)
    raise
  else
    refresh_token!(exception)
    @raw_token.send(method_name, *args, &block)
  end
end

Instance Attribute Details

#raw_tokenObject (readonly)

Returns the value of attribute raw_token.



11
12
13
# File 'lib/access_token_wrapper/base.rb', line 11

def raw_token
  @raw_token
end

Instance Method Details

#configObject



7
8
9
# File 'lib/access_token_wrapper/base.rb', line 7

def config
  AccessTokenWrapper.configuration
end