Class: Mailtrap::InboundForwardRulesAPI

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

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) ⇒ InboundForwardRulesAPI

Returns a new instance of InboundForwardRulesAPI.

Parameters:

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

    The client instance



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

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

Instance Method Details

#create(inbox_id, options) ⇒ InboundForwardRule

Creates a new forward rule

Parameters:

  • inbox_id (Integer) —

    The inbox ID

  • options (Hash) —

    The parameters to create

Options Hash (options):

  • :name (String) —

    The rule name

  • :conditions (Array<Hash>) —

    The rule conditions

  • :destinations (Array<Hash>) —

    The rule destinations

Returns:

Raises:



47
48
49
50
# File 'lib/mailtrap/inbound_forward_rules_api.rb', line 47

def create(inbox_id, options)
  validate_options!(options, supported_options)
  handle_response(client.post(forward_rules_path(inbox_id), options))
end

#delete(inbox_id, forward_rule_id) ⇒ Object

Deletes a forward rule

Parameters:

  • inbox_id (Integer) —

    The inbox ID

  • forward_rule_id (Integer) —

    The forward rule ID

Returns:

  • nil

Raises:



72
73
74
# File 'lib/mailtrap/inbound_forward_rules_api.rb', line 72

def delete(inbox_id, forward_rule_id)
  client.delete("#{forward_rules_path(inbox_id)}/#{forward_rule_id}")
end

#get(inbox_id, forward_rule_id) ⇒ InboundForwardRule

Retrieves a specific forward rule

Parameters:

  • inbox_id (Integer) —

    The inbox ID

  • forward_rule_id (Integer) —

    The forward rule ID

Returns:

Raises:



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

def get(inbox_id, forward_rule_id)
  handle_response(client.get("#{forward_rules_path(inbox_id)}/#{forward_rule_id}"))
end

#list(inbox_id) ⇒ Array<InboundForwardRule>

Lists forward rules in an inbox

Parameters:

  • inbox_id (Integer) —

    The inbox ID

Returns:

Raises:



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

def list(inbox_id)
  response = client.get(forward_rules_path(inbox_id))
  Array(response[:data]).map { |item| build_rule(item) }
end

#update(inbox_id, forward_rule_id, options) ⇒ InboundForwardRule

Updates a forward rule

Parameters:

  • inbox_id (Integer) —

    The inbox ID

  • forward_rule_id (Integer) —

    The forward rule ID

  • options (Hash) —

    The parameters to update

Options Hash (options):

  • :name (String) —

    The rule name

  • :conditions (Array<Hash>) —

    The rule conditions

  • :destinations (Array<Hash>) —

    The rule destinations

Returns:

Raises:



62
63
64
65
# File 'lib/mailtrap/inbound_forward_rules_api.rb', line 62

def update(inbox_id, forward_rule_id, options)
  validate_options!(options, supported_options)
  handle_response(client.patch("#{forward_rules_path(inbox_id)}/#{forward_rule_id}", options))
end