Class: Oauth2ApiClient
- Inherits:
-
Object
- Object
- Oauth2ApiClient
- Defined in:
- lib/oauth2_api_client.rb,
lib/oauth2_api_client/errors.rb,
lib/oauth2_api_client/version.rb,
lib/oauth2_api_client/token_provider.rb
Overview
The Oauth2ApiClient class is a client wrapped around the oauth2 and http-rb gem to interact with APIs using oauth2 for authentication with automatic token caching and renewal.
Defined Under Namespace
Classes: Error, ResponseError, TokenProvider
Constant Summary collapse
- VERSION =
"4.0.0"
Instance Method Summary collapse
-
#initialize(base_url:, token: nil, base_request: HTTP) ⇒ Oauth2ApiClient
constructor
Creates a new Oauth2ApiClient.
- #params(parms = {}) ⇒ Object
-
#token ⇒ String
Returns a oauth2 token to use for authentication.
Constructor Details
#initialize(base_url:, token: nil, base_request: HTTP) ⇒ Oauth2ApiClient
Creates a new Oauth2ApiClient
43 44 45 46 47 |
# File 'lib/oauth2_api_client.rb', line 43 def initialize(base_url:, token: nil, base_request: HTTP) @base_url = base_url @token = token @request = base_request end |
Instance Method Details
#params(parms = {}) ⇒ Object
59 60 61 62 63 |
# File 'lib/oauth2_api_client.rb', line 59 def params(parms = {}) dup.tap do |client| client.instance_variable_set(:@params, (@params || {}).merge(parms)) end end |
#token ⇒ String
Returns a oauth2 token to use for authentication
53 54 55 56 57 |
# File 'lib/oauth2_api_client.rb', line 53 def token return if @token.nil? @token.respond_to?(:to_str) ? @token.to_str : @token.token end |