Class: Mailtrap::SandboxesAPI

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

Direct Known Subclasses

InboxesAPI

Instance Attribute Summary

Attributes included from BaseAPI

#account_id, #client

Instance Method Summary collapse

Methods included from BaseAPI

included, #initialize

Instance Method Details

#clean(sandbox_id) ⇒ Sandbox

Delete all messages (emails) from the sandbox

Parameters:

  • sandbox_id (Integer) —

    The sandbox identifier

Returns:

  • (Sandbox) —

    Updated sandbox object

Raises:



66
67
68
69
# File 'lib/mailtrap/sandboxes_api.rb', line 66

def clean(sandbox_id)
  response = client.patch("#{base_path}/#{sandbox_id}/clean")
  handle_response(response)
end

#create(options) ⇒ Sandbox

Creates a new sandbox

Parameters:

  • options (Hash) —

    The parameters to create

Options Hash (options):

  • :name (String) —

    The sandbox name

  • :project_id (Integer) —

    The project ID. Required.

Returns:

  • (Sandbox) —

    Created sandbox object

Raises:



35
36
37
38
39
40
# File 'lib/mailtrap/sandboxes_api.rb', line 35

def create(options)
  validate_options!(options, supported_options + [:project_id])
  response = client.post("/api/accounts/#{}/projects/#{options[:project_id]}/inboxes",
                         wrap_request(options))
  handle_response(response)
end

#delete(sandbox_id) ⇒ Hash?

Deletes a sandbox

Parameters:

  • sandbox_id (Integer) —

    The sandbox identifier

Returns:

  • (Hash, nil) —

    Deleted sandbox data, or nil when the API returns no content

Raises:



46
47
48
# File 'lib/mailtrap/sandboxes_api.rb', line 46

def delete(sandbox_id)
  base_delete(sandbox_id)
end

#get(sandbox_id) ⇒ Sandbox

Retrieves a specific sandbox

Parameters:

  • sandbox_id (Integer) —

    The sandbox identifier

Returns:

Raises:



24
25
26
# File 'lib/mailtrap/sandboxes_api.rb', line 24

def get(sandbox_id)
  base_get(sandbox_id)
end

#list ⇒ Array<Sandbox>

Lists all sandboxes for the account

Returns:

  • (Array<Sandbox>) —

    Array of sandboxes

Raises:



16
17
18
# File 'lib/mailtrap/sandboxes_api.rb', line 16

def list
  base_list
end

#mark_as_read(sandbox_id) ⇒ Sandbox

Mark all messages in the sandbox as read

Parameters:

  • sandbox_id (Integer) —

    The sandbox identifier

Returns:

  • (Sandbox) —

    Updated sandbox object

Raises:



75
76
77
78
# File 'lib/mailtrap/sandboxes_api.rb', line 75

def mark_as_read(sandbox_id)
  response = client.patch("#{base_path}/#{sandbox_id}/all_read")
  handle_response(response)
end

#reset_credentials(sandbox_id) ⇒ Sandbox

Reset SMTP credentials of the sandbox

Parameters:

  • sandbox_id (Integer) —

    The sandbox identifier

Returns:

  • (Sandbox) —

    Updated sandbox object

Raises:



84
85
86
87
# File 'lib/mailtrap/sandboxes_api.rb', line 84

def reset_credentials(sandbox_id)
  response = client.patch("#{base_path}/#{sandbox_id}/reset_credentials")
  handle_response(response)
end

#reset_email_username(sandbox_id) ⇒ Sandbox

Reset username of email address per sandbox

Parameters:

  • sandbox_id (Integer) —

    The sandbox identifier

Returns:

  • (Sandbox) —

    Updated sandbox object

Raises:



102
103
104
105
# File 'lib/mailtrap/sandboxes_api.rb', line 102

def reset_email_username(sandbox_id)
  response = client.patch("#{base_path}/#{sandbox_id}/reset_email_username")
  handle_response(response)
end

#toggle_email_username(sandbox_id) ⇒ Sandbox

Turn the email address of the sandbox on/off

Parameters:

  • sandbox_id (Integer) —

    The sandbox identifier

Returns:

  • (Sandbox) —

    Updated sandbox object

Raises:



93
94
95
96
# File 'lib/mailtrap/sandboxes_api.rb', line 93

def toggle_email_username(sandbox_id)
  response = client.patch("#{base_path}/#{sandbox_id}/toggle_email_username")
  handle_response(response)
end

#update(sandbox_id, options) ⇒ Sandbox

Updates an existing sandbox

Parameters:

  • sandbox_id (Integer) —

    The sandbox identifier

  • options (Hash) —

    The parameters to update

Options Hash (options):

  • :name (String) —

    The sandbox name

  • :email_username (String) —

    The sandbox email username

Returns:

  • (Sandbox) —

    Updated sandbox object

Raises:



58
59
60
# File 'lib/mailtrap/sandboxes_api.rb', line 58

def update(sandbox_id, options)
  base_update(sandbox_id, options, supported_options + [:email_username])
end