Class: Foil::Server::ApiKeysResource

Inherits:
BaseResource show all
Defined in:
lib/foil/server/client.rb

Instance Method Summary collapse

Methods inherited from BaseResource

#initialize

Constructor Details

This class inherits a constructor from Foil::Server::BaseResource

Instance Method Details

#create(organization_id, name:, type: nil, environment: nil, allowed_origins: nil, scopes: nil) ⇒ Object



236
237
238
239
240
241
242
243
244
245
# File 'lib/foil/server/client.rb', line 236

def create(organization_id, name:, type: nil, environment: nil, allowed_origins: nil, scopes: nil)
  payload = @client.request_json("POST", "/v1/organizations/#{CGI.escape(organization_id)}/api-keys", body: compact({
    name: name,
    type: type,
    environment: environment,
    allowed_origins: allowed_origins,
    scopes: scopes
  }))
  payload[:data]
end

#list(organization_id, limit: nil, cursor: nil) ⇒ Object



247
248
249
250
251
252
253
# File 'lib/foil/server/client.rb', line 247

def list(organization_id, limit: nil, cursor: nil)
  payload = @client.request_json("GET", "/v1/organizations/#{CGI.escape(organization_id)}/api-keys", query: {
    limit: limit,
    cursor: cursor
  })
  list_result(payload)
end

#revoke(organization_id, key_id) ⇒ Object



263
264
265
# File 'lib/foil/server/client.rb', line 263

def revoke(organization_id, key_id)
  @client.request_json("DELETE", "/v1/organizations/#{CGI.escape(organization_id)}/api-keys/#{CGI.escape(key_id)}")[:data]
end

#rotate(organization_id, key_id) ⇒ Object



267
268
269
270
# File 'lib/foil/server/client.rb', line 267

def rotate(organization_id, key_id)
  payload = @client.request_json("POST", "/v1/organizations/#{CGI.escape(organization_id)}/api-keys/#{CGI.escape(key_id)}/rotations")
  payload[:data]
end

#update(organization_id, key_id, name: nil, allowed_origins: nil, scopes: nil) ⇒ Object



255
256
257
258
259
260
261
# File 'lib/foil/server/client.rb', line 255

def update(organization_id, key_id, name: nil, allowed_origins: nil, scopes: nil)
  @client.request_json("PATCH", "/v1/organizations/#{CGI.escape(organization_id)}/api-keys/#{CGI.escape(key_id)}", body: compact({
    name: name,
    allowed_origins: allowed_origins,
    scopes: scopes
  }))[:data]
end