class Mailgun::Domains

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

Public Class Methods

new(client = Mailgun::Client.new) click to toggle source

Public: creates a new Mailgun::Domains instance.

Defaults to Mailgun::Client
# File lib/mailgun/domains/domains.rb, line 11
def initialize(client = Mailgun::Client.new)
  @client = client
end

Public Instance Methods

add(domain, options = {})
Alias for: create
add_domain(domain, options = {})
Alias for: create
create(domain, options = {}) click to toggle source

Public: Add domain

domain - [String] Name of the domain (ex. domain.com) options - [Hash] of

smtp_password - [String] Password for SMTP authentication
spam_action   - [String] disabled or tag
  Disable, no spam filtering will occur for inbound messages.
  Tag, messages will be tagged wtih a spam header. See Spam Filter.
wildcard      - [Boolean] true or false Determines whether the domain will accept email for sub-domains.

Returns [Hash] of created domain

# File lib/mailgun/domains/domains.rb, line 62
def create(domain, options = {})
  fail(ParameterError, 'No domain given to add on Mailgun', caller) unless domain
  options = { smtp_password: nil, spam_action: 'disabled', wildcard: false }.merge(options)
  options[:name] = domain
  @client.post('domains', options).to_h
end
Also aliased as: add, add_domain
delete(domain)
Alias for: remove
delete_domain(domain)
Alias for: remove
get(domain)
Alias for: info
get_domain(domain)
Alias for: info
get_domains(options = {})
Alias for: list
info(domain) click to toggle source

Public: Get domain information

domain - [String] Domain name to lookup

Returns [Hash] Information on the requested domains.

# File lib/mailgun/domains/domains.rb, line 31
def info(domain)
  fail(ParameterError, 'No domain given to find on Mailgun', caller) unless domain
  @client.get("domains/#{domain}").to_h!
end
Also aliased as: get, get_domain
list(options = {}) click to toggle source

Public: Get Domains

limit - [Integer] Maximum number of records to return. (100 by default) skip - [Integer] Number of records to skip. (0 by default)

Returns [Array] A list of domains (hash)

# File lib/mailgun/domains/domains.rb, line 21
def list(options = {})
  @client.get('domains', options).to_h['items']
end
Also aliased as: get_domains
remove(domain) click to toggle source

Public: Delete Domain

domain - [String] domain name to delete (ex. domain.com)

Returns [Boolean] if successful or not

# File lib/mailgun/domains/domains.rb, line 76
def remove(domain)
  fail(ParameterError, 'No domain given to remove on Mailgun', caller) unless domain
  @client.delete("domains/#{domain}").to_h['message'] == 'Domain has been deleted'
end
Also aliased as: delete, delete_domain
verify(domain) click to toggle source

Public: Verify domain, update domain records

Unknown status - this is not in the current Mailgun API
Do no rely on this being available in future releases.

domain - [String] Domain name

Returns [Hash] Information on the updated/verified domains

# File lib/mailgun/domains/domains.rb, line 45
def verify(domain)
  fail(ParameterError, 'No domain given to verify on Mailgun', caller) unless domain
  @client.put("domains/#{domain}/verify", nil).to_h!
end
Also aliased as: verify_domain
verify_domain(domain)
Alias for: verify