mailtrap 2.18.0 → 2.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.md +42 -7
  5. data/lib/mailtrap/account_accesses_api.rb +2 -2
  6. data/lib/mailtrap/action_mailer/delivery_method.rb +13 -2
  7. data/lib/mailtrap/base_api.rb +6 -0
  8. data/lib/mailtrap/billing_usage.rb +1 -1
  9. data/lib/mailtrap/client.rb +23 -9
  10. data/lib/mailtrap/company_info.rb +1 -1
  11. data/lib/mailtrap/company_info_api.rb +14 -14
  12. data/lib/mailtrap/deprecation.rb +37 -0
  13. data/lib/mailtrap/domain.rb +48 -0
  14. data/lib/mailtrap/domains_api.rb +88 -0
  15. data/lib/mailtrap/email_campaign.rb +3 -3
  16. data/lib/mailtrap/email_campaigns_api.rb +4 -4
  17. data/lib/mailtrap/email_log_message.rb +1 -1
  18. data/lib/mailtrap/inbound_inbox.rb +1 -1
  19. data/lib/mailtrap/inbox.rb +5 -53
  20. data/lib/mailtrap/inboxes_api.rb +7 -108
  21. data/lib/mailtrap/marketing_stats.rb +39 -0
  22. data/lib/mailtrap/marketing_stats_api.rb +43 -0
  23. data/lib/mailtrap/project.rb +1 -1
  24. data/lib/mailtrap/projects_api.rb +2 -2
  25. data/lib/mailtrap/sandbox.rb +57 -0
  26. data/lib/mailtrap/sandbox_attachments_api.rb +15 -7
  27. data/lib/mailtrap/sandbox_message.rb +1 -1
  28. data/lib/mailtrap/sandbox_messages_api.rb +16 -8
  29. data/lib/mailtrap/sandboxes_api.rb +117 -0
  30. data/lib/mailtrap/sending_domain.rb +5 -44
  31. data/lib/mailtrap/sending_domains_api.rb +7 -80
  32. data/lib/mailtrap/stats_api.rb +7 -39
  33. data/lib/mailtrap/stats_query_params.rb +29 -0
  34. data/lib/mailtrap/sub_accounts_api.rb +13 -0
  35. data/lib/mailtrap/tracking_opt_out.rb +1 -1
  36. data/lib/mailtrap/tracking_opt_outs_api.rb +2 -2
  37. data/lib/mailtrap/version.rb +1 -1
  38. data/lib/mailtrap/webhook.rb +1 -1
  39. data/lib/mailtrap/webhooks_api.rb +1 -1
  40. data/lib/mailtrap.rb +3 -0
  41. metadata +10 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df2746012d3720b47808a3bd7b8f44f473b49f53bf30b0b758d4467e0b8a578d
4
- data.tar.gz: ba58958bb95d0344e5107c82b76a2a3a1586ea9bfe16211e07d39e167c119d82
3
+ metadata.gz: 8a046159e9198251d27963e5ca486a98d186f315eb9e853f338a6707b94ba152
4
+ data.tar.gz: bda940049de0bf1a636e139fc954a670c323629167ffe87286cf5381ee2c5406
5
5
  SHA512:
6
- metadata.gz: b3e163c56c0f08fc0be204e73a471fa451d5d8ae2eb87700f223c9e44a8a14161b88f916ac6d0d88b37b14c19807fd4d49424aa71b8075b4d7cbd8c87edbe487
7
- data.tar.gz: f7cde5772e9b716761678f4d230b8f8e2d0ed6ba7b0f4afb5546377f36add5a991cc0f4e4e7cb2a44ee0f7c97419f56f732f31cb4f771ef698f154920007b3d5
6
+ metadata.gz: 9e7142319a03c611d9598832d6938ce24b72e0bd2ec4f342be7f2f48a9c6f9f1f2ca8c99797f50e287991d5548ab07e1e699f6bc46f16e374da88663396cf24e
7
+ data.tar.gz: f49455045dc54e123d18c87fe082e9c339b375c374405e61df66752f864ea312fd50b5116e58957505fb1e70d4ab4605810c2e8a43285a63e53759247e4c9c14
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## [2.20.0] - 2026-11-09
2
+
3
+ ## What's Changed
4
+ * add sub account deletion by @oshchyhol in https://github.com/mailtrap/mailtrap-ruby/pull/130
5
+ * Add Sandbox and Domain names; deprecate the Inbox and SendingDomain names by @Rabsztok in https://github.com/mailtrap/mailtrap-ruby/pull/139
6
+
7
+
8
+ **Full Changelog**: https://github.com/mailtrap/mailtrap-ruby/compare/v2.19.0...v2.20.0
9
+
10
+ ## [2.19.0] - 2026-10-29
11
+
12
+ ## What's Changed
13
+ * Add MarketingStatsAPI for GET /api/marketing/stats by @Rabsztok in https://github.com/mailtrap/mailtrap-ruby/pull/136
14
+ * Fix CI on Ubuntu 26.04 by testing Ruby series, not exact patches by @Rabsztok in https://github.com/mailtrap/mailtrap-ruby/pull/137
15
+
16
+
17
+ **Full Changelog**: https://github.com/mailtrap/mailtrap-ruby/compare/v2.18.0...v2.19.0
18
+
1
19
  ## [2.18.0] - 2026-10-07
2
20
 
3
21
  ## What's Changed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mailtrap (2.18.0)
