Class: Courier::AuthTokensClient
- Inherits:
-
Object
- Object
- Courier::AuthTokensClient
- Defined in:
- lib/trycourier/auth_tokens/client.rb
Instance Attribute Summary collapse
-
#request_client ⇒ Object
readonly
Returns the value of attribute request_client.
Instance Method Summary collapse
- #initialize(request_client:) ⇒ AuthTokensClient constructor
-
#issue_token(scope:, expires_in:, request_options: nil) ⇒ AuthTokens::IssueTokenResponse
Returns a new access token.
Constructor Details
#initialize(request_client:) ⇒ AuthTokensClient
13 14 15 16 |
# File 'lib/trycourier/auth_tokens/client.rb', line 13 def initialize(request_client:) # @type [RequestClient] @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ Object (readonly)
Returns the value of attribute request_client.
9 10 11 |
# File 'lib/trycourier/auth_tokens/client.rb', line 9 def request_client @request_client end |
Instance Method Details
#issue_token(scope:, expires_in:, request_options: nil) ⇒ AuthTokens::IssueTokenResponse
Returns a new access token.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/trycourier/auth_tokens/client.rb', line 24 def issue_token(scope:, expires_in:, request_options: nil) response = @request_client.conn.post("/auth/issue-token") do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers["Idempotency-Key"] = .idempotency_key unless &.idempotency_key.nil? unless &.idempotency_expiry.nil? req.headers["X-Idempotency-Expiration"] = .idempotency_expiry end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.body = { **(&.additional_body_parameters || {}), scope: scope, expires_in: expires_in }.compact end AuthTokens::IssueTokenResponse.from_json(json_object: response.body) end |