mailtrap 2.13.0 → 2.14.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e1407023f85d4f46bb34447e8ed5a9cfe5343461ed38008690d9d92006929d1
4
- data.tar.gz: 3efa540454828966a9e6ff4439410d73e69c0c41d8e1e227943ebf1a7cc122dc
3
+ metadata.gz: c0e9b68ca02cc19cc2c9800b4ea92a41082f50e71a79c1df11be822007e462f0
4
+ data.tar.gz: 426de0d20a602d9e792eb71a1fb8d7bfcf5d9b449d5159cff16c1b7e1ac2bb7c
5
5
  SHA512:
6
- metadata.gz: 22ae6dbfc35ff8228eb16d4c3444b9e93eb680f6c59bd4b7b0f2d37629b8c471943ea807c583cc50f50c64267920c67eb80c52a2d8e3dcc7b57379e58c7e7b80
7
- data.tar.gz: e7eb3ff7a9592ffc0918a63c9b75dbe7c81342642c624ded9e2d359136e620f0fc32a6889cee0fef5bf58cd66037ed1370c1b7512d99c623f1f9e033dd7971f4
6
+ metadata.gz: ca735c6afbeca23e39833447203a8988ba07b4cce4e926d78580c4efb8978b51d96afadeaf60975169d2ed44a32be47b1236a803351b9c98c66aa50a7cd8f2dd
7
+ data.tar.gz: defd7a908427006d002903ffe24d286ee7f15fcd2de28497056f2c9b0bf9fabfa1a0c471bb1d4f31ecae5ca8dab272001ce55f5ace461eac7dc5ed18eb8a1740
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [2.14.0] - 2026-08-14
2
+
3
+ ## What's Changed
4
+ * MT-22401: Add Email Campaigns API by @Rabsztok in https://github.com/mailtrap/mailtrap-ruby/pull/119
5
+
6
+
7
+ **Full Changelog**: https://github.com/mailtrap/mailtrap-ruby/compare/v2.13.0...v2.14.0
8
+
1
9
  ## [2.13.0] - 2026-08-04
2
10
 
3
11
  ## What's Changed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mailtrap (2.13.0)
4
+ mailtrap (2.14.0)
5
5
  base64
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -198,6 +198,10 @@ Contact management:
198
198
 
199
199
  - Contacts CRUD & Listing – [`contacts_api.rb`](examples/contacts_api.rb)
200
200
 
201
+ Email marketing:
202
+
203
+ - Email Campaigns CRUD, Lifecycle Actions & Stats – [`email_campaigns_api.rb`](examples/email_campaigns_api.rb)
204
+
201
205
  General:
202
206
 
