mailtrap 2.10.0 → 2.11.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: b3a95002cbfb65622fa2d944bf2de1d41dc25a9a7224f8d244982fdf8154776d
4
- data.tar.gz: a228f3805ce687e8f34bd410595f6e39f9e7d73a426d1d06ca2b35ec972b5c69
3
+ metadata.gz: 9b63e81a019d2e0e7e4361de7ca3c511ffc3d0c292dc8db17c1866e986f57f18
4
+ data.tar.gz: 1b1efad54b339d0271d8c36970c1c668a345e31611a22cb3782ebc6556bd6543
5
5
  SHA512:
6
- metadata.gz: fcec8536fae46762bd7289b7b098f45728c9d00b79bcd1386b6e4cb384fa0fcf859136db5cc956480da7aa1cb5063ed8dbee2312ac0e2bf6c8ac4b872443e650
7
- data.tar.gz: 127126f80cded1f05214a173b1c8e78b8acc6c39bdbf1f168b161ca221a5e4230aa11d098f26c8c188c14778a28c579ac0e2bea52bab2713c82068d43836b677
6
+ metadata.gz: 8e03088d16735f15494b4eee20f6c58dd5a9ec0fb031836326b086687f5cc415d1c841744f27f6ca46c9203952d6abd989ed2f75c4b550fac53b58b62d314838
7
+ data.tar.gz: 63fc1ce090a0ee019693ed36794f5319f7b94caa29302ca9a2f7920b7db92dc611aeed74bd9ba0de4853e5626d108a520c11e0e1eb51dcf83418e1ff3b1105f7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## [2.11.0] - 2026-05-14
2
+ ## What's Changed
3
+ * Update sandboxes api by @IgorDobryn in https://github.com/mailtrap/mailtrap-ruby/pull/103
4
+ * Sending domains endpoints by @IgorDobryn in https://github.com/mailtrap/mailtrap-ruby/pull/104
5
+ * Add contact endpoints by @IgorDobryn in https://github.com/mailtrap/mailtrap-ruby/pull/105
6
+ * Account management API by @IgorDobryn in https://github.com/mailtrap/mailtrap-ruby/pull/106
7
+ * Add api token endpoints by @IgorDobryn in https://github.com/mailtrap/mailtrap-ruby/pull/107
8
+ * Add webhook endpoints by @IgorDobryn in https://github.com/mailtrap/mailtrap-ruby/pull/108
9
+
10
+
1
11
  ## [2.10.0] - 2026-03-23
2
12
 
3
13
  - Add Email Logs API (list and get email sending logs with filters and cursor pagination)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mailtrap (2.10.0)
4
+ mailtrap (2.11.0)
5
5
  base64
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -179,6 +179,7 @@ Email API:
179
179
  - Sending Domains API – [`sending_domains_api.rb`](examples/sending_domains_api.rb)
180
180
  - Sending Stats API – [`stats_api.rb`](examples/stats_api.rb)
181
181
  - Email Logs API – [`email_logs_api.rb`](examples/email_logs_api.rb)
182
+ - Webhooks API – [`webhooks_api.rb`](examples/webhooks_api.rb)
182
183
 
183
184
  Email Sandbox (Testing):
