Class: Redd::AuthStrategies::AuthStrategy
- Defined in:
- lib/redd/auth_strategies/auth_strategy.rb
Overview
The API client for authentication to reddit.
Constant Summary collapse
- AUTH_ENDPOINT =
The API to make authentication requests to.
'https://www.reddit.com'
Constants inherited from Client
Instance Method Summary collapse
-
#authenticate ⇒ Access
abstract
The access token object.
-
#initialize(client_id:, secret:, endpoint: AUTH_ENDPOINT, user_agent: USER_AGENT) ⇒ AuthStrategy
constructor
A new instance of AuthStrategy.
-
#refresh(_access) ⇒ Access
abstract
The new access.
-
#revoke(access) ⇒ Object
Revoke the access token, making it invalid for future requests.
Methods inherited from Client
#delete, #get, #patch, #post, #put, #request
Constructor Details
#initialize(client_id:, secret:, endpoint: AUTH_ENDPOINT, user_agent: USER_AGENT) ⇒ AuthStrategy
Returns a new instance of AuthStrategy.
16 17 18 19 20 |
# File 'lib/redd/auth_strategies/auth_strategy.rb', line 16 def initialize(client_id:, secret:, endpoint: AUTH_ENDPOINT, user_agent: USER_AGENT) super(endpoint: endpoint, user_agent: user_agent) @client_id = client_id @secret = secret end |
Instance Method Details
#authenticate ⇒ Access
This method is abstract.
Perform authentication and return the resulting access object
Returns the access token object.
24 25 26 |
# File 'lib/redd/auth_strategies/auth_strategy.rb', line 24 def authenticate(*) raise 'abstract method: this strategy cannot authenticate with reddit' end |
#refresh(_access) ⇒ Access
This method is abstract.
Refresh the authentication and return the refreshed access
Returns the new access.
31 32 33 |
# File 'lib/redd/auth_strategies/auth_strategy.rb', line 31 def refresh(_access) raise 'abstract method: this strategy cannot refresh access' end |
#revoke(access) ⇒ Object
Revoke the access token, making it invalid for future requests.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/redd/auth_strategies/auth_strategy.rb', line 37 def revoke(access) token = if access.is_a?(String) access elsif access.respond_to?(:refresh_token) access.refresh_token else access.access_token end post('/api/v1/revoke_token', token: token) end |