Class: WorkOS::ApiKeys

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ApiKeys

Returns a new instance of ApiKeys.



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

def initialize(client)
  @client = client
end

Instance Method Details

#create_organization_api_key(organization_id:, name:, permissions: nil, request_options: {}) ⇒ WorkOS::ApiKeyWithValue

Create an API key for an organization

Parameters:

  • organization_id (String)

    Unique identifier of the Organization.

  • name (String)

    The name for the API key.

  • permissions (Array<String>, nil) (defaults to: nil)

    The permission slugs to assign to the API key.

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

    (see WorkOS::Types::RequestOptions)

Returns:



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/workos/api_keys.rb', line 106

def create_organization_api_key(
  organization_id:,
  name:,
  permissions: nil,
  request_options: {}
)
  body = {
    "name" => name,
    "permissions" => permissions
  }.compact
  response = @client.request(
    method: :post,
    path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/api_keys",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::ApiKeyWithValue.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

#create_validation(value:, request_options: {}) ⇒ WorkOS::ApiKeyValidationResponse

Validate API key

Parameters:

  • value (String)

    The value for an API key.

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

    (see WorkOS::Types::RequestOptions)

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/workos/api_keys.rb', line 17

def create_validation(
  value:,
  request_options: {}
)
  body = {
    "value" => value
  }.compact
  response = @client.request(
    method: :post,
    path: "/api_keys/validations",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::ApiKeyValidationResponse.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

#delete_api_key(id:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete an API key

Parameters:

  • id (String)

    The unique ID of the API key.

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

    (see WorkOS::Types::RequestOptions)



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/workos/api_keys.rb', line 40

def delete_api_key(
  id:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/api_keys/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#list_organization_api_keys(organization_id:, before: nil, after: nil, limit: nil, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::ApiKey>

List API keys for an organization

Parameters:

  • organization_id (String)

    Unique identifier of the Organization.

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

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.

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

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list.

  • limit (Integer, nil) (defaults to: nil)

    Upper limit on the number of objects to return, between ‘1` and `100`.

  • order (WorkOS::Types::OrganizationsApiKeysOrder, nil) (defaults to: "desc")

    Order the results by the creation time.

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

    (see WorkOS::Types::RequestOptions)

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/workos/api_keys.rb', line 61

def list_organization_api_keys(
  organization_id:,
  before: nil,
  after: nil,
  limit: nil,
  order: "desc",
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order
  }.compact
  response = @client.request(
    method: :get,
    path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/api_keys",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_organization_api_keys(
      organization_id: organization_id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::ApiKey,
    filters: {organization_id: organization_id, before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end