184
185
 
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailtrap
4
+ # Data Transfer Object for API Token
5
+ # @attr_reader id [Integer] The API token ID
6
+ # @attr_reader name [String] Token display name
7
+ # @attr_reader last_4_digits [String] Last 4 characters of the token
8
+ # @attr_reader created_by [String] Name of the user or token that created this token
9
+ # @attr_reader expires_at [String, nil] When the token expires (ISO 8601); nil if it does not expire
10
+ # @attr_reader resources [Array<Hash>] Permissions granted to this token
11
+ # @attr_reader token [String, nil] Full token value — only populated by #create and #reset
12
+ ApiToken = Struct.new(
13
+ :id,
14
+ :name,
15
+ :last_4_digits,
16
+ :created_by,
17
+ :expires_at,
18
+ :resources,
19
+ :token,
20
+ keyword_init: true
21
+ )
22
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_api'
4
+ require_relative 'api_token'
5
+
6
+ module Mailtrap
7
+ class ApiTokensAPI
8
+ include BaseAPI
9
+
10
+ self.supported_options = %i[name resources].freeze
11
+
12
+ self.response_class = ApiToken
13
+
14
+ # Lists API tokens visible to the current API token
15
+ # @return [Array<ApiToken>] Array of API tokens
16
+ # @!macro api_errors
17
+ def list
18
+ base_list
19
+ end
20
+
21
+ # Retrieves a single API token by ID
22
+ # @param token_id [Integer] The API token ID
23
+ # @return [ApiToken] API token object (the `token` field is nil — full value is only
24
+ # returned by #create and #reset)
25
+ # @!macro api_errors
26
+ def get(token_id)
27
+ base_get(token_id)
28
+ end
29
+
30
+ # Creates a new API token. The full `token` value is returned ONLY ONCE — store it securely.
31
+ # @param [Hash] options The parameters to create
32
+ # @option options [String] :name Display name for the token
33
+ # @option options [Array<Hash>] :resources Permissions to assign
34
+ # - `{ resource_type:, resource_id:, access_level: }`
35
+ # @return [ApiToken] Created token (full `token` value populated)
36
+ # @!macro api_errors
37
+ # @raise [ArgumentError] If invalid options are provided
38
+ def create(options)
39
+ base_create(options)
40
+ end
41
+
42
+ # Expires the requested token and returns a new one with the same permissions.
43
+ # The old token stops working after a short grace period. The new `token` value is
44
+ # returned ONLY ONCE — store it securely
45
+ # @param token_id [Integer] The API token ID
46
+ # @return [ApiToken] New token (full `token` value populated)
47
+ # @!macro api_errors
48
+ def reset(token_id)
49
+ response = client.post("#{base_path}/#{token_id}/reset")
50
+ handle_response(response)
51
+ end
52
+
53
+ # Permanently deletes an API token
54
+ # @param token_id [Integer] The API token ID
55
+ # @return nil
56
+ # @!macro api_errors
57
+ def delete(token_id)
58
+ base_delete(token_id)
59
+ end
60
+
61
+ private
62
+
63
+ def base_path
64
+ "/api/accounts/#{account_id}/api_tokens"
65
+ end
66
+ end
67
+ end
@@ -207,6 +207,20 @@ module Mailtrap
207
207
  )
208
208
  end
209
209
 
210
+ # Performs a PUT request to the specified path
211
+ # @param path [String] The request path
212
+ # @param body [Hash] The request body
213
+ # @return [Hash, String, nil] JSON response or raw response body
214
+ # @!macro api_errors
215
+ def put(path, body = nil)
216
+ perform_request(
217
+ method: :put,
218
+ host: general_api_host,
219
+ path:,
220
+ body:
221
+ )
222
+ end
223
+
210
224
  # Performs a DELETE request to the specified path
211
225
  # @param path [String] The request path
212
226
  # @return [Hash, String, nil] JSON response or raw response body
@@ -261,6 +275,8 @@ module Mailtrap
261
275
  Net::HTTP::Post.new(uri_or_path)
262
276
  when :patch
263
277
  Net::HTTP::Patch.new(uri_or_path)
278
+ when :put
279
+ Net::HTTP::Put.new(uri_or_path)
264
280
  when :delete
265
281
  Net::HTTP::Delete.new(uri_or_path)
