Class: Mailtrap::ApiTokensAPI

Inherits:
Object
  • Object
show all
Includes:
BaseAPI
Defined in:
lib/mailtrap/api_tokens_api.rb

Instance Attribute Summary

Attributes included from BaseAPI

#account_id, #client

Instance Method Summary collapse

Methods included from BaseAPI

included, #initialize

Instance Method Details

#create(options) ⇒ ApiToken

Creates a new API token. The full ‘token` value is returned ONLY ONCE — store it securely.

Parameters:

  • options (Hash)

    The parameters to create

Options Hash (options):

  • :name (String)

    Display name for the token

  • :resources (Array<Hash>)

    Permissions to assign

    • ‘{ resource_type:, resource_id:, access_level: }`

Returns:

  • (ApiToken)

    Created token (full ‘token` value populated)

Raises:



38
39
40
# File 'lib/mailtrap/api_tokens_api.rb', line 38

def create(options)
  base_create(options)
end

#delete(token_id) ⇒ Object

Permanently deletes an API token

Parameters:

  • token_id (Integer)

    The API token ID

Returns:

  • nil

Raises:



57
58
59
# File 'lib/mailtrap/api_tokens_api.rb', line 57

def delete(token_id)
  base_delete(token_id)
end

#get(token_id) ⇒ ApiToken

Retrieves a single API token by ID

Parameters:

  • token_id (Integer)

    The API token ID

Returns:

  • (ApiToken)

    API token object (the ‘token` field is nil — full value is only returned by #create and #reset)

Raises:



26
27
28
# File 'lib/mailtrap/api_tokens_api.rb', line 26

def get(token_id)
  base_get(token_id)
end

#listArray<ApiToken>

Lists API tokens visible to the current API token

Returns:

  • (Array<ApiToken>)

    Array of API tokens

Raises:



17
18
19
# File 'lib/mailtrap/api_tokens_api.rb', line 17

def list
  base_list
end

#reset(token_id) ⇒ ApiToken

Expires the requested token and returns a new one with the same permissions. The old token stops working after a short grace period. The new ‘token` value is returned ONLY ONCE — store it securely

Parameters:

  • token_id (Integer)

    The API token ID

Returns:

  • (ApiToken)

    New token (full ‘token` value populated)

Raises:



48
49
50
51
# File 'lib/mailtrap/api_tokens_api.rb', line 48

def reset(token_id)
  response = client.post("#{base_path}/#{token_id}/reset")
  handle_response(response)
end