Class: Courier::AuthTokensClient

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/auth_tokens/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ AuthTokensClient

Parameters:



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_clientObject (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.

Parameters:

Returns:



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.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    unless request_options&.authorization_token.nil?
      req.headers["Authorization"] =
        request_options.authorization_token
    end
    req.headers["Idempotency-Key"] = request_options.idempotency_key unless request_options&.idempotency_key.nil?
    unless request_options&.idempotency_expiry.nil?
      req.headers["X-Idempotency-Expiration"] = request_options.idempotency_expiry
    end
    req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    req.body = {
      **(request_options&.additional_body_parameters || {}),
      scope: scope,
      expires_in: expires_in
    }.compact
  end
  AuthTokens::IssueTokenResponse.from_json(json_object: response.body)
end