266
282
  else
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailtrap
4
+ # Data Transfer Object for Sending Domain Company Info
5
+ # @see https://docs.mailtrap.io/developers/management/sending-domains
6
+ # @attr_reader name [String, nil] Company or individual name
7
+ # @attr_reader address [String, nil] Street address
8
+ # @attr_reader city [String, nil] City
9
+ # @attr_reader country [String, nil] Country
10
+ # @attr_reader phone [String, nil] Phone number
11
+ # @attr_reader zip_code [String, nil] ZIP or postal code
12
+ # @attr_reader privacy_policy_url [String, nil] URL to the privacy policy page
13
+ # @attr_reader terms_of_service_url [String, nil] URL to the terms of service page
14
+ # @attr_reader website_url [String, nil] Company website URL or LinkedIn / personal website
15
+ # @attr_reader info_level [String, nil] Whether the sender is a "business" or "individual"
16
+ CompanyInfo = Struct.new(
17
+ :name,
18
+ :address,
19
+ :city,
20
+ :country,
21
+ :phone,
22
+ :zip_code,
23
+ :privacy_policy_url,
24
+ :terms_of_service_url,
25
+ :website_url,
26
+ :info_level,
27
+ keyword_init: true
28
+ )
29
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_api'
4
+ require_relative 'company_info'
5
+
6
+ module Mailtrap
7
+ class CompanyInfoAPI
8
+ include BaseAPI
9
+
10
+ self.supported_options = %i[
11
+ name
12
+ address
13
+ city
14
+ country
15
+ phone
16
+ zip_code
17
+ privacy_policy_url
18
+ terms_of_service_url
19
+ website_url
20
+ info_level
21
+ ].freeze
22
+
23
+ self.response_class = CompanyInfo
24
+
25
+ # Gets company information for a sending domain
26
+ # @param sending_domain_id [Integer] The sending domain ID
27
+ # @return [CompanyInfo] Company information
28
+ # @!macro api_errors
29
+ def get(sending_domain_id)
30
+ response = client.get(base_path(sending_domain_id))
31
+ build_entity(response[:data], CompanyInfo)
32
+ end
33
+
34
+ # Creates company information for a sending domain
35
+ # @param sending_domain_id [Integer] The sending domain ID
36
+ # @param [Hash] options The company info attributes
37
+ # @option options [String] :name Company or individual name
38
+ # @option options [String] :address Street address
39
+ # @option options [String] :city City
40
+ # @option options [String] :country Country
41
+ # @option options [String] :phone Phone number
42
+ # @option options [String] :zip_code ZIP or postal code
43
+ # @option options [String] :privacy_policy_url URL to the privacy policy page
44
+ # @option options [String] :terms_of_service_url URL to the terms of service page
45
+ # @option options [String] :website_url Company website URL
46
+ # @option options [String] :info_level Whether the sender is a "business" or "individual"
47
+ # @return [CompanyInfo] Created company information
48
+ # @!macro api_errors
49
+ # @raise [ArgumentError] If invalid options are provided
50
+ def create(sending_domain_id, options)
51
+ validate_options!(options, supported_options)
52
+ response = client.post(base_path(sending_domain_id), wrap_request(options))
53
+ build_entity(response[:data], CompanyInfo)
54
+ end
55
+
56
+ # Updates company information for a sending domain
57
+ # @param sending_domain_id [Integer] The sending domain ID
58
+ # @param [Hash] options The company info attributes to update
59
+ # @return [CompanyInfo] Updated company information
60
+ # @!macro api_errors
61
+ # @raise [ArgumentError] If invalid options are provided
62
+ def update(sending_domain_id, options)
63
+ validate_options!(options, supported_options)
64
+ response = client.patch(base_path(sending_domain_id), wrap_request(options))
65
+ build_entity(response[:data], CompanyInfo)
66
+ end
67
+
68
+ private
69
+
70
+ def base_path(sending_domain_id)
71
+ "/api/accounts/#{account_id}/sending_domains/#{sending_domain_id}/company_info"
72
+ end
73
+
74
+ def wrap_request(options)
75
+ { company_info: options }
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailtrap
4
+ # Data Transfer Object for Contact Event
5
+ # @attr_reader contact_id [String] The contact ID (UUID)
6
+ # @attr_reader contact_email [String] The contact email
7
+ # @attr_reader name [String] The event name
8
+ # @attr_reader params [Hash] The event parameters (string keys, scalar values)
9
+ ContactEvent = Struct.new(
10
+ :contact_id,
11
+ :contact_email,
12
+ :name,
13
+ :params,
14
+ keyword_init: true
15
+ )
16
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_api'
4
+ require_relative 'contact_event'
5
+
6
+ module Mailtrap
7
+ class ContactEventsAPI
8
+ include BaseAPI
9
+
10
+ self.supported_options = %i[name params].freeze
11
+
12
+ self.response_class = ContactEvent
13
+
14
+ # Creates a contact event
15
+ # @param contact_identifier [String] The contact UUID or email address
16
+ # @param [Hash] options The event parameters
17
+ # @option options [String] :name The event name (max 255 characters)
18
+ # @option options [Hash] :params A hash of string keys and scalar values
19
+ # @return [ContactEvent] Created contact event object
20
+ # @!macro api_errors
21
+ # @raise [ArgumentError] If invalid options are provided
22
+ def create(contact_identifier, options)
23
+ validate_options!(options, supported_options)
24
+ response = client.post(base_path(contact_identifier), options)
25
+ build_entity(response, ContactEvent)
26
+ end
27
+
28
+ private
29
+
30
+ def base_path(contact_identifier)
31
+ "/api/accounts/#{account_id}/contacts/#{contact_identifier}/events"
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailtrap
4
+ # Data Transfer Object for Contact Export
5
+ # @attr_reader id [Integer] The contact export ID
6
+ # @attr_reader status [String] The export status (created, started, finished)
7
+ # @attr_reader created_at [String] When the export was created
8
+ # @attr_reader updated_at [String] When the export was last updated
9
+ # @attr_reader url [String, nil] URL of the exported file (only when status is "finished")
10
+ ContactExport = Struct.new(
11
+ :id,
12
+ :status,
13
+ :created_at,
14
+ :updated_at,
15
+ :url,
16
+ keyword_init: true
17
+ )
18
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_api'
4
+ require_relative 'contact_export'
5
+
6
+ module Mailtrap
7
+ class ContactExportsAPI
8
+ include BaseAPI
9
+
10
+ self.supported_options = %i[filters].freeze
11
+
12
+ self.response_class = ContactExport
13
+
14
+ # Retrieves a specific contact export
15
+ # @param export_id [Integer] The contact export ID
16
+ # @return [ContactExport] Contact export object
17
+ # @!macro api_errors
18
+ def get(export_id)
19
+ base_get(export_id)
20
+ end
21
+
22
+ # Creates a new contact export
23
+ # @param [Hash] options The export parameters
24
+ # @option options [Array<Hash>] :filters Filters to apply to the export
25
+ # - `{ name: 'list_id', operator: 'equal', value: [Integer, ...] }`
26
+ # - `{ name: 'subscription_status', operator: 'equal', value: 'subscribed' | 'unsubscribed' }`
27
+ # @return [ContactExport] Created contact export object
28
+ # @!macro api_errors
29
+ # @raise [ArgumentError] If invalid options are provided
30
+ def create(options)
31
+ base_create(options)
32
+ end
33
+
34
+ private
35
+
36
+ def base_path
37
+ "/api/accounts/#{account_id}/contacts/exports"
38
+ end
39
+ end
40
+ end
@@ -85,6 +85,24 @@ module Mailtrap
85
85
  handle_response(response)
