Class: Apertur::Resources::Keys

Inherits:
Object
  • Object
show all
Defined in:
lib/apertur/resources/keys.rb

Overview

Manage API keys within a project.

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Keys

Returns a new instance of Keys.

Parameters:



8
9
10
# File 'lib/apertur/resources/keys.rb', line 8

def initialize(http)
  @http = http
end

Instance Method Details

#create(project_id, **options) ⇒ Hash

Create a new API key.

Parameters:

  • project_id (String)

    the project ID

  • options (Hash)

    key configuration (e.g. name, scopes)

Returns:

  • (Hash)

    the created key, including the plaintext secret (shown only once)



25
26
27
# File 'lib/apertur/resources/keys.rb', line 25

def create(project_id, **options)
  @http.request(:post, "/api/v1/projects/#{project_id}/keys", body: options)
end

#delete(project_id, key_id) ⇒ nil

Delete an API key.

Parameters:

  • project_id (String)

    the project ID

  • key_id (String)

    the key ID

Returns:

  • (nil)


44
45
46
# File 'lib/apertur/resources/keys.rb', line 44

def delete(project_id, key_id)
  @http.request(:delete, "/api/v1/projects/#{project_id}/keys/#{key_id}")
end

#list(project_id) ⇒ Array<Hash>

List all API keys for a project.

Parameters:

  • project_id (String)

    the project ID

Returns:

  • (Array<Hash>)

    list of API keys



16
17
18
# File 'lib/apertur/resources/keys.rb', line 16

def list(project_id)
  @http.request(:get, "/api/v1/projects/#{project_id}/keys")
end

#set_destinations(key_id, destination_ids, long_polling_enabled: false) ⇒ Hash

Set the destinations and long-polling configuration for a key.

Parameters:

  • key_id (String)

    the key ID

  • destination_ids (Array<String>)

    destination IDs to associate

  • long_polling_enabled (Boolean) (defaults to: false)

    whether to enable long-polling (default: false)

Returns:

  • (Hash)

    the updated key-destinations mapping



54
55
56
57
58
# File 'lib/apertur/resources/keys.rb', line 54

def set_destinations(key_id, destination_ids, long_polling_enabled: false)
  body = { destination_ids: destination_ids }
  body[:long_polling_enabled] = long_polling_enabled unless long_polling_enabled.nil?
  @http.request(:put, "/api/v1/keys/#{key_id}/destinations", body: body)
end

#update(project_id, key_id, **options) ⇒ Hash

Update an existing API key.

Parameters:

  • project_id (String)

    the project ID

  • key_id (String)

    the key ID

  • options (Hash)

    fields to update

Returns:

  • (Hash)

    the updated key



35
36
37
# File 'lib/apertur/resources/keys.rb', line 35

def update(project_id, key_id, **options)
  @http.request(:patch, "/api/v1/projects/#{project_id}/keys/#{key_id}", body: options)
end