Class: Mailgun::Subaccounts

Inherits:
Object
  • Object
show all
Defined in:
lib/mailgun/subaccounts/subaccounts.rb

Overview

A Mailgun::Subaccounts object is a simple CRUD interface to Mailgun Subaccounts. Uses Mailgun

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client = Mailgun::Client.new(Mailgun.api_key, Mailgun.api_host || 'api.mailgun.net', 'v5')) ⇒ Subaccounts

Public: creates a new Mailgun::Subaccounts instance. Defaults to Mailgun::Client



11
12
13
# File 'lib/mailgun/subaccounts/subaccounts.rb', line 11

def initialize(client = Mailgun::Client.new(Mailgun.api_key, Mailgun.api_host || 'api.mailgun.net', 'v5'))
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/mailgun/subaccounts/subaccounts.rb', line 7

def client
  @client
end

Instance Method Details

#create(name, options = {}) ⇒ Object

Public: Add Subaccount

name - [String] Name of the subaccount being created options - [Hash] of

name - [String] Name of the subaccount being created.
headers       - [String] (Optional) Key Value json dictionary of headers to be stored with the subaccount.
                ex.('{"Subject": "{{subject}}"}')

Returns [Hash] of created subaccount

Raises:



53
54
55
56
57
# File 'lib/mailgun/subaccounts/subaccounts.rb', line 53

def create(name, options = {})
  raise(ParameterError, 'No name given to create subaccount', caller) unless name

  client.post('accounts/subaccounts', options.merge!(name: name)).to_h!
end

#disable(subaccount_id, options = {}) ⇒ Object

Public: Disable a subaccount

subaccount_id - [String] subaccount name to disable options - [Hash] of

headers       - [String] (Optional) Key Value json dictionary of headers to be stored with the subaccount.
                ex.('{"Subject": "{{subject}}"}')

Returns [Hash] Information on the requested subaccount.

Raises:



67
68
69
70
71
# File 'lib/mailgun/subaccounts/subaccounts.rb', line 67

def disable(subaccount_id, options = {})
  raise(ParameterError, 'No Id of subaccount specified', caller) unless subaccount_id

  client.post("accounts/subaccounts/#{subaccount_id}/disable", options).to_h!
end

#enable(subaccount_id, options = {}) ⇒ Object

Public: Enable a subaccount

subaccount_id - [String] subaccount name to enable options - [Hash] of

headers       - [String] (Optional) Key Value json dictionary of headers to be stored with the subaccount.
                ex.('{"Subject": "{{subject}}"}')

Returns [Hash] Information on the requested subaccount.

Raises:



81
82
83
84
85
# File 'lib/mailgun/subaccounts/subaccounts.rb', line 81

def enable(subaccount_id, options = {})
  raise(ParameterError, 'No Id of subaccount specified', caller) unless subaccount_id

  client.post("accounts/subaccounts/#{subaccount_id}/enable", options).to_h!
end

#info(subaccount_id, options = {}) ⇒ Object

Public: Get subaccount information

subaccount_id - [String] subaccount name to lookup for options - [Hash] of

headers       - [String] (Optional) Key Value json dictionary of headers to be stored with the subaccount.
                ex.('{"Subject": "{{subject}}"}')

Returns [Hash] Information on the requested subaccount.

Raises:



38
39
40
41
42
# File 'lib/mailgun/subaccounts/subaccounts.rb', line 38

def info(subaccount_id, options = {})
  raise(ParameterError, 'No Id of subaccount specified', caller) unless subaccount_id

  client.get("accounts/subaccounts/#{subaccount_id}", options).to_h!
end

#list(options = {}) ⇒ Object Also known as: get_subaccounts

Public: Get subaccounts options - [Hash] of

limit  - [Integer] Maximum number of records to return. (10 by default)
skip     [Integer] Number of records to skip
sort     [Array] “asc” or “desc”
enabled  [boolean] (Optional) Returns all enabled/disabled subaccounts, defaults to all if omitted
headers       - [String] (Optional) Key Value json dictionary of headers to be stored with the subaccount.
                ex.('{"Subject": "{{subject}}"}')

Returns [Array] A list of subaccounts (hash)



25
26
27
# File 'lib/mailgun/subaccounts/subaccounts.rb', line 25

def list(options = {})
  client.get('accounts/subaccounts', options).to_h!
end