86
86
  end
87
87
 
88
+ # Turn the email address of the inbox on/off
89
+ # @param inbox_id [Integer] The Inbox identifier
90
+ # @return [Inbox] Updated Inbox object
91
+ # @!macro api_errors
92
+ def toggle_email_username(inbox_id)
93
+ response = client.patch("#{base_path}/#{inbox_id}/toggle_email_username")
94
+ handle_response(response)
95
+ end
96
+
97
+ # Reset username of email address per inbox
98
+ # @param inbox_id [Integer] The Inbox identifier
99
+ # @return [Inbox] Updated Inbox object
100
+ # @!macro api_errors
101
+ def reset_email_username(inbox_id)
102
+ response = client.patch("#{base_path}/#{inbox_id}/reset_email_username")
103
+ handle_response(response)
104
+ end
105
+
88
106
  private
89
107
 
90
108
  def wrap_request(options)
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailtrap
4
+ # Data Transfer Object for a node in the Permissions resources tree
5
+ # @attr_reader id [Integer] Resource ID
6
+ # @attr_reader name [String] Resource name
7
+ # @attr_reader type [String] Resource type (account, project, inbox, sending_domain, ...)
8
+ # @attr_reader access_level [Integer] The access level the current token has on this resource
9
+ # @attr_reader resources [Array<PermissionResource>] Nested child resources
10
+ PermissionResource = Struct.new(
11
+ :id,
12
+ :name,
13
+ :type,
14
+ :access_level,
15
+ :resources,
16
+ keyword_init: true
17
+ )
18
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_api'
4
+ require_relative 'permission_resource'
5
+
6
+ module Mailtrap
7
+ class PermissionsAPI
8
+ include BaseAPI
9
+
10
+ # Bulk-updates user or token permissions on an account access
11
+ # @param account_access_id [Integer] The account access ID
12
+ # @param permissions [Array<Hash>] Array of permission entries
13
+ # - `{ resource_id:, resource_type:, access_level: }` to create or update
14
+ # - `{ resource_id:, resource_type:, _destroy: true }` to remove
15
+ # @return [Hash] API response (e.g. `{ message: 'Permissions have been updated!' }`)
16
+ # @!macro api_errors
17
+ def bulk_update(account_access_id, permissions)
18
+ client.put(
19
+ "#{base_path}/account_accesses/#{account_access_id}/permissions/bulk",
20
+ { permissions: permissions }
21
+ )
22
+ end
23
+
24
+ # Returns the recursive tree of resources the current token can access.
25
+ # Each node carries the token's access_level and any nested child resources.
26
+ # @return [Array<PermissionResource>] Top-level resources, each with nested children
27
+ # @!macro api_errors
28
+ def resources
29
+ response = client.get("#{base_path}/permissions/resources")
30
+ build_resource_tree(response)
31
+ end
32
+
33
+ private
34
+
35
+ def base_path
36
+ "/api/accounts/#{account_id}"
37
+ end
38
+
39
+ def build_resource_tree(items)
40
+ items.map do |item|
41
+ PermissionResource.new(
42
+ id: item[:id],
43
+ name: item[:name],
44
+ type: item[:type],
45
+ access_level: item[:access_level],
46
+ resources: build_resource_tree(Array(item[:resources]))
47
+ )
48
+ end
49
+ end
50
+ end
51
+ end
@@ -7,7 +7,7 @@ module Mailtrap
7
7
  class SendingDomainsAPI