203
207
  - Accounts API – [`accounts_api.rb`](examples/accounts_api.rb)
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailtrap
4
+ # Data Transfer Object for Email Campaign Stats
5
+ #
6
+ # Aggregated campaign performance metrics. All counts and rates are +0+ when the
7
+ # campaign has not been started.
8
+ # @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/email-campaigns
9
+ # @attr_reader delivery_count [Integer] Number of delivered messages
10
+ # @attr_reader open_count [Integer] Number of opened messages
11
+ # @attr_reader click_count [Integer] Number of clicked messages
12
+ # @attr_reader bounce_count [Integer] Number of bounced messages
13
+ # @attr_reader unsubscription_count [Integer] Number of unsubscriptions
14
+ # @attr_reader sent_count [Integer] Number of sent messages
15
+ # @attr_reader spam_count [Integer] Number of spam complaints
16
+ # @attr_reader delivery_rate [Float] Share of sent messages that were delivered (0–1)
17
+ # @attr_reader open_rate [Float] Share of delivered messages that were opened (0–1)
18
+ # @attr_reader click_rate [Float] Share of delivered messages that were clicked (0–1)
19
+ # @attr_reader bounce_rate [Float] Share of sent messages that bounced (0–1)
20
+ # @attr_reader spam_rate [Float] Share of sent messages marked as spam (0–1)
21
+ # @attr_reader unsubscription_rate [Float] Share of delivered messages that unsubscribed (0–1)
22
+ EmailCampaignStats = Struct.new(
23
+ :delivery_count,
24
+ :open_count,
25
+ :click_count,
26
+ :bounce_count,
27
+ :unsubscription_count,
28
+ :sent_count,
29
+ :spam_count,
30
+ :delivery_rate,
31
+ :open_rate,
32
+ :click_rate,
33
+ :bounce_rate,
34
+ :spam_rate,
35
+ :unsubscription_rate,
36
+ keyword_init: true
37
+ )
38
+
39
+ # Data Transfer Object for Email Campaign
40
+ # @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/email-campaigns
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
45
+ # @attr_reader name [String] Campaign name
46
+ # @attr_reader from_local_part [String] Local part (before the @) of the From address
47
+ # @attr_reader from_display_name [String] Display name shown in the From header
48
+ # @attr_reader reply_to [Hash, nil] Reply-To address parts (+display_name+, +local_part+, +domain+)
49
+ # @attr_reader current_state [String] Lifecycle state (+draft+, +scheduled+, +started+, +queued+,
50
+ # +paused+, +terminating+, +under_review+, +finished+, +failed+, +failed_immediately+)
51
+ # @attr_reader current_state_metadata [Hash, nil] Metadata about the most recent state transition
52
+ # (+reason+, +error+, +errors+ as an array of +{message, rcpt_index}+ objects, +scheduled_at+)
53
+ # @attr_reader created_at [String] The creation timestamp
54
+ # @attr_reader updated_at [String] The last update timestamp
55
+ # @attr_reader last_started_at [String, nil] When the campaign was last started, or +nil+
56
+ # @attr_reader last_started_at_date [String, nil] Date the campaign was last started, present only when started
57
+ # @attr_reader recipient_total_count [Integer, nil] Total number of recipients,
58
+ # or +nil+ until the audience is resolved
59
+ # @attr_reader contact_list_ids [Array<Integer>] IDs of the contact lists included in the campaign's audience
60
+ # @attr_reader contact_segment_ids [Array<Integer>] IDs of the contact segments included in the campaign's audience
61
+ # @attr_reader delivery_mode [String] How the campaign is delivered (+rapid+ or +gradual+)
62
+ # @attr_reader delivery_options [Hash, nil] Delivery throttling options (+emails_per_hour+)
63
+ # @attr_reader template [Hash, nil] The campaign template (+id+, +subject+, +merge_tags+,
64
+ # +body_html+, +body_text+; bodies are omitted on list responses)
65
+ EmailCampaign = Struct.new(
66
+ :id,
67
+ :domain_id,
68
+ :domain_name,
69
+ :name,
70
+ :from_local_part,
71
+ :from_display_name,
72
+ :reply_to,
73
+ :current_state,
74
+ :current_state_metadata,
75
+ :created_at,
76
+ :updated_at,
77
+ :last_started_at,
78
+ :last_started_at_date,
79
+ :recipient_total_count,
80
+ :contact_list_ids,
81
+ :contact_segment_ids,
82
+ :delivery_mode,
83
+ :delivery_options,
84
+ :template,
85
+ keyword_init: true
86
+ )
87
+
88
+ # Response from listing email campaigns (paginated)
89
+ # @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/email-campaigns
90
+ # @attr_reader data [Array<EmailCampaign>] Page of email campaigns, newest first
91
+ # @attr_reader pagination [Hash] Page-token pagination metadata
92
+ # (+token+, +prev_token+, +next_token+, +first_url+, +prev_url+, +current_url+, +next_url+)
93
+ EmailCampaignsListResponse = Struct.new(
94
+ :data,
95
+ :pagination,
96
+ keyword_init: true
97
+ )
98
+ end
@@ -0,0 +1,189 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_api'
4
+ require_relative 'email_campaign'
5
+
6
+ module Mailtrap
7
+ class EmailCampaignsAPI
8
+ include BaseAPI
9
+
10
+ self.supported_options = %i[
11
+ name
12
+ domain_id
13
+ from_display_name
14
+ from_local_part
15
+ reply_to
16
+ template_attributes
17
+ delivery_mode
18
+ delivery_options
19
+ contact_list_ids
20
+ contact_segment_ids
21
+ ].freeze
22
+
23
+ self.response_class = EmailCampaign
24
+
25
+ attr_reader :client
26
+
27
+ # @param client [Mailtrap::Client] The client instance
28
+ def initialize(client = Mailtrap::Client.new)
29
+ @client = client
30
+ end
31
+
32
+ # Lists email campaigns for the account, newest first
33
+ # @param per_page [Integer, nil] Number of campaigns per page (max 100, default 50)
34
+ # @param search [String, nil] Filter campaigns by name
35
+ # @param token [Integer, nil] Page number to retrieve (page-token pagination, default 1)
36
+ # @return [EmailCampaignsListResponse] The page of campaigns and pagination metadata
37
+ # @!macro api_errors
38
+ def list(per_page: nil, search: nil, token: nil)
39
+ query_params = {}
40
+ query_params[:per_page] = per_page unless per_page.nil?
41
+ query_params[:search] = search unless search.nil?
42
+ query_params[:token] = token unless token.nil?
43
+
44
+ response = client.get(base_path, query_params)
45
+
46
+ EmailCampaignsListResponse.new(
47
+ data: Array(response[:data]).map { |item| build_entity(item, response_class) },
48
+ pagination: response[:pagination]
49
+ )
50
+ end
51
+
52
+ # Retrieves a specific email campaign
53
+ # @param email_campaign_id [Integer] The email campaign ID
54
+ # @return [EmailCampaign] Email campaign object
55
+ # @!macro api_errors
56
+ def get(email_campaign_id)
57
+ base_get(email_campaign_id)
58
+ end
59
+
60
+ # Creates a new email campaign in the +draft+ state
61
+ # @param [Hash] options The parameters to create
62
+ # @option options [String] :name Campaign name (required)
63
+ # @option options [Integer] :domain_id ID of the verified sending domain (required),
64
+ # as returned by the Sending Domains endpoints
65
+ # @option options [String] :from_display_name Display name shown in the From header
66
+ # @option options [String] :from_local_part Local part (before the @) of the From address (required)
67
+ # @option options [Hash] :reply_to Reply-To address parts (+display_name+, +local_part+, +domain+)
68
+ # @option options [Hash] :template_attributes Template attributes (+subject+ (required),
69
+ # +body_html+, +body_text+, +merge_tags+)
70
+ # @option options [String] :delivery_mode How the campaign is delivered (+rapid+ or +gradual+)
71
+ # @option options [Hash] :delivery_options Delivery throttling options (+emails_per_hour+),
72
+ # applies when +delivery_mode+ is +gradual+
73
+ # @option options [Array<Integer>] :contact_list_ids IDs of contact lists to send to
74
+ # @option options [Array<Integer>] :contact_segment_ids IDs of contact segments to send to
75
+ # @return [EmailCampaign] Created email campaign
76
+ # @!macro api_errors
77
+ # @raise [ArgumentError] If invalid options are provided
78
+ def create(options)
79
+ base_create(options)
80
+ end
81
+
82
+ # Updates an existing +draft+ email campaign. Only the provided attributes are changed;
83
+ # +template_attributes+ sub-fields are also updated partially, in place.
84
+ # @param email_campaign_id [Integer] The email campaign ID
85
+ # @param [Hash] options The parameters to update; accepts the same fields as {#create}
86
+ # @option options [String] :name Campaign name
87
+ # @option options [Integer] :domain_id ID of the verified sending domain,
88
+ # as returned by the Sending Domains endpoints
89
+ # @option options [String] :from_display_name Display name shown in the From header
90
+ # @option options [String] :from_local_part Local part (before the @) of the From address
91
+ # @option options [Hash] :reply_to Reply-To address parts (+display_name+, +local_part+, +domain+)
92
+ # @option options [Hash] :template_attributes Template attributes (+subject+, +body_html+,
93
+ # +body_text+, +merge_tags+)
94
+ # @option options [String] :delivery_mode How the campaign is delivered (+rapid+ or +gradual+)
95
+ # @option options [Hash] :delivery_options Delivery throttling options (+emails_per_hour+),
96
+ # applies when +delivery_mode+ is +gradual+
97
+ # @option options [Array<Integer>] :contact_list_ids IDs of contact lists to send to
98
+ # @option options [Array<Integer>] :contact_segment_ids IDs of contact segments to send to
99
+ # @return [EmailCampaign] Updated email campaign
100
+ # @!macro api_errors
101
+ # @raise [ArgumentError] If invalid options are provided
102
+ def update(email_campaign_id, options)
103
+ base_update(email_campaign_id, options)
104
+ end
105
+
106
+ # Deletes an email campaign. Only a campaign in the +draft+ state can be deleted.
107
+ # @param email_campaign_id [Integer] The email campaign ID
108
+ # @return [nil]
109
+ # @!macro api_errors
110
+ def delete(email_campaign_id)
111
+ base_delete(email_campaign_id)
112
+ end
113
+
114
+ # Starts sending a +draft+ campaign immediately
115
+ # @param email_campaign_id [Integer] The email campaign ID
116
+ # @return [EmailCampaign] The started email campaign
117
+ # @!macro api_errors
118
+ def start(email_campaign_id)
119
+ perform_action(email_campaign_id, :start)
120
+ end
121
+
122
+ # Schedules a +draft+ campaign to start sending at a future time.
123
+ # The time is reported back in +current_state_metadata.scheduled_at+.
124
+ # @param email_campaign_id [Integer] The email campaign ID
125
+ # @param datetime [String] When to send the campaign (ISO 8601); must be in the future
126
+ # and no more than 1 month ahead
127
+ # @return [EmailCampaign] The scheduled email campaign
128
+ # @!macro api_errors
129
+ def schedule(email_campaign_id, datetime)
130
+ perform_action(email_campaign_id, :schedule, { datetime: })
131
+ end
132
+
133
+ # Cancels a +scheduled+ campaign, returning it to the +draft+ state
134
+ # @param email_campaign_id [Integer] The email campaign ID
135
+ # @return [EmailCampaign] The cancelled email campaign
136
+ # @!macro api_errors
137
+ def cancel(email_campaign_id)
138
+ perform_action(email_campaign_id, :cancel)
139
+ end
140
+
141
+ # Terminates a campaign that is currently sending (+started+, +queued+, or +paused+),
142
+ # aborting the in-flight send
143
+ # @param email_campaign_id [Integer] The email campaign ID
144
+ # @return [EmailCampaign] The terminated email campaign
145
+ # @!macro api_errors
146
+ def terminate(email_campaign_id)
147
+ perform_action(email_campaign_id, :terminate)
148
+ end
149
+
150
+ # Resets a +scheduled+ campaign back to the +draft+ state
151
+ # @param email_campaign_id [Integer] The email campaign ID
152
+ # @return [EmailCampaign] The reset email campaign
153
+ # @!macro api_errors
154
+ def reset(email_campaign_id)
155
+ perform_action(email_campaign_id, :reset)
156
+ end
157
+
158
+ # Retrieves aggregated performance statistics for an email campaign.
159
+ # By default statistics are aggregated since the campaign was last started.
160
+ # @param email_campaign_id [Integer] The email campaign ID
161
+ # @param start_date [String, nil] Start of the aggregation window (inclusive), +YYYY-MM-DD+
162
+ # @param end_date [String, nil] End of the aggregation window (inclusive), +YYYY-MM-DD+
163
+ # @return [EmailCampaignStats] Aggregated campaign statistics
164
+ # @!macro api_errors
165
+ def stats(email_campaign_id, start_date: nil, end_date: nil)
166
+ query_params = {}
167
+ query_params[:start_date] = start_date unless start_date.nil?
168
+ query_params[:end_date] = end_date unless end_date.nil?
169
+
170
+ response = client.get("#{base_path}/#{email_campaign_id}/stats", query_params)
171
+ build_entity(response[:data], EmailCampaignStats)
172
+ end
173
+
174
+ private
175
+
176
+ def perform_action(email_campaign_id, action, body = nil)
177
+ response = client.post("#{base_path}/#{email_campaign_id}/#{action}", body)
178
+ handle_response(response)
179
+ end
180
+
181
+ def base_path
182
+ '/api/email_campaigns'
183
+ end
184
+
185
+ def handle_response(response)
186
+ build_entity(response[:data], response_class)
187
+ end
188
+ end
189
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mailtrap
4
- VERSION = '2.13.0'
4
+ VERSION = '2.14.0'
5
5
  end
data/lib/mailtrap.rb CHANGED
@@ -18,6 +18,7 @@ require_relative 'mailtrap/contact_imports_api'
18
18
  require_relative 'mailtrap/contact_exports_api'
19
19
  require_relative 'mailtrap/contact_events_api'
20
20
  require_relative 'mailtrap/suppressions_api'
21
+ require_relative 'mailtrap/email_campaigns_api'
21
22
  require_relative 'mailtrap/sending_domains_api'
22
23
  require_relative 'mailtrap/company_info_api'
23
24
  require_relative 'mailtrap/email_logs_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.13.0
4
+ version: 2.14.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-08-04 00:00:00.000000000 Z
11
+ date: 2026-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -72,6 +72,8 @@ 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/email_campaign.rb
76
+ - lib/mailtrap/email_campaigns_api.rb
75
77
  - lib/mailtrap/email_log_event.rb
76
78
  - lib/mailtrap/email_log_event_details.rb
77
79
  - lib/mailtrap/email_log_message.rb