Class: WorkOS::Agents

Inherits:
Object
  • Object
show all
Defined in:
lib/workos/agents.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Agents

Returns a new instance of Agents.



9
10
11
# File 'lib/workos/agents.rb', line 9

def initialize(client)
  @client = client
end

Instance Method Details

#create_validate(type:, credential:, audience: nil, request_options: {}) ⇒ WorkOS::AgentCredentialValidation

Validate an agent credential

Parameters:

  • type (WorkOS::Types::AgentAdminValidateCredentialRequestType)

    The kind of credential being validated — an agent API key or an agent access token.

  • credential (String)

    The credential value to validate: the API key value for api_key, or the access token (JWT) for access_token.

  • audience (String, nil) (defaults to: nil)

    When provided, the access token's aud claim is verified against this value. Tokens issued for a different resource are rejected.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/workos/agents.rb', line 51

def create_validate(
  type:,
  credential:,
  audience: nil,
  request_options: {}
)
  body = {
    "type" => type,
    "credential" => credential,
    "audience" => audience
  }.compact
  response = @client.request(
    method: :post,
    path: "/agents/credentials/validate",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::AgentCredentialValidation.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#get_registration(id:, request_options: {}) ⇒ WorkOS::AgentRegistration

Get an agent registration

Parameters:

  • id (String)

    The unique ID of the agent registration.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/workos/agents.rb', line 78

def get_registration(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/agents/registrations/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::AgentRegistration.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#update_attempts(type:, claim_attempt_token:, user:, organization_id: nil, request_options: {}) ⇒ WorkOS::ClaimViewResponse

Link a claim attempt to an external user

Parameters:

  • type (String)

    The operation to perform on the claim attempt. Currently only link_external_user is supported.

  • claim_attempt_token (String)

    The token identifying the claim attempt.

  • user (WorkOS::AgentAdminLinkClaimAttemptToExternalUserRequestUser)

    The user to attach to the claim attempt, identified by email and external ID.

  • organization_id (String, nil) (defaults to: nil)

    The organization to place the agent in. Required when the user belongs to more than one organization.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/workos/agents.rb', line 20

def update_attempts(
  type:,
  claim_attempt_token:,
  user:,
  organization_id: nil,
  request_options: {}
)
  body = {
    "type" => type,
    "claim_attempt_token" => claim_attempt_token,
    "user" => user,
    "organization_id" => organization_id
  }.compact
  response = @client.request(
    method: :patch,
    path: "/agents/claims/attempts",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::ClaimViewResponse.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end