8
8
  include BaseAPI
9
9
 
10
- self.supported_options = %i[domain_name]
10
+ self.supported_options = %i[open_tracking_enabled click_tracking_enabled auto_unsubscribe_link_enabled]
11
11
 
12
12
  self.response_class = SendingDomain
13
13
 
@@ -34,7 +34,7 @@ module Mailtrap
34
34
  # @!macro api_errors
35
35
  # @raise [ArgumentError] If invalid options are provided
36
36
  def create(options)
37
- base_create(options)
37
+ base_create(options, %i[domain_name])
38
38
  end
39
39
 
40
40
  # Deletes a sending domain
@@ -45,6 +45,19 @@ module Mailtrap
45
45
  base_delete(domain_id)
46
46
  end
47
47
 
48
+ # Updates configuration settings for a sending domain
49
+ # @param domain_id [Integer] The sending domain ID
50
+ # @param [Hash] options The parameters to update
51
+ # @option options [Boolean] :open_tracking_enabled Enable open tracking for emails sent from this domain
52
+ # @option options [Boolean] :click_tracking_enabled Enable click tracking for links in emails sent from this domain
53
+ # @option options [Boolean] :auto_unsubscribe_link_enabled Automatically add an unsubscribe link to emails
54
+ # @return [SendingDomain] Updated sending domain
55
+ # @!macro api_errors
56
+ # @raise [ArgumentError] If invalid options are provided
57
+ def update(domain_id, options)
58
+ base_update(domain_id, options)
59
+ end
60
+
48
61
  # Email DNS configuration instructions for the sending domain
49
62
  # @param domain_id [Integer] The sending domain ID
