Class: Mailgun::Domains
- Inherits:
-
Object
- Object
- Mailgun::Domains
- Defined in:
- lib/mailgun/domains/domains.rb
Overview
A Mailgun::Domains object is a simple CRUD interface to Mailgun Domains. Uses Mailgun
Instance Method Summary collapse
-
#create(domain, options = {}) ⇒ Object
(also: #add, #add_domain)
Public: Add domain.
-
#info(domain) ⇒ Object
(also: #get, #get_domain)
Public: Get domain information.
-
#initialize(client = Mailgun::Client.new) ⇒ Domains
constructor
Public: creates a new Mailgun::Domains instance.
-
#list(options = {}) ⇒ Object
(also: #get_domains)
Public: Get Domains.
-
#remove(domain) ⇒ Object
(also: #delete, #delete_domain)
Public: Delete Domain.
-
#verify(domain) ⇒ Object
(also: #verify_domain)
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.
Constructor Details
#initialize(client = Mailgun::Client.new) ⇒ Domains
Public: creates a new Mailgun::Domains instance.
Defaults to Mailgun::Client
11 12 13 |
# File 'lib/mailgun/domains/domains.rb', line 11 def initialize(client = Mailgun::Client.new) @client = client end |
Instance Method Details
#create(domain, options = {}) ⇒ Object Also known as: add, add_domain
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 .
Tag, 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
62 63 64 65 66 67 |
# File 'lib/mailgun/domains/domains.rb', line 62 def create(domain, = {}) fail(ParameterError, 'No domain given to add on Mailgun', caller) unless domain = { smtp_password: nil, spam_action: 'disabled', wildcard: false }.merge() [:name] = domain @client.post('domains', ).to_h end |
#info(domain) ⇒ Object Also known as: get, get_domain
Public: Get domain information
domain - [String] Domain name to lookup
Returns [Hash] Information on the requested domains.
31 32 33 34 |
# 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 |
#list(options = {}) ⇒ Object Also known as: get_domains
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)
21 22 23 |
# File 'lib/mailgun/domains/domains.rb', line 21 def list( = {}) @client.get('domains', ).to_h['items'] end |
#remove(domain) ⇒ Object Also known as: delete, delete_domain
Public: Delete Domain
domain - [String] domain name to delete (ex. domain.com)
Returns [Boolean] if successful or not
76 77 78 79 |
# 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 |
#verify(domain) ⇒ Object Also known as: verify_domain
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
45 46 47 48 |
# 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 |