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::ApiKeyWithValue
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: nil, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::ApiKey>
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::ApiKeyWithValue
Create an API key for an organization
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" => }.compact response = @client.request( method: :post, path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/api_keys", auth: true, body: body, 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
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: ) 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
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: ) 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
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: ) 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::ApiKey, filters: {organization_id: organization_id, before: before, limit: limit, order: order}, fetch_next: fetch_next ) end |