50
63
  # @param email [String] The email for instructions
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailtrap
4
+ # Data Transfer Object for an organization sub account
5
+ # @attr_reader id [Integer] The sub account ID
6
+ # @attr_reader name [String] The sub account name
7
+ SubAccount = Struct.new(
8
+ :id,
9
+ :name,
10
+ keyword_init: true
11
+ )
12
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_api'
4
+ require_relative 'sub_account'
5
+
6
+ module Mailtrap
7
+ class SubAccountsAPI
8
+ include BaseAPI
9
+
10
+ attr_reader :organization_id
11
+
12
+ self.supported_options = %i[name].freeze
13
+
14
+ self.response_class = SubAccount
15
+
16
+ # @param organization_id [Integer] The organization ID
17
+ # @param client [Mailtrap::Client] The client instance
18
+ # @raise [ArgumentError] If organization_id is nil
19
+ def initialize(organization_id, client = Mailtrap::Client.new)
20
+ raise ArgumentError, 'organization_id is required' if organization_id.nil?
21
+
22
+ @organization_id = organization_id
23
+ @client = client
24
+ end
25
+
26
+ # Lists all sub accounts under the organization
27
+ # @return [Array<SubAccount>] Array of sub accounts
28
+ # @!macro api_errors
29
+ def list
30
+ base_list
31
+ end
32
+
33
+ # Creates a new sub account under the organization
34
+ # @param [Hash] options The parameters to create
35
+ # @option options [String] :name Name of the sub account
36
+ # @return [SubAccount] Created sub account
37
+ # @!macro api_errors
38
+ # @raise [ArgumentError] If invalid options are provided
39
+ def create(options)
40
+ base_create(options)
41
+ end
42
+
43
+ private
44
+
45
+ def base_path
46
+ "/api/organizations/#{organization_id}/sub_accounts"
47
+ end
48
+
49
+ def wrap_request(options)
50
+ { account: options }
51
+ end
52
+ end
53
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mailtrap
4
- VERSION = '2.10.0'
4
+ VERSION = '2.11.0'
5
5
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailtrap
4
+ # Data Transfer Object for Webhook
5
+ # @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/8d553c46c2d33-webhooks
6
+ # @attr_reader id [Integer] The webhook ID
7
+ # @attr_reader url [String] The URL that will receive webhook payloads
8
+ # @attr_reader active [Boolean] Whether the webhook is active
9
+ # @attr_reader webhook_type [String] The type of webhook (`email_sending` or `audit_log`)
10
+ # @attr_reader payload_format [String] The webhook payload format (`json` or `jsonlines`)
11
+ # @attr_reader sending_stream [String, nil] The sending stream (`transactional` or `bulk`).
12
+ # Applicable only for `email_sending` webhooks.
13
+ # @attr_reader domain_id [Integer, nil] The sending domain ID the webhook is scoped to,
14
+ # or nil for all domains. Applicable only for `email_sending` webhooks.
15
+ # @attr_reader event_types [Array<String>] The event types the webhook is subscribed to.
16
+ # Applicable only for `email_sending` webhooks.
17
+ # @attr_reader signing_secret [String, nil] HMAC SHA-256 signing secret. Returned only on creation.
18
+ Webhook = Struct.new(
19
+ :id,
20
+ :url,
21
+ :active,
22
+ :webhook_type,
23
+ :payload_format,
24
+ :sending_stream,
25
+ :domain_id,
26
+ :event_types,
27
+ :signing_secret,
28
+ keyword_init: true
29
+ )
30
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_api'
4
+ require_relative 'webhook'
5
+
6
+ module Mailtrap
7
+ class WebhooksAPI
8
+ include BaseAPI
9
+
10
+ self.supported_options = %i[url webhook_type active payload_format sending_stream event_types domain_id]
11
+
12
+ self.response_class = Webhook
13
+
14
+ # Lists all webhooks for the account
15
+ # @return [Array<Webhook>] Array of webhooks
16
+ # @!macro api_errors
17
+ def list
18
+ response = client.get(base_path)
19
+ response[:data].map { |item| build_entity(item, response_class) }
20
+ end
21
+
22
+ # Retrieves a specific webhook
23
+ # @param webhook_id [Integer] The webhook ID
24
+ # @return [Webhook] Webhook object
25
+ # @!macro api_errors
26
+ def get(webhook_id)
27
+ base_get(webhook_id)
28
+ end
29
+
30
+ # Creates a new webhook
31
+ # @param [Hash] options The parameters to create
32
+ # @option options [String] :url The URL that will receive webhook payloads
33
+ # @option options [String] :webhook_type The type of webhook (`email_sending` or `audit_log`)
34
+ # @option options [Boolean] :active Whether the webhook is active. Defaults to true.
35
+ # @option options [String] :payload_format Payload format (`json` or `jsonlines`). Defaults to `json`.
36
+ # @option options [String] :sending_stream Sending stream (`transactional` or `bulk`).
37
+ # Required for `email_sending` webhook type.
38
+ # @option options [Array<String>] :event_types Event types to subscribe to.
39
+ # Required for `email_sending` webhook type.
40
+ # @option options [Integer] :domain_id Sending domain ID to scope the webhook to.
41
+ # Applicable only for `email_sending` webhooks.
42
+ # @return [Webhook] Created webhook (includes `signing_secret`)
43
+ # @!macro api_errors
44
+ # @raise [ArgumentError] If invalid options are provided
45
+ def create(options)
46
+ base_create(options)
47
+ end
48
+
49
+ # Updates an existing webhook
50
+ # @param webhook_id [Integer] The webhook ID
51
+ # @param [Hash] options The parameters to update
52
+ # @option options [String] :url The URL that will receive webhook payloads
53
+ # @option options [Boolean] :active Whether the webhook is active
54
+ # @option options [String] :payload_format Payload format (`json` or `jsonlines`)
55
+ # @option options [Array<String>] :event_types Event types to subscribe to.
56
+ # Applicable only for `email_sending` webhooks.
57
+ # @return [Webhook] Updated webhook
58
+ # @!macro api_errors
59
+ # @raise [ArgumentError] If invalid options are provided
60
+ def update(webhook_id, options)
61
+ base_update(webhook_id, options, %i[url active payload_format event_types])
62
+ end
63
+
64
+ # Deletes a webhook
65
+ # @param webhook_id [Integer] The webhook ID
66
+ # @return [Webhook] Deleted webhook
67
+ # @!macro api_errors
68
+ def delete(webhook_id)
69
+ response = client.delete("#{base_path}/#{webhook_id}")
70
+ handle_response(response) if response
71
+ end
72
+
73
+ private
74
+
75
+ def base_path
76
+ "/api/accounts/#{account_id}/webhooks"
77
+ end
78
+
79
+ def wrap_request(options)
80
+ { webhook: options }
81
+ end
82
+
83
+ def handle_response(response)
84
+ build_entity(response[:data], response_class)
85
+ end
86
+ end
87
+ end
data/lib/mailtrap.rb CHANGED
@@ -6,20 +6,27 @@ require_relative 'mailtrap/errors'
6
6
  require_relative 'mailtrap/version'
