Class: Whop_sdk::APIKeys::Client
- Inherits:
-
Object
- Object
- Whop_sdk::APIKeys::Client
- Defined in:
- lib/whop_sdk/api_keys/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Whop_sdk::Types::APIKey
Creates an API key for an account or app.
-
#delete(request_options: {}, **params) ⇒ Whop_sdk::APIKeys::Types::DeleteAPIKeysResponse
Permanently revokes an API key; requests using its secret stop authenticating immediately.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Whop_sdk::APIKeys::Types::ListAPIKeysResponse
Lists the API keys of an account or app, newest first.
-
#list_permissions(request_options: {}, **_params) ⇒ Whop_sdk::APIKeys::Types::ListPermissionsAPIKeysResponse
Lists the catalog of permission actions that can be granted to users, apps, and API keys — the source for the dashboard's permission pickers.
-
#retrieve(request_options: {}, **params) ⇒ Whop_sdk::Types::APIKey
Retrieves an API key with its effective permission grants.
-
#rotate(request_options: {}, **params) ⇒ Whop_sdk::Types::APIKey
Rotates the API key's secret, invalidating the previous secret immediately.
-
#update(request_options: {}, **params) ⇒ Whop_sdk::Types::APIKey
Updates an API key's name, permissions, API version, expiration, or IP allowlist.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/whop_sdk/api_keys/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Whop_sdk::Types::APIKey
Creates an API key for an account or app. The response is the only place the full secret_key is returned —
store it immediately. Requires a user session; API keys cannot manage API keys.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/whop_sdk/api_keys/client.rb', line 104 def create(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "api_keys", body: Whop_sdk::APIKeys::Types::CreateAPIKeysRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Whop_sdk::Types::APIKey.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#delete(request_options: {}, **params) ⇒ Whop_sdk::APIKeys::Types::DeleteAPIKeysResponse
Permanently revokes an API key; requests using its secret stop authenticating immediately. Default and agent-backend keys cannot be deleted.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/whop_sdk/api_keys/client.rb', line 217 def delete(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "api_keys/#{URI.encode_uri_component(params[:id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Whop_sdk::APIKeys::Types::DeleteAPIKeysResponse.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list(request_options: {}, **params) ⇒ Whop_sdk::APIKeys::Types::ListAPIKeysResponse
Lists the API keys of an account or app, newest first. Responses never include the full secret — only its obfuscated form.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/whop_sdk/api_keys/client.rb', line 41 def list(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["resource_id"] = params[:resource_id] if params.key?(:resource_id) query_params["resource_type"] = params[:resource_type] if params.key?(:resource_type) query_params["created_before"] = params[:created_before] if params.key?(:created_before) query_params["created_after"] = params[:created_after] if params.key?(:created_after) query_params["first"] = params[:first] if params.key?(:first) query_params["after"] = params[:after] if params.key?(:after) query_params["last"] = params[:last] if params.key?(:last) query_params["before"] = params[:before] if params.key?(:before) query_params["order"] = params[:order] if params.key?(:order) query_params["direction"] = params[:direction] if params.key?(:direction) Whop_sdk::Internal::CursorItemIterator.new( cursor_field: :end_cursor, item_field: :data, initial_cursor: query_params["after"] ) do |next_cursor| query_params["after"] = next_cursor request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "api_keys", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) parsed_response = Whop_sdk::APIKeys::Types::ListAPIKeysResponse.load(response.body) [parsed_response, response] else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end end |
#list_permissions(request_options: {}, **_params) ⇒ Whop_sdk::APIKeys::Types::ListPermissionsAPIKeysResponse
Lists the catalog of permission actions that can be granted to users, apps, and API keys — the source for the dashboard's permission pickers. Small and returned in full on one page.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/whop_sdk/api_keys/client.rb', line 142 def (request_options: {}, **_params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "api_keys/permissions", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Whop_sdk::APIKeys::Types::ListPermissionsAPIKeysResponse.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#retrieve(request_options: {}, **params) ⇒ Whop_sdk::Types::APIKey
Retrieves an API key with its effective permission grants. The full secret is never returned — rotate the key if it was lost.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/whop_sdk/api_keys/client.rb', line 179 def retrieve(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "api_keys/#{URI.encode_uri_component(params[:id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Whop_sdk::Types::APIKey.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#rotate(request_options: {}, **params) ⇒ Whop_sdk::Types::APIKey
Rotates the API key's secret, invalidating the previous secret immediately. The response is the only place the
new secret_key is returned.
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/whop_sdk/api_keys/client.rb', line 298 def rotate(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "api_keys/#{URI.encode_uri_component(params[:id].to_s)}/rotate", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Whop_sdk::Types::APIKey.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#update(request_options: {}, **params) ⇒ Whop_sdk::Types::APIKey
Updates an API key's name, permissions, API version, expiration, or IP allowlist. Fields that are omitted keep their current value; default keys cannot be modified.
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/whop_sdk/api_keys/client.rb', line 255 def update(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request_data = Whop_sdk::APIKeys::Types::UpdateAPIKeysRequest.new(params).to_h non_body_param_names = %w[id] body = request_data.except(*non_body_param_names) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "PATCH", path: "api_keys/#{URI.encode_uri_component(params[:id].to_s)}", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Whop_sdk::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Whop_sdk::Types::APIKey.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |