Class: FloopFloop::ApiKeys
- Inherits:
-
Object
- Object
- FloopFloop::ApiKeys
- Defined in:
- lib/floopfloop/api_keys.rb
Instance Method Summary collapse
-
#create(name:) ⇒ Object
Returns the IssuedApiKey hash.
-
#initialize(client) ⇒ ApiKeys
constructor
A new instance of ApiKeys.
-
#list ⇒ Object
Returns the array of API key summaries — flattens the => […] wrapper for callers.
-
#remove(id_or_name) ⇒ Object
Revoke by id OR by human-readable name.
Constructor Details
#initialize(client) ⇒ ApiKeys
Returns a new instance of ApiKeys.
5 6 7 |
# File 'lib/floopfloop/api_keys.rb', line 5 def initialize(client) @client = client end |
Instance Method Details
#create(name:) ⇒ Object
Returns the IssuedApiKey hash. The “rawKey” field is the ONLY time the full secret leaves the server — surface it once to the user, then discard.
19 20 21 |
# File 'lib/floopfloop/api_keys.rb', line 19 def create(name:) @client.request("POST", "/api/v1/api-keys", body: { name: name }) end |
#list ⇒ Object
Returns the array of API key summaries — flattens the => […] wrapper for callers.
11 12 13 14 |
# File 'lib/floopfloop/api_keys.rb', line 11 def list data = @client.request("GET", "/api/v1/api-keys") data.is_a?(Hash) ? (data["keys"] || []) : (data || []) end |
#remove(id_or_name) ⇒ Object
Revoke by id OR by human-readable name. Mirrors the Node SDK’s ergonomic shortcut — does a preflight list to resolve the name.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/floopfloop/api_keys.rb', line 25 def remove(id_or_name) match = list.find { |k| k["id"] == id_or_name || k["name"] == id_or_name } unless match raise FloopFloop::Error.new( code: "NOT_FOUND", message: "API key not found: #{id_or_name}", status: 404, ) end @client.request("DELETE", "/api/v1/api-keys/#{url_encode(match['id'])}") nil end |