4
+ mailtrap (2.20.0)
5
5
  base64
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -115,7 +115,7 @@ Send emails to your Sandbox for testing purposes:
115
115
  ```ruby
116
116
  require 'mailtrap'
117
117
 
118
- client = Mailtrap::Client.new(api_key: 'your-api-key', sandbox: true, inbox_id: YOUR_INBOX_ID)
118
+ client = Mailtrap::Client.new(api_key: 'your-api-key', sandbox: true, sandbox_id: YOUR_SANDBOX_ID)
119
119
  client.send(mail)
120
120
 
121
121
  # You can also pass the request parameters directly
@@ -139,9 +139,8 @@ Meaning your recipients will receive emails only in the default encoding which
139
139
  is `quoted-printable`, if you send with Mailtrap API.
140
140
 
141
141
  For those who need to use `7bit` or any other encoding, SMTP provides
142
- better flexibility in that regard. Go to your _Mailtrap account_ → _Email Sending_
143
- → _Sending Domains_ → _Your domain_ → _SMTP/API Settings_ to find the SMTP
144
- configuration example.
142
+ better flexibility in that regard. Go to your _Mailtrap account_ → _Domains_
143
+ → _Your domain_ → _Integration_ to find the SMTP configuration example.
145
144
 
146
145
  ### Multiple Mailtrap Clients
147
146
 
@@ -175,17 +174,17 @@ Email API:
175
174
 
176
175
  - Full Email Sending – [`full.rb`](examples/full.rb)
177
176
  - Batch Sending – [`batch.rb`](examples/batch.rb)
178
- - Sending Domains API – [`sending_domains_api.rb`](examples/sending_domains_api.rb)
177
+ - Domains API – [`domains_api.rb`](examples/domains_api.rb)
179
178
  - Sending Stats API – [`stats_api.rb`](examples/stats_api.rb)
180
179
  - Email Logs API – [`email_logs_api.rb`](examples/email_logs_api.rb)
181
180
  - Webhooks API – [`webhooks_api.rb`](examples/webhooks_api.rb)
182
181
  - Suppressions API – [`suppressions_api.rb`](examples/suppressions_api.rb)
183
182
  - Tracking Opt-outs API – [`tracking_opt_outs_api.rb`](examples/tracking_opt_outs_api.rb)
184
183
 
185
- Email Sandbox (Testing):
184
+ Email Sandbox:
186
185
 
187
186
  - Projects CRUD – [`projects_api.rb`](examples/projects_api.rb)
188
- - Inboxes CRUD - [`inboxes_api.rb`](examples/inboxes_api.rb)
187
+ - Sandboxes CRUD - [`sandboxes_api.rb`](examples/sandboxes_api.rb)
189
188
  - Sandbox Messages CRUD - [`sandbox_messages_api.rb`](examples/sandbox_messages_api.rb)
190
189
  - Sandbox Attachments API - [`sandbox_attachments_api.rb`](examples/sandbox_attachments_api.rb)
191
190
 
@@ -204,6 +203,7 @@ Contact management:
204
203
  Email marketing:
205
204
 
206
205
  - Email Campaigns CRUD, Lifecycle Actions & Stats – [`email_campaigns_api.rb`](examples/email_campaigns_api.rb)
206
+ - Email Marketing Stats API – [`marketing_stats_api.rb`](examples/marketing_stats_api.rb)
207
207
 
208
208
  General:
209
209
 
@@ -212,11 +212,46 @@ General:
212
212
  - API Tokens API – [`api_tokens_api.rb`](examples/api_tokens_api.rb)
213
213
  - Billing API – [`billing_api.rb`](examples/billing_api.rb)
214
214
  - Permissions API – [`permissions_api.rb`](examples/permissions_api.rb)
215
+ - Sub Accounts API (list, create, delete) – [`sub_accounts_api.rb`](examples/sub_accounts_api.rb)
215
216
  - Templates API (experimental) – [`templates_api.rb`](examples/templates_api.rb)
216
217
  - Email Templates API – [`email_templates_api.rb`](examples/email_templates_api.rb)
217
218
  - Action Mailer – [`action_mailer.rb`](examples/action_mailer.rb)
218
219
  - Verifying webhook signatures – [`webhooks_signature_verification.ru`](examples/webhooks_signature_verification.ru)
219
220
 
221
+ ## Renamed APIs
222
+
223
+ Email Sandbox inboxes are now called sandboxes, and sending domains are now called
224
+ domains. The old names still work and call the same API endpoints, but they print a
225
+ deprecation warning and will be removed in a future major release.
226
+
227
+ | Deprecated | Use instead |
228
+ |------------|-------------|
229
+ | `Mailtrap::InboxesAPI` | `Mailtrap::SandboxesAPI` |
230
+ | `Mailtrap::Inbox` | `Mailtrap::Sandbox` |
231
+ | `Mailtrap::SendingDomainsAPI` | `Mailtrap::DomainsAPI` |
232
+ | `Mailtrap::SendingDomain` | `Mailtrap::Domain` |
233
+ | `Mailtrap::Client.new(inbox_id:)` and the ActionMailer `inbox_id` setting | `sandbox_id` |
234
+ | `#inbox_id` on `Client`, `SandboxMessagesAPI` and `SandboxAttachmentsAPI` | `#sandbox_id` |
235
+
236
+ The other old names warn once per process. `Mailtrap::Inbox` and `Mailtrap::SendingDomain`
237
+ use Ruby's `deprecate_constant`, so they warn only when Ruby's deprecation warnings are
238
+ enabled (for example, `ruby -W:deprecated`), and they can warn more than once. Attributes and filters that
239
+ mirror API fields keep their names, such as `SandboxMessage#inbox_id`, `Project#inboxes`
240
+ and the `sending_domain_ids:` stats filter.
241
+
242
+ The once-per-process warnings print whether or not Ruby's deprecation warnings are
243
+ enabled, so `-W:no-deprecated` doesn't hide them. To silence them, filter out the
244
+ warnings tagged `[mailtrap]`:
245
+
246
+ ```ruby
247
+ module SilenceMailtrapDeprecations
248
+ def warn(message, ...)
249
+ super unless message.include?('[mailtrap]')
250
+ end
251
+ end
252
+ Warning.extend(SilenceMailtrapDeprecations)
253
+ ```
254
+
220
255
  ## Migration guide v1 → v2
221
256
 
222
257
  Change `Mailtrap::Sending::Client` to `Mailtrap::Client`.
@@ -9,9 +9,9 @@ module Mailtrap
9
9
 
10
10
  self.response_class = AccountAccess
11
11
 
12
- # Retrieves a list of account accesses with optional filtering by domain, inbox, or project IDs
12
+ # Retrieves a list of account accesses with optional filtering by domain, sandbox, or project IDs
13
13
  # @param domain_ids [Array<Integer>] Optional array of domain IDs to filter by
14
- # @param inbox_ids [Array<Integer>] Optional array of inbox IDs to filter by
14
+ # @param inbox_ids [Array<Integer>] Optional array of sandbox IDs to filter by
15
15
  # @param project_ids [Array<Integer>] Optional array of project IDs to filter by
16
16
  # @return [Array<AccountAccess>] List of account access objects