7
7
  require_relative 'mailtrap/accounts_api'
8
8
  require_relative 'mailtrap/account_accesses_api'
9
+ require_relative 'mailtrap/api_tokens_api'
10
+ require_relative 'mailtrap/permissions_api'
11
+ require_relative 'mailtrap/sub_accounts_api'
9
12
  require_relative 'mailtrap/billing_api'
10
13
  require_relative 'mailtrap/email_templates_api'
11
14
  require_relative 'mailtrap/contacts_api'
12
15
  require_relative 'mailtrap/contact_lists_api'
13
16
  require_relative 'mailtrap/contact_fields_api'
14
17
  require_relative 'mailtrap/contact_imports_api'
18
+ require_relative 'mailtrap/contact_exports_api'
19
+ require_relative 'mailtrap/contact_events_api'
15
20
  require_relative 'mailtrap/suppressions_api'
16
21
  require_relative 'mailtrap/sending_domains_api'
22
+ require_relative 'mailtrap/company_info_api'
17
23
  require_relative 'mailtrap/email_logs_api'
18
24
  require_relative 'mailtrap/projects_api'
19
25
  require_relative 'mailtrap/inboxes_api'
20
26
  require_relative 'mailtrap/sandbox_messages_api'
21
27
  require_relative 'mailtrap/sandbox_attachments_api'
