Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ Refer to the [`examples`](examples) folder for more examples:
- [ActionMailer](examples/action_mailer.rb)
- [Email Templates API](examples/email_templates_api.rb)
- [Projects API](examples/projects_api.rb)
- [Sending Domains API](examples/sending_domains_api.rb)

### Content-Transfer-Encoding

Expand Down
29 changes: 29 additions & 0 deletions examples/sending_domains_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'mailtrap'

account_id = 3229
client = Mailtrap::Client.new(api_key: 'your-api-key')
sending_domains = Mailtrap::InboxesAPI.new(account_id, client)

# Create new Sending Domain
sending_domain = sending_domains.create(domain_name: 'example.com')
# => #<struct Mailtrap::SendingDomain id=1, domain_name="example.com">

# Get all Sending Domains
sending_domains.list
# => [#<struct Mailtrap::SendingDomain id=1, domain_name="example.com">]

# Update Sending Domain
sending_domains.update(sending_domain.id, domain_name: 'proper.com')
# => #<struct Mailtrap::SendingDomain id=1, domain_name="proper.com">

# Get sending domain
sending_domain = sending_domains.get(sending_domain.id)
# => #<struct Mailtrap::SendingDomain id=1, domain_name="proper.com">

# Send setup email
sending_domains.clean(sending_domain.id, 'jonathan@mail.com')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is clean?

# => nil

# Delete sending domain
sending_domains.delete(sending_domain.id)
# => nil
1 change: 1 addition & 0 deletions lib/mailtrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require_relative 'mailtrap/contact_imports_api'
require_relative 'mailtrap/suppressions_api'
require_relative 'mailtrap/projects_api'
require_relative 'mailtrap/sending_domains_api'

module Mailtrap
# @!macro api_errors
Expand Down
27 changes: 27 additions & 0 deletions lib/mailtrap/sending_domain.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module Mailtrap
# Data Transfer Object for Sending Domain
# @see https://docs.mailtrap.io/developers/management/sending-domains
# @attr_reader id [Integer] The sending domain ID
# @attr_reader domain_name [String] The sending domain name
# @attr_reader dns_verified [Boolean] Whether the DNS is verified
# @attr_reader compliance_status [String] The compliance status
# @attr_reader created_at [String] The creation timestamp
# @attr_reader updated_at [String] The last update timestamp
#
SendingDomain = Struct.new(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are much more fields that our api returns

:id,
:domain_name,
:dns_verified,
:compliance_status,
:created_at,
:updated_at,
keyword_init: true
) do
# @return [Hash] The SendingDomain attributes as a hash
def to_h
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm

super.compact
end
end
end
67 changes: 67 additions & 0 deletions lib/mailtrap/sending_domains_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# frozen_string_literal: true

require_relative 'base_api'
require_relative 'sending_domain'

module Mailtrap
class SendingDomainsAPI
include BaseAPI

self.supported_options = %i[domain_name]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor. Domain name can be specified only on creation. I'd maybe considered specifying it explicitly when calling base_create.


self.response_class = SendingDomain

# Lists all sending domains for the account
# @return [Array<SendingDomain>] Array of sending domains
# @!macro api_errors
def list
response = client.get(base_path)
response[:data].map { |item| handle_response(item) }
end

# Retrieves a specific sending domain
# @param domain_id [Integer] The sending domain ID
# @return [SendingDomain] Sending domain object
# @!macro api_errors
def get(domain_id)
base_get(domain_id)
end

# Creates a new sending domain
# @param [Hash] options The parameters to create
# @option options [String] :domain_name The sending domain name
# @return [SendingDomain] Created sending domain
# @!macro api_errors
# @raise [ArgumentError] If invalid options are provided
def create(options)
base_create(options)
end

# Deletes a sending domain
# @param domain_id [Integer] The sending domain ID
# @return nil
# @!macro api_errors
def delete(domain_id)
base_delete(domain_id)
end

# Email DNS configuration instructions for the sending domain
# @param domain_id [Integer] The sending domain ID
# @param email [String] The email for instructions
# @return nil
# @!macro api_errors
def send_setup_instructions(domain_id, email)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets use kwargs for email for consistency. see list(email: nil) in suppressions api

client.post("#{base_path}/#{domain_id}/send_setup_instructions", { email: email })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handle the response

end

private

def base_path
"/api/accounts/#{account_id}/sending_domains"
end

def wrap_request(options)
{ sending_domain: options }
end
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading