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
@@ -1,88 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'base_api'
3
+ require_relative 'deprecation'
4
+ require_relative 'domains_api'
4
5
  require_relative 'sending_domain'
5
6
 
6
7
  module Mailtrap
7
- class SendingDomainsAPI
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 = SendingDomain
19
-
20
- # Lists all sending domains for the account
21
- # @return [Array<SendingDomain>] Array of sending 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 sending domain
29
- # @param domain_id [Integer] The sending domain ID
30
- # @return [SendingDomain] Sending domain object
31
- # @!macro api_errors
32
- def get(domain_id)
33
- base_get(domain_id)
34
- end
35
-
36
- # Creates a new sending domain
37
- # @param [Hash] options The parameters to create
38
- # @option options [String] :domain_name The sending domain name
39
- # @return [SendingDomain] Created sending 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 sending domain
47
- # @param domain_id [Integer] The sending 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 sending domain
55
- # @param domain_id [Integer] The sending 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 [SendingDomain] Updated sending 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 sending domain
70
- # @param domain_id [Integer] The sending 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 }
8
+ # @deprecated Use {DomainsAPI} instead.
9
+ class SendingDomainsAPI < DomainsAPI
10
+ def initialize(*)
11
+ Deprecation.warn('Mailtrap::SendingDomainsAPI', 'Mailtrap::DomainsAPI')
12
+ super
86
13
  end
87
14
  end
88
15
  end
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'date'
4
3
  require_relative 'base_api'
4
+ require_relative 'stats_query_params'
5
5
  require_relative 'sending_stats'
6
6
  require_relative 'sending_stat_group'
7
7
 
8
8
  module Mailtrap
9
9
  class StatsAPI
10
10
  include BaseAPI
11
+ include StatsQueryParams
11
12
 
12
- ARRAY_FILTERS = %i[sending_domain_ids sending_streams categories email_service_providers].freeze
13
13
  GROUP_KEYS = {
14
14
  'domains' => :sending_domain_id,
15
15
  'categories' => :category,
@@ -20,7 +20,7 @@ module Mailtrap
20
20
  # Get aggregated sending stats
21
21
  # @param start_date [String, Date, Time] Start date for the stats period (required)
22
22
  # @param end_date [String, Date, Time] End date for the stats period (required)
23
- # @param sending_domain_ids [Array<Integer>] Filter by sending domain IDs
23
+ # @param sending_domain_ids [Array<Integer>] Filter by domain IDs
24
24
  # @param sending_streams [Array<String>] Filter by sending streams
25
25
  # @param categories [Array<String>] Filter by categories
26
26
  # @param email_service_providers [Array<String>] Filter by email service providers
@@ -39,7 +39,7 @@ module Mailtrap
39
39
  # Get sending stats grouped by domain
40
40
  # @param start_date [String, Date, Time] Start date for the stats period (required)
41
41
  # @param end_date [String, Date, Time] End date for the stats period (required)
42
- # @param sending_domain_ids [Array<Integer>] Filter by sending domain IDs
42
+ # @param sending_domain_ids [Array<Integer>] Filter by domain IDs
43
43
  # @param sending_streams [Array<String>] Filter by sending streams
44
44
  # @param categories [Array<String>] Filter by categories
45
45
  # @param email_service_providers [Array<String>] Filter by email service providers
@@ -54,7 +54,7 @@ module Mailtrap
54
54
  # Get sending stats grouped by category
55
55
  # @param start_date [String, Date, Time] Start date for the stats period (required)
56
56
  # @param end_date [String, Date, Time] End date for the stats period (required)
57
- # @param sending_domain_ids [Array<Integer>] Filter by sending domain IDs
57
+ # @param sending_domain_ids [Array<Integer>] Filter by domain IDs
58
58
  # @param sending_streams [Array<String>] Filter by sending streams
59
59
  # @param categories [Array<String>] Filter by categories
60
60
  # @param email_service_providers [Array<String>] Filter by email service providers
@@ -69,7 +69,7 @@ module Mailtrap
69
69
  # Get sending stats grouped by email service provider
70
70
  # @param start_date [String, Date, Time] Start date for the stats period (required)
71
71
  # @param end_date [String, Date, Time] End date for the stats period (required)
72
- # @param sending_domain_ids [Array<Integer>] Filter by sending domain IDs
72
+ # @param sending_domain_ids [Array<Integer>] Filter by domain IDs
73
73
  # @param sending_streams [Array<String>] Filter by sending streams
74
74
  # @param categories [Array<String>] Filter by categories
75
75
  # @param email_service_providers [Array<String>] Filter by email service providers
@@ -84,7 +84,7 @@ module Mailtrap
84
84
  # Get sending stats grouped by date
85
85
  # @param start_date [String, Date, Time] Start date for the stats period (required)
86
86
  # @param end_date [String, Date, Time] End date for the stats period (required)
87
- # @param sending_domain_ids [Array<Integer>] Filter by sending domain IDs
87
+ # @param sending_domain_ids [Array<Integer>] Filter by domain IDs
88
88
  # @param sending_streams [Array<String>] Filter by sending streams
89
89
  # @param categories [Array<String>] Filter by categories
90
90
  # @param email_service_providers [Array<String>] Filter by email service providers
@@ -112,38 +112,6 @@ module Mailtrap
112
112
  end
113
113
  end
114
114
 
115
- def build_query_params(start_date, end_date, filters)
116
- params = { start_date: normalize_date(start_date), end_date: normalize_date(end_date) }
117
-
118
- ARRAY_FILTERS.each do |filter_key|
119
- values = filters[filter_key]
120
- params["#{filter_key}[]"] = values if values
121
- end
122
-
123
- params
124
- end
125
-
126
- def normalize_date(value)
127
- case value
128
- when Date
129
- value.iso8601
130
- when Time
131
- value.strftime('%F')
132
- when String
133
- unless /\A\d{4}-\d{2}-\d{2}\z/.match?(value)
134
- raise ArgumentError,
135
- "Invalid date: #{value.inspect}. Expected a Date, Time, or String in YYYY-MM-DD format."
136
- end
137
-
138
- Date.iso8601(value).iso8601
139
- else
140
- raise ArgumentError,
141
- "Invalid date: #{value.inspect}. Expected a Date, Time, or String in YYYY-MM-DD format."
142
- end
143
- rescue Date::Error
144
- raise ArgumentError, "Invalid date: #{value.inspect}. Expected a Date, Time, or String in YYYY-MM-DD format."
145
- end
146
-
147
115
  def base_path
148
116
  "/api/accounts/#{account_id}/stats"
149
117
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+
5
+ module Mailtrap
6
+ # Query parameters of the sending stats and Email Marketing stats endpoints: the period as
7
+ # +YYYY-MM-DD+ dates and every array filter as a repeated +key[]+ parameter. A +nil+ or empty
8
+ # filter is left out.
9
+ module StatsQueryParams
10
+ private
11
+
12
+ def build_query_params(start_date, end_date, filters)
13
+ params = { start_date: normalize_date(start_date), end_date: normalize_date(end_date) }
14
+ filters.each { |filter_key, values| params["#{filter_key}[]"] = values unless Array(values).empty? }
15
+ params
16
+ end
17
+
18
+ def normalize_date(value)
19
+ case value
20
+ when Date, Time # DateTime is a Date, but its #iso8601 includes the time of day
21
+ return value.strftime('%F')
22
+ when String
23
+ return value if /\A\d{4}-\d{2}-\d{2}\z/.match?(value) && Date.valid_date?(*value.split('-').map(&:to_i))
24
+ end
25
+
26
+ raise ArgumentError, "Invalid date: #{value.inspect}. Expected a Date, Time, or String in YYYY-MM-DD format."
27
+ end
28
+ end
29
+ end
@@ -40,6 +40,19 @@ module Mailtrap
40
40
  base_create(options)
41
41
  end
42
42
 
43
+ # Permanently deletes a sub account under the organization
44
+ #
45
+ # Requires organization admin permissions. The deletion is permanent
46
+ # and removes all data of the sub account. Deleting the last sub account also deletes the organization.
47
+ # A repeated call for the same sub account returns a 404 error.
48
+ # Rate limit: 10 requests per minute per organization.
49
+ # @param sub_account_id [Integer] The sub account ID
50
+ # @return nil
51
+ # @!macro api_errors
52
+ def delete(sub_account_id)
53
+ base_delete(sub_account_id)
54
+ end
55
+
43
56
  private
44
57
 
45
58
  def base_path
@@ -6,7 +6,7 @@ module Mailtrap
6
6
  # @attr_reader id [String] The tracking opt-out UUID
7
7
  # @attr_reader email [String] The email address opted out of tracking
8
8
  # @attr_reader created_at [String] The creation timestamp
9
- # @attr_reader domain_name [String, nil] Sending domain the tracking opt-out applies to
9
+ # @attr_reader domain_name [String, nil] Domain the tracking opt-out applies to
10
10
  TrackingOptOut = Struct.new(
11
11
  :id,
12
12
  :email,
@@ -39,10 +39,10 @@ module Mailtrap
39
39
  )
40
40
  end
41
41
 
42
- # Adds an email address to the tracking opt-out list for a sending domain
42
+ # Adds an email address to the tracking opt-out list for a domain
43
43
  # @param [Hash] options The tracking opt-out attributes
44
44
  # @option options [String] :email Email address to opt out of tracking
45
- # @option options [Integer] :domain_id ID of the sending domain the opt-out applies to
45
+ # @option options [Integer] :domain_id ID of the domain the opt-out applies to
46
46
  # @return [TrackingOptOut] Created tracking opt-out
47
47
  # @!macro api_errors
48
48
  # @raise [ArgumentError] If invalid options are provided
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mailtrap
4
- VERSION = '2.18.0'
4
+ VERSION = '2.20.0'
5
5
  end
@@ -11,7 +11,7 @@ module Mailtrap
11
11
  # @attr_reader payload_format [String] The webhook payload format (`json` or `jsonlines`)
12
12
  # @attr_reader sending_stream [String, nil] The sending stream (`transactional` or `bulk`).
13
13
  # Applicable only for `email_sending` webhooks.
14
- # @attr_reader domain_id [Integer, nil] The sending domain ID the webhook is scoped to,
14
+ # @attr_reader domain_id [Integer, nil] The domain ID the webhook is scoped to,
15
15
  # or nil for all domains. Applicable only for `email_sending` webhooks.
16
16
  # @attr_reader inbound_inbox_id [Integer, nil] The inbound inbox ID the webhook is linked to.
17
17
  # Applicable only for `inbound_receiving` webhooks.
@@ -39,7 +39,7 @@ module Mailtrap
39
39
  # Required for `email_sending` webhook type.
40
40
  # @option options [Array<String>] :event_types Event types to subscribe to.
41
41
  # Required for `email_sending` webhook type.
42
- # @option options [Integer] :domain_id Sending domain ID to scope the webhook to.
42
+ # @option options [Integer] :domain_id Domain ID to scope the webhook to.
43
43
  # Applicable only for `email_sending` webhooks.
44
44
  # @option options [Integer] :inbound_inbox_id Inbound inbox ID to link the webhook to.
45
45
  # Applicable only for `inbound_receiving` webhooks; omit to apply to all inboxes
data/lib/mailtrap.rb CHANGED
@@ -21,10 +21,13 @@ require_relative 'mailtrap/contact_events_api'
21
21
  require_relative 'mailtrap/suppressions_api'
22
22
  require_relative 'mailtrap/tracking_opt_outs_api'
23
23
  require_relative 'mailtrap/email_campaigns_api'
24
+ require_relative 'mailtrap/marketing_stats_api'
25
+ require_relative 'mailtrap/domains_api'
24
26
  require_relative 'mailtrap/sending_domains_api'
25
27
  require_relative 'mailtrap/company_info_api'
26
28
  require_relative 'mailtrap/email_logs_api'
27
29
  require_relative 'mailtrap/projects_api'
30
+ require_relative 'mailtrap/sandboxes_api'
28
31
  require_relative 'mailtrap/inboxes_api'
29
32
  require_relative 'mailtrap/sandbox_messages_api'
30
33
  require_relative 'mailtrap/sandbox_attachments_api'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailtrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.18.0
4
+ version: 2.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Railsware Products Studio LLC
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-10-12 00:00:00.000000000 Z
11
+ date: 2026-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -72,6 +72,9 @@ files:
72
72
  - lib/mailtrap/contact_lists_api.rb
73
73
  - lib/mailtrap/contacts_api.rb
74
74
  - lib/mailtrap/contacts_import_request.rb
75
+ - lib/mailtrap/deprecation.rb
76
+ - lib/mailtrap/domain.rb
77
+ - lib/mailtrap/domains_api.rb
75
78
  - lib/mailtrap/email_campaign.rb
76
79
  - lib/mailtrap/email_campaigns_api.rb
77
80
  - lib/mailtrap/email_log_event.rb
@@ -106,19 +109,24 @@ files:
106
109
  - lib/mailtrap/mail.rb
107
110
  - lib/mailtrap/mail/base.rb
108
111
  - lib/mailtrap/mail/from_template.rb
112
+ - lib/mailtrap/marketing_stats.rb
113
+ - lib/mailtrap/marketing_stats_api.rb
109
114
  - lib/mailtrap/permission_resource.rb
110
115
  - lib/mailtrap/permissions_api.rb
111
116
  - lib/mailtrap/project.rb
112
117
  - lib/mailtrap/projects_api.rb
118
+ - lib/mailtrap/sandbox.rb
113
119
  - lib/mailtrap/sandbox_attachment.rb
114
120
  - lib/mailtrap/sandbox_attachments_api.rb
115
121
  - lib/mailtrap/sandbox_message.rb
116
122
  - lib/mailtrap/sandbox_messages_api.rb
123
+ - lib/mailtrap/sandboxes_api.rb
117
124
  - lib/mailtrap/sending_domain.rb
118
125
  - lib/mailtrap/sending_domains_api.rb
119
126
  - lib/mailtrap/sending_stat_group.rb
120
127
  - lib/mailtrap/sending_stats.rb
121
128
  - lib/mailtrap/stats_api.rb
129
+ - lib/mailtrap/stats_query_params.rb
122
130
  - lib/mailtrap/sub_account.rb
123
131
  - lib/mailtrap/sub_accounts_api.rb
124
132
  - lib/mailtrap/suppression.rb