17
17
  # @!macro api_errors
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../deprecation'
4
+
3
5
  module Mailtrap
4
6
  module ActionMailer
5
7
  class DeliveryMethod
6
8
  attr_accessor :settings
7
9
 
8
- ALLOWED_PARAMS = %i[api_key api_host api_port bulk sandbox inbox_id].freeze
10
+ ALLOWED_PARAMS = %i[api_key api_host api_port bulk sandbox sandbox_id].freeze
9
11
 
10
12
  def initialize(settings)
11
13
  self.settings = settings
@@ -22,7 +24,16 @@ module Mailtrap
22
24
  private
23
25
 
24
26
  def client
25
- @client ||= Mailtrap::Client.new(**settings.slice(*ALLOWED_PARAMS))
27
+ @client ||= Mailtrap::Client.new(**client_settings)
28
+ end
29
+
30
+ def client_settings
31
+ params = settings.slice(*ALLOWED_PARAMS)
32
+ inbox_id = settings[:inbox_id]
33
+ return params if inbox_id.nil?
34
+
35
+ Deprecation.warn('The ActionMailer mailtrap_settings inbox_id', 'sandbox_id')
36
+ params.merge(sandbox_id: Deprecation.resolve_sandbox_id(params[:sandbox_id], inbox_id))
26
37
  end
27
38
  end
28
39
  end
@@ -10,6 +10,12 @@ module Mailtrap
10
10
 
11
11
  module ClassMethods
12
12
  attr_accessor :supported_options, :response_class
13
+
14
+ def inherited(subclass)
15
+ super
16
+ subclass.supported_options = supported_options
17
+ subclass.response_class = response_class
18
+ end
13
19
  end
14
20
 
15
21
  # @param account_id [Integer] The account ID
@@ -4,7 +4,7 @@ module Mailtrap
4
4
  # Data Transfer Object for Billing Usage data
5
5
  # @see https://docs.mailtrap.io/developers/account-management/billing
6
6
  # @attr_reader billing [Hash] The billing cycle details
7
- # @attr_reader testing [Hash] Testing subscription usage
7
+ # @attr_reader testing [Hash] Email Sandbox subscription usage
8
8
  # @attr_reader sending [Hash] Sending subscription usage
9
9
  #
10
10
  BillingUsage = Struct.new(
@@ -3,6 +3,7 @@
3
3
  require 'json'
4
4
  require 'net/http'
5
5
  require 'uri'
6
+ require_relative 'deprecation'
6
7
 
7
8
  module Mailtrap
8
9
  class Client
@@ -12,7 +13,7 @@ module Mailtrap
12
13
  GENERAL_API_HOST = 'mailtrap.io'
13
14
  API_PORT = 443
14
15
 
15
- attr_reader :api_key, :api_host, :general_api_host, :api_port, :bulk, :sandbox, :inbox_id
16
+ attr_reader :api_key, :api_host, :general_api_host, :api_port, :bulk, :sandbox, :sandbox_id
16
17
 
17
18
  # Initializes a new Mailtrap::Client instance.
18
19
  #
@@ -25,8 +26,9 @@ module Mailtrap
25
26
  # If enabled, it is incompatible with `sandbox: true`.
26
27
  # @param [Boolean] sandbox Whether to use the Mailtrap sandbox API. Default: false.
27
28
  # If enabled, it is incompatible with `bulk: true`.
28
- # @param [Integer] inbox_id The sandbox inbox ID to send to. Required if sandbox API is used.
29
- # @raise [ArgumentError] If api_key or api_port is nil, or if sandbox is true but inbox_id is nil,
29
+ # @param [Integer] sandbox_id The sandbox ID to send to. Required if sandbox API is used.
30
+ # @param [Integer] inbox_id Deprecated: use `sandbox_id` instead.
31
+ # @raise [ArgumentError] If api_key or api_port is nil, or if sandbox is true but sandbox_id is nil,
30
32
  # or if incompatible options are provided.
31
33
  def initialize( # rubocop:disable Metrics/ParameterLists
32
34
  api_key: ENV.fetch('MAILTRAP_API_KEY'),
@@ -35,9 +37,14 @@ module Mailtrap
35
37
  api_port: API_PORT,
36
38
  bulk: false,
37
39
  sandbox: false,
40
+ sandbox_id: nil,
38
41
  inbox_id: nil
39
42
  )
40
- validate_args!(api_key, api_port, bulk, sandbox, inbox_id)
43
+ unless inbox_id.nil?
44
+ Deprecation.warn('Mailtrap::Client.new(inbox_id:)', 'Mailtrap::Client.new(sandbox_id:)')
45
+ sandbox_id = Deprecation.resolve_sandbox_id(sandbox_id, inbox_id)
46
+ end
47
+ validate_args!(api_key, api_port, bulk, sandbox, sandbox_id)
41
48
 
42
49
  api_host ||= select_api_host(bulk:, sandbox:)
43
50
 
@@ -47,10 +54,17 @@ module Mailtrap
47
54
  @api_port = api_port
48
55
  @bulk = bulk
49
56
  @sandbox = sandbox
50
- @inbox_id = inbox_id
57
+ @sandbox_id = sandbox_id
51
58
  @http_clients = {}
52
59
  end
53
60
 
61
+ # @deprecated Use {#sandbox_id} instead.
62
+ # @return [Integer, nil] The sandbox ID
63
+ def inbox_id
64
+ Deprecation.warn('Mailtrap::Client#inbox_id', 'Mailtrap::Client#sandbox_id')
65
+ sandbox_id
66
+ end
67
+
54
68
  # Sends a batch of emails.
55
69
  # @example Batch sending with template
56
70
  # batch_base = Mailtrap::Mail.batch_base_from_template(
@@ -235,11 +249,11 @@ module Mailtrap
235
249
 
236
250
  private
237
251
 
238
- def validate_args!(api_key, api_port, bulk, sandbox, inbox_id)
252
+ def validate_args!(api_key, api_port, bulk, sandbox, sandbox_id)
239
253
  raise ArgumentError, 'api_key is required' if api_key.nil?
240
254
  raise ArgumentError, 'api_port is required' if api_port.nil?
241
255
  raise ArgumentError, 'bulk stream is not applicable for sandbox API' if bulk && sandbox
242
- raise ArgumentError, 'inbox_id is required for sandbox API' if sandbox && inbox_id.nil?
256
+ raise ArgumentError, 'sandbox_id is required for sandbox API' if sandbox && sandbox_id.nil?
243
257
  end
244
258
 
245
259
  def select_api_host(bulk:, sandbox:)
@@ -344,11 +358,11 @@ module Mailtrap
344
358
  end
345
359
 
346
360
  def send_path
347
- "/api/send#{"/#{inbox_id}" if sandbox}"
361
+ "/api/send#{"/#{sandbox_id}" if sandbox}"
348
362
  end
349
363
 
350
364
  def batch_request_path
351
- "/api/batch#{"/#{inbox_id}" if sandbox}"
365
+ "/api/batch#{"/#{sandbox_id}" if sandbox}"
352
366
  end
353
367
  end
354
368
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mailtrap
4
- # Data Transfer Object for Sending Domain Company Info
4
+ # Data Transfer Object for Domain Company Info
5
5
  # @see https://docs.mailtrap.io/developers/management/sending-domains
6
6
  # @attr_reader name [String, nil] Company or individual name
7
7
  # @attr_reader address [String, nil] Street address
@@ -22,17 +22,17 @@ module Mailtrap
22
22
 
23
23
  self.response_class = CompanyInfo
24
24
 
25
- # Gets company information for a sending domain
26
- # @param sending_domain_id [Integer] The sending domain ID
25
+ # Gets company information for a domain
26
+ # @param domain_id [Integer] The domain ID
27
27
  # @return [CompanyInfo] Company information
28
28
  # @!macro api_errors
29
- def get(sending_domain_id)
30
- response = client.get(base_path(sending_domain_id))
29
+ def get(domain_id)
30
+ response = client.get(base_path(domain_id))
31
31
  build_entity(response[:data], CompanyInfo)
32
32
  end
33
33
 
34
- # Creates company information for a sending domain
35
- # @param sending_domain_id [Integer] The sending domain ID
34
+ # Creates company information for a domain
35
+ # @param domain_id [Integer] The domain ID
36
36
  # @param [Hash] options The company info attributes
37
37
  # @option options [String] :name Company or individual name
38
38
  # @option options [String] :address Street address
@@ -47,28 +47,28 @@ module Mailtrap
47
47
  # @return [CompanyInfo] Created company information
48
48
  # @!macro api_errors
49
49
  # @raise [ArgumentError] If invalid options are provided
50
- def create(sending_domain_id, options)
50
+ def create(domain_id, options)
51
51
  validate_options!(options, supported_options)
52
- response = client.post(base_path(sending_domain_id), wrap_request(options))
52
+ response = client.post(base_path(domain_id), wrap_request(options))
53
53
  build_entity(response[:data], CompanyInfo)
54
54
  end
55
55
 
56
- # Updates company information for a sending domain
57
- # @param sending_domain_id [Integer] The sending domain ID
56
+ # Updates company information for a domain
57
+ # @param domain_id [Integer] The domain ID
58
58
  # @param [Hash] options The company info attributes to update
59
59
  # @return [CompanyInfo] Updated company information
60
60
  # @!macro api_errors
61
61
  # @raise [ArgumentError] If invalid options are provided
62
- def update(sending_domain_id, options)
62
+ def update(domain_id, options)
63
63
  validate_options!(options, supported_options)
64
- response = client.patch(base_path(sending_domain_id), wrap_request(options))
64
+ response = client.patch(base_path(domain_id), wrap_request(options))
65
65
  build_entity(response[:data], CompanyInfo)
66
66
  end
67
67
 
68
68
  private
69
69
 
70
- def base_path(sending_domain_id)
71
- "/api/accounts/#{account_id}/sending_domains/#{sending_domain_id}/company_info"
70
+ def base_path(domain_id)
71
+ "/api/accounts/#{account_id}/sending_domains/#{domain_id}/company_info"
72
72
  end
73
73
 
74
74
  def wrap_request(options)
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'set'
4
+
5
+ module Mailtrap
6
+ # Emits a deprecation warning once per process for each deprecated name, and maps the
7
+ # deprecated inbox_id onto sandbox_id.
8
+ # @api private
9
+ module Deprecation
10
+ WARNED = Set.new
11
+ MUTEX = Mutex.new
12
+
13
+ # Call it directly from the deprecated method: the warning points at that method's caller.
14
+ # @param old_name [String] The deprecated name
15
+ # @param new_name [String] The name to use instead
16
+ def self.warn(old_name, new_name)
17
+ return unless MUTEX.synchronize { WARNED.add?(old_name) }
18
+
19
+ Kernel.warn(
20
+ "[mailtrap] #{old_name} is deprecated and will be removed in a future major release; " \
21
+ "use #{new_name} instead.",
22
+ uplevel: 2
23
+ )
24
+ end
25
+
26
+ # @param sandbox_id [Integer, String, nil] The ID given as sandbox_id
27
+ # @param inbox_id [Integer, String] The ID given as the deprecated inbox_id
28
+ # @return [Integer, String] The sandbox ID to use
29
+ # @raise [ArgumentError] If both IDs are given and differ
30
+ def self.resolve_sandbox_id(sandbox_id, inbox_id)
31
+ return inbox_id if sandbox_id.nil?
32
+ return sandbox_id if sandbox_id.to_s == inbox_id.to_s
33
+
34
+ raise ArgumentError, 'sandbox_id and inbox_id differ; pass only sandbox_id'
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailtrap
4
+ # Data Transfer Object for Domain
5
+ # @see https://docs.mailtrap.io/developers/management/sending-domains
6
+ # @attr_reader id [Integer] The domain ID
7
+ # @attr_reader domain_name [String] The domain name
8
+ # @attr_reader demo [Boolean] Whether the domain is a demo domain
9
+ # @attr_reader compliance_status [String] The compliance status of the domain
10
+ # @attr_reader dns_verified [Boolean] Whether the DNS records are verified
11
+ # @attr_reader dns_verified_at [String, nil] The timestamp when DNS was verified
12
+ # @attr_reader dns_records [Array] The DNS records for the domain
13
+ # @attr_reader open_tracking_enabled [Boolean] Whether open tracking is enabled
14
+ # @attr_reader click_tracking_enabled [Boolean] Whether click tracking is enabled
15
+ # @attr_reader tracking_opt_out_enabled [Boolean] Whether the tracking opt-out link is enabled
16
+ # @attr_reader auto_unsubscribe_link_enabled [Boolean] Whether auto unsubscribe link is enabled
17
+ # @attr_reader custom_domain_tracking_enabled [Boolean] Whether custom domain tracking is enabled
18
+ # @attr_reader health_alerts_enabled [Boolean] Whether health alerts are enabled
19
+ # @attr_reader critical_alerts_enabled [Boolean] Whether critical alerts are enabled
20
+ # @attr_reader alert_recipient_email [String, nil] The email address for alert recipients
21
+ # @attr_reader inbound_enabled [Boolean] Whether inbound email is enabled for this domain
22
+ # @attr_reader inbound_verified [Boolean] Whether the domain's inbound MX records are verified
23
+ # @attr_reader permissions [Hash] The permissions for the domain
24
+ #
25
+ Domain = Struct.new(
26
+ :id,
27
+ :domain_name,
28
+ :demo,
29
+ :compliance_status,
30
+ :dns_verified,
31
+ :dns_verified_at,
32
+ :dns_records,
33
+ :open_tracking_enabled,
34
+ :click_tracking_enabled,
35
+ :tracking_opt_out_enabled,
36
+ :auto_unsubscribe_link_enabled,
37
+ :custom_domain_tracking_enabled,
38
+ :health_alerts_enabled,
39
+ :critical_alerts_enabled,
40
+ :alert_recipient_email,
41
+ :inbound_enabled,
42
+ :inbound_verified,
43
+ :permissions,
44
+ :created_at,
45
+ :updated_at,
46
+ keyword_init: true
47
+ )
48
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_api'
4
+ require_relative 'domain'
5
+
6
+ module Mailtrap
7
+ class DomainsAPI
8
+ include BaseAPI
9
+
10
+ self.supported_options = %i[
11
+ open_tracking_enabled
12
+ click_tracking_enabled
13
+ tracking_opt_out_enabled
14
+ auto_unsubscribe_link_enabled
15
+ inbound_enabled
16
+ ]
17
+
18
+ self.response_class = Domain
19
+
20
+ # Lists all domains for the account
21
+ # @return [Array<Domain>] Array of domains
22
+ # @!macro api_errors
23
+ def list
24
+ response = client.get(base_path)
25
+ response[:data].map { |item| handle_response(item) }
26
+ end
27
+
28
+ # Retrieves a specific domain
29
+ # @param domain_id [Integer] The domain ID
30
+ # @return [Domain] Domain object
31
+ # @!macro api_errors
32
+ def get(domain_id)
33
+ base_get(domain_id)
34
+ end
35
+
36
+ # Creates a new domain
37
+ # @param [Hash] options The parameters to create
38
+ # @option options [String] :domain_name The domain name
39
+ # @return [Domain] Created domain
40
+ # @!macro api_errors
41
+ # @raise [ArgumentError] If invalid options are provided
42
+ def create(options)
43
+ base_create(options, %i[domain_name])
44
+ end
45
+
46
+ # Deletes a domain
47
+ # @param domain_id [Integer] The domain ID
48
+ # @return nil
49
+ # @!macro api_errors
50
+ def delete(domain_id)
51
+ base_delete(domain_id)
52
+ end
53
+
54
+ # Updates configuration settings for a domain
55
+ # @param domain_id [Integer] The domain ID
56
+ # @param [Hash] options The parameters to update
57
+ # @option options [Boolean] :open_tracking_enabled Enable open tracking for emails sent from this domain
58
+ # @option options [Boolean] :click_tracking_enabled Enable click tracking for links in emails sent from this domain
59
+ # @option options [Boolean] :tracking_opt_out_enabled Enable the tracking opt-out link in tracked emails
60
+ # @option options [Boolean] :auto_unsubscribe_link_enabled Automatically add an unsubscribe link to emails
61
+ # @option options [Boolean] :inbound_enabled Enable inbound email for this domain
62
+ # @return [Domain] Updated domain
63
+ # @!macro api_errors
64
+ # @raise [ArgumentError] If invalid options are provided
65
+ def update(domain_id, options)
66
+ base_update(domain_id, options)
67
+ end
68
+
69
+ # Email DNS configuration instructions for the domain
70
+ # @param domain_id [Integer] The domain ID
71
+ # @param email [String] The email for instructions
72
+ # @return nil
73
+ # @!macro api_errors
74
+ def send_setup_instructions(domain_id, email:)
75
+ client.post("#{base_path}/#{domain_id}/send_setup_instructions", email:)
76
+ end
77
+
78
+ private
79
+
80
+ def base_path
81
+ "/api/accounts/#{account_id}/sending_domains"
82
+ end
83
+
84
+ def wrap_request(options)
85
+ { sending_domain: options }
86
+ end
87
+ end
88
+ end
@@ -39,9 +39,9 @@ module Mailtrap
39
39
  # Data Transfer Object for Email Campaign
40
40
  # @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/email-campaigns
41
41
  # @attr_reader id [Integer] The email campaign ID
42
- # @attr_reader domain_id [Integer] ID of the sending domain used for the campaign,
43
- # as returned by the Sending Domains endpoints
44
- # @attr_reader domain_name [String] Name of the sending domain used for the campaign
42
+ # @attr_reader domain_id [Integer] ID of the domain used for the campaign,
43
+ # as returned by the Domains endpoints
44
+ # @attr_reader domain_name [String] Name of the domain used for the campaign
45
45
  # @attr_reader name [String] Campaign name
46
46
  # @attr_reader from_local_part [String] Local part (before the @) of the From address
47
47
  # @attr_reader from_display_name [String] Display name shown in the From header
@@ -58,8 +58,8 @@ module Mailtrap
58
58
  # Creates a new email campaign in the +draft+ state
59
59
  # @param [Hash] options The parameters to create
60
60
  # @option options [String] :name Campaign name (required)
61
- # @option options [Integer] :domain_id ID of the verified sending domain (required),
62
- # as returned by the Sending Domains endpoints
61
+ # @option options [Integer] :domain_id ID of the verified domain (required),
62
+ # as returned by the Domains endpoints
63
63
  # @option options [String] :from_display_name Display name shown in the From header
64
64
  # @option options [String] :from_local_part Local part (before the @) of the From address (required)
65
65
  # @option options [Hash] :reply_to Reply-To address parts (+display_name+, +local_part+, +domain+)
@@ -82,8 +82,8 @@ module Mailtrap
82
82
  # @param email_campaign_id [Integer] The email campaign ID
83
83
  # @param [Hash] options The parameters to update; accepts the same fields as {#create}
84
84
  # @option options [String] :name Campaign name
85
- # @option options [Integer] :domain_id ID of the verified sending domain,
86
- # as returned by the Sending Domains endpoints
85
+ # @option options [Integer] :domain_id ID of the verified domain,
86
+ # as returned by the Domains endpoints
87
87
  # @option options [String] :from_display_name Display name shown in the From header
88
88
  # @option options [String] :from_local_part Local part (before the @) of the From address
89
89
  # @option options [Hash] :reply_to Reply-To address parts (+display_name+, +local_part+, +domain+)
@@ -17,7 +17,7 @@ module Mailtrap
17
17
  # @attr_reader category [String, nil] Message category
18
18
  # @attr_reader custom_variables [Hash, nil] Custom variables
19
19
  # @attr_reader sending_stream [String] transactional or bulk
20
- # @attr_reader sending_domain_id [Integer] Sending domain ID
20
+ # @attr_reader sending_domain_id [Integer] Domain ID
21
21
  # @attr_reader template_id [Integer, nil] Template ID if sent from template
22
22
  # @attr_reader template_variables [Hash, nil] Template variables
23
23
  # @attr_reader opens_count [Integer] Number of opens
@@ -6,7 +6,7 @@ module Mailtrap
6
6
  # @attr_reader id [Integer] The inbox ID
7
7
  # @attr_reader name [String] The inbox name
8
8
  # @attr_reader address [String] The inbox's inbound address
9
- # @attr_reader domain_id [Integer] The sending domain the inbox is attached to
9
+ # @attr_reader domain_id [Integer] The domain the inbox is attached to
10
10
  InboundInbox = Struct.new(
11
11
  :id,
12
12
  :name,