-
Notifications
You must be signed in to change notification settings - Fork 7
Add Sending domains API #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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') | ||
| # => nil | ||
|
|
||
| # Delete sending domain | ||
| sending_domains.delete(sending_domain.id) | ||
| # => nil | ||
| 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( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rm |
||
| super.compact | ||
| end | ||
| end | ||
| end | ||
| 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] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 }) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is
clean?