Class: WorkOS::ApiKeys
- Inherits:
-
Object
- Object
- WorkOS::ApiKeys
- Defined in:
- lib/workos/api_keys.rb
Instance Method Summary collapse
-
#create_organization_api_key(organization_id:, name:, permissions: nil, request_options: {}) ⇒ WorkOS::OrganizationApiKeyWithValue
Create an API key for an organization.
-
#create_validation(value:, request_options: {}) ⇒ WorkOS::ApiKeyValidationResponse
Validate API key.
-
#delete_api_key(id:, request_options: {}) ⇒ void
Delete an API key.
-
#initialize(client) ⇒ ApiKeys
constructor
A new instance of ApiKeys.
-
#list_organization_api_keys(organization_id:, before: nil, after: nil, limit: 10, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::OrganizationApiKey>
List API keys for an organization.
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::OrganizationApiKeyWithValue
Create an API key for an organization
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/workos/api_keys.rb', line 66 def create_organization_api_key( organization_id:, name:, permissions: nil, request_options: {} ) body = { "name" => name, "permissions" => }.compact response = @client.request( method: :post, path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/api_keys", auth: true, body: body, request_options: ) result = WorkOS::OrganizationApiKeyWithValue.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
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/workos/api_keys.rb', line 92 def create_validation( value:, request_options: {} ) body = { "value" => value } response = @client.request( method: :post, path: "/api_keys/validations", auth: true, body: body, 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
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/workos/api_keys.rb', line 115 def delete_api_key( id:, request_options: {} ) @client.request( method: :delete, path: "/api_keys/#{WorkOS::Util.encode_path(id)}", auth: true, request_options: ) nil end |
#list_organization_api_keys(organization_id:, before: nil, after: nil, limit: 10, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::OrganizationApiKey>
List API keys for an organization
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/workos/api_keys.rb', line 21 def list_organization_api_keys( organization_id:, before: nil, after: nil, limit: 10, 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: ) fetch_next = ->(cursor) { list_organization_api_keys( organization_id: organization_id, before: before, after: cursor, limit: limit, order: order, request_options: ) } WorkOS::Types::ListStruct.from_response( response, model: WorkOS::OrganizationApiKey, filters: {organization_id: organization_id, before: before, limit: limit, order: order}, fetch_next: fetch_next ) end |