Class: Anypost::Resources::ApiKeys

Inherits:
Base
  • Object
show all
Defined in:
lib/anypost/resources/api_keys.rb

Overview

Operations on the ‘/api-keys` endpoints.

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Anypost::Resources::Base

Instance Method Details

#create(params) ⇒ Object

Issue a new API key.

The plaintext secret is returned only in this response, as ‘key` — store it securely; it cannot be retrieved later.



16
17
18
# File 'lib/anypost/resources/api_keys.rb', line 16

def create(params)
  request_object(:post, "/api-keys", body: params)
end

#delete(id) ⇒ Object

Delete a key. It may keep authenticating for up to 5 minutes (gateway cache).



32
33
34
35
# File 'lib/anypost/resources/api_keys.rb', line 32

def delete(id)
  @http.request(:delete, "/api-keys/#{encode(id)}")
  nil
end

#get(id) ⇒ Object

Retrieve a single API key’s metadata. The secret is never returned.



21
22
23
# File 'lib/anypost/resources/api_keys.rb', line 21

def get(id)
  request_object(:get, "/api-keys/#{encode(id)}")
end

#list(params = {}) ⇒ Object

List the team’s API keys, newest-first.



8
9
10
# File 'lib/anypost/resources/api_keys.rb', line 8

def list(params = {})
  paginate("/api-keys", {limit: params[:limit], after: params[:after]})
end

#update(id, params) ⇒ Object

Update a key’s name, permissions, and restrictions. The secret is not rotated here. Changes may take up to 5 minutes to propagate.



27
28
29
# File 'lib/anypost/resources/api_keys.rb', line 27

def update(id, params)
  request_object(:patch, "/api-keys/#{encode(id)}", body: params)
end