22
28
  require_relative 'mailtrap/stats_api'
29
+ require_relative 'mailtrap/webhooks_api'
23
30
 
24
31
  module Mailtrap
25
32
  # @!macro api_errors
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailtrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.0
4
+ version: 2.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Railsware Products Studio LLC
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-05-14 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: base64
@@ -49,12 +50,20 @@ files:
49
50
  - lib/mailtrap/action_mailer.rb
50
51
  - lib/mailtrap/action_mailer/delivery_method.rb
51
52
  - lib/mailtrap/action_mailer/railtie.rb
53
+ - lib/mailtrap/api_token.rb
54
+ - lib/mailtrap/api_tokens_api.rb
52
55
  - lib/mailtrap/attachment.rb
53
56
  - lib/mailtrap/base_api.rb
54
57
  - lib/mailtrap/billing_api.rb
55
58
  - lib/mailtrap/billing_usage.rb
56
59
  - lib/mailtrap/client.rb
60
+ - lib/mailtrap/company_info.rb
61
+ - lib/mailtrap/company_info_api.rb
57
62
  - lib/mailtrap/contact.rb
63
+ - lib/mailtrap/contact_event.rb
64
+ - lib/mailtrap/contact_events_api.rb
65
+ - lib/mailtrap/contact_export.rb
66
+ - lib/mailtrap/contact_exports_api.rb
58
67
  - lib/mailtrap/contact_field.rb
59
68
  - lib/mailtrap/contact_fields_api.rb
60
69
  - lib/mailtrap/contact_import.rb
@@ -76,6 +85,8 @@ files:
76
85
  - lib/mailtrap/mail.rb
77
86
  - lib/mailtrap/mail/base.rb
78
87
  - lib/mailtrap/mail/from_template.rb
88
+ - lib/mailtrap/permission_resource.rb
89
+ - lib/mailtrap/permissions_api.rb
79
90
  - lib/mailtrap/project.rb
80
91
  - lib/mailtrap/projects_api.rb
81
92
  - lib/mailtrap/sandbox_attachment.rb
@@ -87,9 +98,13 @@ files:
87
98
  - lib/mailtrap/sending_stat_group.rb
88
99
  - lib/mailtrap/sending_stats.rb
89
100
  - lib/mailtrap/stats_api.rb
101
+ - lib/mailtrap/sub_account.rb
102
+ - lib/mailtrap/sub_accounts_api.rb
90
103
  - lib/mailtrap/suppression.rb
91
104
  - lib/mailtrap/suppressions_api.rb
92
105
  - lib/mailtrap/version.rb
106
+ - lib/mailtrap/webhook.rb
107
+ - lib/mailtrap/webhooks_api.rb
93
108
  - mailtrap.gemspec
94
109
  homepage: https://github.com/mailtrap/mailtrap-ruby
95
110
  licenses:
@@ -99,6 +114,7 @@ metadata:
99
114
  source_code_uri: https://github.com/mailtrap/mailtrap-ruby
100
115
  changelog_uri: https://github.com/mailtrap/mailtrap-ruby/blob/main/CHANGELOG.md
101
116
  rubygems_mfa_required: 'true'
117
+ post_install_message:
102
118
  rdoc_options: []
103
119
  require_paths:
104
120
  - lib
@@ -113,7 +129,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
129
  - !ruby/object:Gem::Version
114
130
  version: '0'
115
131
  requirements: []
116
- rubygems_version: 4.0.3
132
+ rubygems_version: 3.5.11
133
+ signing_key:
117
134
  specification_version: 4
118
135
  summary: Official mailtrap.io API client
119
136
  test_files: []