mailtrap 2.4.1 → 2.4.2

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: 9051a9ecb98e5863ddcf088f3f7e46e0adc5c78704feb50cf83d96e5f8291b55
4
- data.tar.gz: 991d829e6b2a412c710e45d5731cebd42430546b40aac3147fd618686faa3f82
3
+ metadata.gz: fbab8dc3de2d25ab941149a0324bde111b57ce174a3b4d6c7f9233a2081edaf6
4
+ data.tar.gz: 2504ee84dc9fea519b8fef55c9adf9e160f28f2e400a28d9b228db0fb82a3bcf
5
5
  SHA512:
6
- metadata.gz: c657894990e6ddef1d77f6ab380e56fbbf66f9286087ee3f10e6f14c63708ac09fcecfd547c095cb91240fa7c50674cffa6cbae917c8b5ee75a5b1be91a0a03d
7
- data.tar.gz: eb1e87d218d66bcdbb8fe0c9a27d1912e8171836b08270f1221247edb08c1577e3e0932b7b9ef4e8aa29adca4dc56aec7a68b6f821f0065cf2ff1defcf4518a6
6
+ metadata.gz: 60f24be1ea02688b21315cd2b33c17b7ef09d5e11c2695f7f237c6fadac1bd0c9aa2458b74713f3ffb13421bc1d58237fd12b5b6a5a101be00e5530f9ebf86a5
7
+ data.tar.gz: 53e05d3a12c3f68cd5ade6cb844e3316902594be51aa85a624941ad7c501765bbf8302d985f6c9a27028034397a794281d4266d06580ffdb5b289d876c3ac28d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mailtrap (2.4.1)
4
+ mailtrap (2.4.2)
5
5
  base64
6
6
 
7
7
  GEM
@@ -65,7 +65,7 @@ GEM
65
65
  regexp_parser (2.10.0)
66
66
  reline (0.6.1)
67
67
  io-console (~> 0.5)
68
- rexml (3.4.1)
68
+ rexml (3.4.2)
69
69
  rspec (3.13.0)
70
70
  rspec-core (~> 3.13.0)
