Class: Mailtrap::InboundInboxesAPI

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

Constant Summary collapse

CREATE_OPTIONS =
%i[name domain_id].freeze
UPDATE_OPTIONS =
%i[name].freeze

Instance Attribute Summary

Attributes included from BaseAPI

#account_id, #client

Instance Method Summary collapse

Methods included from BaseAPI

included

Constructor Details

#initialize(client = Mailtrap::Client.new) ⇒ InboundInboxesAPI

Inbound is scoped to the token's account, so no account_id is required.

Parameters:

  • client (Mailtrap::Client) (defaults to: Mailtrap::Client.new)

    The client instance



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

def initialize(client = Mailtrap::Client.new)
  @client = client
end

Instance Method Details

#create(folder_id, options) ⇒ InboundInbox

Creates a new inbox in a folder

Parameters:

  • folder_id (Integer)

    The folder ID

  • options (Hash)

    The parameters to create

Options Hash (options):

  • :name (String)

    The inbox name

  • :domain_id (Integer)

    Attach to a custom domain; omit for a Mailtrap-hosted inbox

Returns:

Raises:



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

def create(folder_id, options)
  validate_options!(options, CREATE_OPTIONS)
  handle_response(client.post(inboxes_path(folder_id), options))
end

#delete(folder_id, inbox_id) ⇒ Object

Deletes an inbox

Parameters:

  • folder_id (Integer)

    The folder ID

  • inbox_id (Integer)

    The inbox ID

Returns:

  • nil

Raises:



69
70
71
# File 'lib/mailtrap/inbound_inboxes_api.rb', line 69

def delete(folder_id, inbox_id)
  client.delete("#{inboxes_path(folder_id)}/#{inbox_id}")
end

#get(folder_id, inbox_id) ⇒ InboundInbox

Retrieves a specific inbox

Parameters:

  • folder_id (Integer)

    The folder ID

  • inbox_id (Integer)

    The inbox ID

Returns:

Raises:



34
35
36
# File 'lib/mailtrap/inbound_inboxes_api.rb', line 34

def get(folder_id, inbox_id)
  handle_response(client.get("#{inboxes_path(folder_id)}/#{inbox_id}"))
end

#list(folder_id) ⇒ Array<InboundInbox>

Lists all inboxes in a folder

Parameters:

  • folder_id (Integer)

    The folder ID

Returns:

Raises:



25
26
27
# File 'lib/mailtrap/inbound_inboxes_api.rb', line 25

def list(folder_id)
  client.get(inboxes_path(folder_id)).map { |item| handle_response(item) }
end

#update(folder_id, inbox_id, options) ⇒ InboundInbox

Updates an inbox

Parameters:

  • folder_id (Integer)

    The folder ID

  • inbox_id (Integer)

    The inbox ID

  • options (Hash)

    The parameters to update

Options Hash (options):

  • :name (String)

    The inbox name

Returns:

Raises:



59
60
61
62
# File 'lib/mailtrap/inbound_inboxes_api.rb', line 59

def update(folder_id, inbox_id, options)
  validate_options!(options, UPDATE_OPTIONS)
  handle_response(client.patch("#{inboxes_path(folder_id)}/#{inbox_id}", options))
end