Class: Courier::AsyncAuthTokensClient

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:) ⇒ AsyncAuthTokensClient

Parameters:



51
52
53
54
# File 'lib/trycourier/auth_tokens/client.rb', line 51

def initialize(request_client:)
  # @type [AsyncRequestClient]
  @request_client = request_client
end

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



47
48
49
# File 'lib/trycourier/auth_tokens/client.rb', line 47

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:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/trycourier/auth_tokens/client.rb', line 62

def issue_token(scope:, expires_in:, request_options: nil)
  Async do
    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
end