71
71
  rspec-expectations (~> 3.13.0)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![test](https://github.com/railsware/mailtrap-ruby/actions/workflows/main.yml/badge.svg)](https://github.com/railsware/mailtrap-ruby/actions/workflows/main.yml)
1
+ [![test](https://github.com/mailtrap/mailtrap-ruby/actions/workflows/main.yml/badge.svg)](https://github.com/mailtrap/mailtrap-ruby/actions/workflows/main.yml)
2
2
  [![docs](https://shields.io/badge/docs-rubydoc.info-blue)](https://rubydoc.info/gems/mailtrap)
3
3
  [![gem](https://shields.io/gem/v/mailtrap)](https://rubygems.org/gems/mailtrap)
4
4
  [![downloads](https://shields.io/gem/dt/mailtrap)](https://rubygems.org/gems/mailtrap)
@@ -182,7 +182,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
182
182
 
183
183
  ## Contributing
184
184
 
185
- Bug reports and pull requests are welcome on [GitHub](https://github.com/railsware/mailtrap-ruby). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
185
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/mailtrap/mailtrap-ruby). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
186
186
 
187
187
  ## License
188
188
 
@@ -64,8 +64,8 @@ module Mailtrap
64
64
  client.delete("#{base_path}/#{id}")
65
65
  end
66
66
 
67
- def base_list
68
- response = client.get(base_path)
67
+ def base_list(query_params = {})
68
+ response = client.get(base_path, query_params)
69
69
  response.map { |item| handle_response(item) }
70
70
  end
71
71
 
@@ -119,10 +119,15 @@ module Mailtrap
119
119
  # @!macro api_errors
120
120
  # @raise [Mailtrap::MailSizeError] If the message is too large.
121
121
  def send_batch(base, requests)
122
- perform_request(:post, api_host, batch_request_path, {
123
- base:,
124
- requests:
125
- })
122
+ perform_request(
123
+ method: :post,
124
+ host: api_host,
125
+ path: batch_request_path,
126
+ body: {
127
+ base:,
128
+ requests:
129
+ }
130
+ )
126
131
  end
127
132
 
128
133
  # Sends an email
@@ -152,15 +157,26 @@ module Mailtrap
152
157
  # @!macro api_errors
153
158
  # @raise [Mailtrap::MailSizeError] If the message is too large
154
159
  def send(mail)
155
- perform_request(:post, api_host, send_path, mail)
160
+ perform_request(
161
+ method: :post,
162
+ host: api_host,
163
+ path: send_path,
164
+ body: mail
165
+ )
156
166
  end
157
167
 
158
168
  # Performs a GET request to the specified path
159
169
  # @param path [String] The request path
170
+ # @param query_params [Hash] Query parameters to append to the URL (optional)
160
171
  # @return [Hash, nil] The JSON response
161
172
  # @!macro api_errors
162
- def get(path)
163
- perform_request(:get, general_api_host, path)
173
+ def get(path, query_params = {})
174
+ perform_request(
175
+ method: :get,
176
+ host: general_api_host,
177
+ path:,
178
+ query_params:
179
+ )
164
180
  end
165
181
 
166
182
  # Performs a POST request to the specified path
@@ -169,7 +185,12 @@ module Mailtrap
169
185
  # @return [Hash, nil] The JSON response
170
186
  # @!macro api_errors
171
187
  def post(path, body = nil)
172
- perform_request(:post, general_api_host, path, body)
188
+ perform_request(
189
+ method: :post,
190
+ host: general_api_host,
191
+ path:,
192
+ body:
193
+ )
173
194
  end
174
195
 
175
196
  # Performs a PATCH request to the specified path
@@ -178,7 +199,12 @@ module Mailtrap
178
199
  # @return [Hash, nil] The JSON response
179
200
  # @!macro api_errors
180
201
  def patch(path, body = nil)
181
- perform_request(:patch, general_api_host, path, body)
202
+ perform_request(
203
+ method: :patch,
204
+ host: general_api_host,
205
+ path:,
206
+ body:
207
+ )
182
208
  end
183
209
 
184
210
  # Performs a DELETE request to the specified path
@@ -186,7 +212,11 @@ module Mailtrap
186
212
  # @return [Hash, nil] The JSON response
187
213
  # @!macro api_errors
188
214
  def delete(path)
189
- perform_request(:delete, general_api_host, path)
215
+ perform_request(
216
+ method: :delete,
217
+ host: general_api_host,
218
+ path:
219
+ )
190
220
  end
191
221
 
192
222
  private
@@ -213,23 +243,27 @@ module Mailtrap
213
243
  "/api/batch#{"/#{inbox_id}" if sandbox}"
214
244
  end
215
245
 
216
- def perform_request(method, host, path, body = nil)
246
+ def perform_request(method:, host:, path:, query_params: {}, body: nil)
217
247
  http_client = http_client_for(host)
218
- request = setup_request(method, path, body)
248
+
249
+ uri = URI::HTTPS.build(host:, path:)
250
+ uri.query = URI.encode_www_form(query_params) if query_params.any?
251
+
252
+ request = setup_request(method, uri, body)
219
253
  response = http_client.request(request)
220
254
  handle_response(response)
221
255
  end
222
256
 
223
- def setup_request(method, path, body = nil)
257
+ def setup_request(method, uri_or_path, body = nil)
224
258
  request = case method
225
259
  when :get
226
- Net::HTTP::Get.new(path)
260
+ Net::HTTP::Get.new(uri_or_path)
227
261
  when :post
228
- Net::HTTP::Post.new(path)
262
+ Net::HTTP::Post.new(uri_or_path)
229
263
  when :patch
230
- Net::HTTP::Patch.new(path)
264
+ Net::HTTP::Patch.new(uri_or_path)
231
265
  when :delete
232
- Net::HTTP::Delete.new(path)
266
+ Net::HTTP::Delete.new(uri_or_path)
233
267
  else
234
268
  raise ArgumentError, "Unsupported HTTP method: #{method}"
235
269
  end
@@ -237,7 +271,7 @@ module Mailtrap
237
271
  request.body = body.to_json if body
238
272
  request['Authorization'] = "Bearer #{api_key}"
239
273
  request['Content-Type'] = 'application/json'
240
- request['User-Agent'] = 'mailtrap-ruby (https://github.com/railsware/mailtrap-ruby)'
274
+ request['User-Agent'] = 'mailtrap-ruby (https://github.com/mailtrap/mailtrap-ruby)'
241
275
 
242
276
  request
243
277
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailtrap
4
+ # Data Transfer Object for Contact Import
5
+ # @attr_reader id [Integer] The contact import ID
6
+ # @attr_reader status [String] The status of the import (created, started, finished, failed)
7
+ # @attr_reader created_contacts_count [Integer, nil] Number of contacts created in this import
8
+ # @attr_reader updated_contacts_count [Integer, nil] Number of contacts updated in this import
9
+ # @attr_reader contacts_over_limit_count [Integer, nil] Number of contacts over the allowed limit
10
+ ContactImport = Struct.new(
11
+ :id,
12
+ :status,
13
+ :created_contacts_count,
14
+ :updated_contacts_count,
15
+ :contacts_over_limit_count,
16
+ keyword_init: true
17
+ ) do
18
+ # @return [Hash] The contact attributes as a hash
19
+ def to_h
20
+ super.compact
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'contact_import'
4
+ require_relative 'contacts_import_request'
5
+
6
+ module Mailtrap
7
+ class ContactImportsAPI
8
+ include BaseAPI
9
+
10
+ self.supported_options = %i[email fields list_ids_included list_ids_excluded]
11
+
12
+ self.response_class = ContactImport
13
+
14
+ # Retrieves a specific contact import
15
+ # @param import_id [Integer] The contact import identifier
16
+ # @return [ContactImport] Contact import object
17
+ # @!macro api_errors
18
+ def get(import_id)
19
+ base_get(import_id)
20
+ end
21
+
22
+ # Create contacts import
23
+ #
24
+ # @example Using Mailtrap::ContactsImportRequest
25
+ # import_request = Mailtrap::ContactsImportRequest.new.tap do |req|
26
+ # req.upsert(email: 'jane@example.com', fields: { first_name: 'Jane' })
27
+ # .add_to_lists(email: 'jane@example.com', list_ids: [1])
28
+ # .remove_from_lists(email: 'jane@example.com', list_ids: [2])
29
+ # req.upsert(email: 'john@example.com', fields: { first_name: 'John' })
30
+ # .add_to_lists(email: 'john@example.com', list_ids: [1])
31
+ # .remove_from_lists(email: 'john@example.com', list_ids: [2])
32
+ # end
33
+ # contact_imports.create(import_request)
34
+ #
35
+ # @example Using plain hash
36
+ # contact_imports.create([
37
+ # {email: 'john@example.com', fields: { first_name: 'John' }, list_ids_included: [1], list_ids_excluded: [2]},
38
+ # {email: 'jane@example.com', fields: { first_name: 'Jane' }, list_ids_included: [1], list_ids_excluded: [2]}
39
+ # ])
40
+ #
41
+ # @param contacts [Mailtrap::ContactsImportRequest, Array<Hash>] The contacts import request
42
+ #
43
+ # @return [ContactImport] Created contact import object
44
+ # @!macro api_errors
45
+ # @raise [ArgumentError] If invalid options are provided
46
+ def create(contacts)
47
+ contact_data = contacts.to_a.each do |contact|
48
+ validate_options!(contact, supported_options)
49
+ end
50
+ response = client.post(base_path, contacts: contact_data)
51
+ handle_response(response)
52
+ end
53
+ alias start create
54
+
55
+ private
56
+
57
+ def base_path
58
+ "/api/accounts/#{account_id}/contacts/imports"
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailtrap
4
+ # A builder class for creating contact import requests
5
+ # Allows you to build a collection of contacts with their associated fields and list memberships
6
+ class ContactsImportRequest
7
+ def initialize
8
+ @data = Hash.new do |h, k|
9
+ h[k] = { email: k, fields: {}, list_ids_included: [], list_ids_excluded: [] }
10
+ end
11
+ end
12
+
13
+ # Creates or updates a contact with the provided email and fields
14
+ # @param email [String] The contact's email address
15
+ # @param fields [Hash] Contact fields in the format: field_merge_tag => String, Integer, Float, Boolean, or
16
+ # ISO-8601 date string (yyyy-mm-dd)
17
+ # @return [ContactsImportRequest] Returns self for method chaining
18
+ def upsert(email:, fields: {})
19
+ validate_email!(email)
20
+
21
+ @data[email][:fields].merge!(fields)
22
+
23
+ self
24
+ end
25
+
26
+ # Adds a contact to the specified lists
27
+ # @param email [String] The contact's email address
28
+ # @param list_ids [Array<Integer>] Array of list IDs to add the contact to
29
+ # @return [ContactsImportRequest] Returns self for method chaining
30
+ def add_to_lists(email:, list_ids:)
31
+ validate_email!(email)
32
+
33
+ append_list_ids email:, list_ids:, key: :list_ids_included
34
+
35
+ self
36
+ end
37
+
38
+ # Removes a contact from the specified lists
39
+ # @param email [String] The contact's email address
40
+ # @param list_ids [Array<Integer>] Array of list IDs to remove the contact from
41
+ # @return [ContactsImportRequest] Returns self for method chaining
42
+ def remove_from_lists(email:, list_ids:)
43
+ validate_email!(email)
44
+
45
+ append_list_ids email:, list_ids:, key: :list_ids_excluded
46
+
47
+ self
48
+ end
49
+
50
+ # @return [Array<Hash>] Array of contact objects ready for import
51
+ def to_a
52
+ @data.values
53
+ end
54
+
55
+ private
56
+
57
+ def validate_email!(email)
58
+ raise ArgumentError, 'email must be present' if email.nil? || email.empty?
59
+ end
60
+
61
+ def append_list_ids(email:, list_ids:, key:)
62
+ raise ArgumentError, 'list_ids must be present' if list_ids.empty?
63
+
64
+ @data[email][key] |= list_ids
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailtrap
4
+ # Data Transfer Object for Suppression
5
+ # @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/f8144826d885a-list-and-search-suppressions
6
+ # @attr_reader id [String] The suppression UUID
7
+ # @attr_reader type [String] The suppression type
8
+ # @attr_reader created_at [String] The creation timestamp
9
+ # @attr_reader email [String] The email address
10
+ # @attr_reader sending_stream [String] The sending stream
11
+ # @attr_reader domain_name [String, nil] The domain name
12
+ # @attr_reader message_bounce_category [String, nil] The bounce category
13
+ # @attr_reader message_category [String, nil] The message category
14
+ # @attr_reader message_client_ip [String, nil] The client IP
15
+ # @attr_reader message_created_at [String, nil] The message creation timestamp
16
+ # @attr_reader message_esp_response [String, nil] The ESP response
17
+ # @attr_reader message_esp_server_type [String, nil] The ESP server type
18
+ # @attr_reader message_outgoing_ip [String, nil] The outgoing IP
19
+ # @attr_reader message_recipient_mx_name [String, nil] The recipient MX name
20
+ # @attr_reader message_sender_email [String, nil] The sender email
21
+ # @attr_reader message_subject [String, nil] The message subject
22
+ Suppression = Struct.new(
23
+ :id,
24
+ :type,
25
+ :created_at,
26
+ :email,
27
+ :sending_stream,
28
+ :domain_name,
29
+ :message_bounce_category,
30
+ :message_category,
31
+ :message_client_ip,
32
+ :message_created_at,
33
+ :message_esp_response,
34
+ :message_esp_server_type,
35
+ :message_outgoing_ip,
36
+ :message_recipient_mx_name,
37
+ :message_sender_email,
38
+ :message_subject,
39
+ keyword_init: true
40
+ ) do
41
+ # @return [Hash] The suppression attributes as a hash
42
+ def to_h
43
+ super.compact
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_api'
4
+ require_relative 'suppression'
5
+
6
+ module Mailtrap
7
+ class SuppressionsAPI
8
+ include BaseAPI
9
+
10
+ self.response_class = Suppression
11
+
12
+ # Lists all suppressions for the account
13
+ # @param email [String] Email address to filter suppressions (optional)
14
+ # @return [Array<Suppression>] Array of suppression objects
15
+ # @!macro api_errors
16
+ def list(email: nil)
17
+ query_params = {}
18
+ query_params[:email] = email if email
19
+
20
+ base_list(query_params)
21
+ end
22
+
23
+ # Deletes a suppression
24
+ # @param suppression_id [String] The suppression UUID
25
+ # @return nil
26
+ # @!macro api_errors
27
+ def delete(suppression_id)
28
+ client.delete("#{base_path}/#{suppression_id}")
29
+ end
30
+
31
+ private
32
+
33
+ def base_path
34
+ "/api/accounts/#{account_id}/suppressions"
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mailtrap
4
- VERSION = '2.4.1'
4
+ VERSION = '2.4.2'
5
5
  end
data/lib/mailtrap.rb CHANGED
@@ -8,6 +8,8 @@ require_relative 'mailtrap/email_templates_api'
8
8
  require_relative 'mailtrap/contacts_api'
9
9
  require_relative 'mailtrap/contact_lists_api'
10
10
  require_relative 'mailtrap/contact_fields_api'
11
+ require_relative 'mailtrap/contact_imports_api'
12
+ require_relative 'mailtrap/suppressions_api'
11
13
 
12
14
  module Mailtrap
13
15
  # @!macro api_errors
data/mailtrap.gemspec CHANGED
@@ -10,13 +10,13 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = 'Official mailtrap.io API client'
12
12
  spec.description = 'Official mailtrap.io API client'
13
- spec.homepage = 'https://github.com/railsware/mailtrap-ruby'
13
+ spec.homepage = 'https://github.com/mailtrap/mailtrap-ruby'
14
14
  spec.license = 'MIT'
15
15
  spec.required_ruby_version = '>= 3.1.0'
16
16
 
17
17
  spec.metadata['homepage_uri'] = spec.homepage
18
- spec.metadata['source_code_uri'] = 'https://github.com/railsware/mailtrap-ruby'
19
- spec.metadata['changelog_uri'] = 'https://github.com/railsware/mailtrap-ruby/blob/main/CHANGELOG.md'
18
+ spec.metadata['source_code_uri'] = 'https://github.com/mailtrap/mailtrap-ruby'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/mailtrap/mailtrap-ruby/blob/main/CHANGELOG.md'
20
20
  spec.metadata['rubygems_mfa_required'] = 'true'
21
21
 
22
22
  spec.add_dependency 'base64'
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.4.1
4
+ version: 2.4.2
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: 2025-08-22 00:00:00.000000000 Z
11
+ date: 2025-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -51,24 +51,29 @@ files:
51
51
  - lib/mailtrap/contact.rb
52
52
  - lib/mailtrap/contact_field.rb
53
53
  - lib/mailtrap/contact_fields_api.rb
54
+ - lib/mailtrap/contact_import.rb
55
+ - lib/mailtrap/contact_imports_api.rb
54
56
  - lib/mailtrap/contact_list.rb
55
57
  - lib/mailtrap/contact_lists_api.rb
56
58
  - lib/mailtrap/contacts_api.rb
59
+ - lib/mailtrap/contacts_import_request.rb
57
60
  - lib/mailtrap/email_template.rb
58
61
  - lib/mailtrap/email_templates_api.rb
59
62
  - lib/mailtrap/errors.rb
60
63
  - lib/mailtrap/mail.rb
61
64
  - lib/mailtrap/mail/base.rb
62
65
  - lib/mailtrap/mail/from_template.rb
66
+ - lib/mailtrap/suppression.rb
67
+ - lib/mailtrap/suppressions_api.rb
63
68
  - lib/mailtrap/version.rb
64
69
  - mailtrap.gemspec
65
- homepage: https://github.com/railsware/mailtrap-ruby
70
+ homepage: https://github.com/mailtrap/mailtrap-ruby
66
71
  licenses:
67
72
  - MIT
68
73
  metadata:
69
- homepage_uri: https://github.com/railsware/mailtrap-ruby
70
- source_code_uri: https://github.com/railsware/mailtrap-ruby
71
- changelog_uri: https://github.com/railsware/mailtrap-ruby/blob/main/CHANGELOG.md
74
+ homepage_uri: https://github.com/mailtrap/mailtrap-ruby
75
+ source_code_uri: https://github.com/mailtrap/mailtrap-ruby
76
+ changelog_uri: https://github.com/mailtrap/mailtrap-ruby/blob/main/CHANGELOG.md
72
77
  rubygems_mfa_required: 'true'
73
78
  post_install_message:
74
79
  rdoc_options: []