Class: Mailgun::Subaccounts
- Inherits:
-
Object
- Object
- Mailgun::Subaccounts
- 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
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#create(name, options = {}) ⇒ Object
Public: Add Subaccount.
-
#disable(subaccount_id, options = {}) ⇒ Object
Public: Disable a subaccount.
-
#enable(subaccount_id, options = {}) ⇒ Object
Public: Enable a subaccount.
-
#info(subaccount_id, options = {}) ⇒ Object
Public: Get subaccount information.
-
#initialize(client = Mailgun::Client.new(Mailgun.api_key, Mailgun.api_host || 'api.mailgun.net', 'v5')) ⇒ Subaccounts
constructor
Public: creates a new Mailgun::Subaccounts instance.
-
#list(options = {}) ⇒ Object
(also: #get_subaccounts)
Public: Get subaccounts options - [Hash] of limit - [Integer] Maximum number of records to return.
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
10 11 12 |
# File 'lib/mailgun/subaccounts/subaccounts.rb', line 10 def initialize(client = Mailgun::Client.new(Mailgun.api_key, Mailgun.api_host || 'api.mailgun.net', 'v5')) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/mailgun/subaccounts/subaccounts.rb', line 6 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
51 52 53 54 |
# File 'lib/mailgun/subaccounts/subaccounts.rb', line 51 def create(name, = {}) fail(ParameterError, 'No name given to create subaccount', caller) unless name client.post("accounts/subaccounts", .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.
64 65 66 67 |
# File 'lib/mailgun/subaccounts/subaccounts.rb', line 64 def disable(subaccount_id, = {}) fail(ParameterError, 'No Id of subaccount specified', caller) unless subaccount_id client.post("accounts/subaccounts/#{subaccount_id}/disable", ).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.
77 78 79 80 |
# File 'lib/mailgun/subaccounts/subaccounts.rb', line 77 def enable(subaccount_id, = {}) fail(ParameterError, 'No Id of subaccount specified', caller) unless subaccount_id client.post("accounts/subaccounts/#{subaccount_id}/enable", ).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.
37 38 39 40 |
# File 'lib/mailgun/subaccounts/subaccounts.rb', line 37 def info(subaccount_id, = {}) fail(ParameterError, 'No Id of subaccount specified', caller) unless subaccount_id client.get("accounts/subaccounts/#{subaccount_id}", ).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]
Returns [Array] A list of subaccounts (hash)
24 25 26 |
# File 'lib/mailgun/subaccounts/subaccounts.rb', line 24 def list( = {}) client.get("accounts/subaccounts", ).to_h! end |