mailtrap 2.16.0 → 2.18.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 +4 -4
- data/CHANGELOG.md +18 -0
- data/Gemfile.lock +1 -1
- data/README.md +3 -1
- data/lib/mailtrap/inbound_forward_outcome.rb +21 -0
- data/lib/mailtrap/inbound_forward_rule.rb +21 -0
- data/lib/mailtrap/inbound_forward_rule_condition.rb +17 -0
- data/lib/mailtrap/inbound_forward_rule_destination.rb +11 -0
- data/lib/mailtrap/inbound_forward_rules_api.rb +106 -0
- data/lib/mailtrap/inbound_message.rb +2 -0
- data/lib/mailtrap/inbound_messages_api.rb +8 -0
- data/lib/mailtrap/inbound_thread_message.rb +5 -8
- data/lib/mailtrap/inbound_thread_message_delivery.rb +17 -0
- data/lib/mailtrap/inbound_threads_api.rb +17 -2
- data/lib/mailtrap/template.rb +36 -0
- data/lib/mailtrap/templates_api.rb +91 -0
- data/lib/mailtrap/version.rb +1 -1
- data/lib/mailtrap.rb +2 -0
- metadata +10 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: df2746012d3720b47808a3bd7b8f44f473b49f53bf30b0b758d4467e0b8a578d
|
|
4
|
+
data.tar.gz: ba58958bb95d0344e5107c82b76a2a3a1586ea9bfe16211e07d39e167c119d82
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b3e163c56c0f08fc0be204e73a471fa451d5d8ae2eb87700f223c9e44a8a14161b88f916ac6d0d88b37b14c19807fd4d49424aa71b8075b4d7cbd8c87edbe487
|
|
7
|
+
data.tar.gz: f7cde5772e9b716761678f4d230b8f8e2d0ed6ba7b0f4afb5546377f36add5a991cc0f4e4e7cb2a44ee0f7c97419f56f732f31cb4f771ef698f154920007b3d5
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## [2.18.0] - 2026-10-07
|
|
2
|
+
|
|
3
|
+
## What's Changed
|
|
4
|
+
* Add inbound forward rules, forward outcomes, thread delivery and search by @mklocek in https://github.com/mailtrap/mailtrap-ruby/pull/132
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
**Full Changelog**: https://github.com/mailtrap/mailtrap-ruby/compare/v2.17.0...v2.18.0
|
|
8
|
+
|
|
9
|
+
## [2.17.0] - 2026-10-07
|
|
10
|
+
|
|
11
|
+
## What's Changed
|
|
12
|
+
* Add TemplatesAPI for the paginated /api/templates endpoints by @izikaj in https://github.com/mailtrap/mailtrap-ruby/pull/133
|
|
13
|
+
|
|
14
|
+
## New Contributors
|
|
15
|
+
* @izikaj made their first contribution in https://github.com/mailtrap/mailtrap-ruby/pull/133
|
|
16
|
+
|
|
17
|
+
**Full Changelog**: https://github.com/mailtrap/mailtrap-ruby/compare/v2.16.0...v2.17.0
|
|
18
|
+
|
|
1
19
|
## [2.16.0] - 2026-08-31
|
|
2
20
|
|
|
3
21
|
## What's Changed
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -195,6 +195,7 @@ Inbound Email:
|
|
|
195
195
|
- Inbound Inboxes API – [`inbound_inboxes_api.rb`](examples/inbound_inboxes_api.rb)
|
|
196
196
|
- Inbound Messages API (list, get, delete, reply, reply_all, forward) – [`inbound_messages_api.rb`](examples/inbound_messages_api.rb)
|
|
197
197
|
- Inbound Threads API – [`inbound_threads_api.rb`](examples/inbound_threads_api.rb)
|
|
198
|
+
- Inbound Forward Rules API – [`inbound_forward_rules_api.rb`](examples/inbound_forward_rules_api.rb)
|
|
198
199
|
|
|
199
200
|
Contact management:
|
|
200
201
|
|
|
@@ -211,7 +212,8 @@ General:
|
|
|
211
212
|
- API Tokens API – [`api_tokens_api.rb`](examples/api_tokens_api.rb)
|
|
212
213
|
- Billing API – [`billing_api.rb`](examples/billing_api.rb)
|
|
213
214
|
- Permissions API – [`permissions_api.rb`](examples/permissions_api.rb)
|
|
214
|
-
- Templates API – [`
|
|
215
|
+
- Templates API (experimental) – [`templates_api.rb`](examples/templates_api.rb)
|
|
216
|
+
- Email Templates API – [`email_templates_api.rb`](examples/email_templates_api.rb)
|
|
215
217
|
- Action Mailer – [`action_mailer.rb`](examples/action_mailer.rb)
|
|
216
218
|
- Verifying webhook signatures – [`webhooks_signature_verification.ru`](examples/webhooks_signature_verification.ru)
|
|
217
219
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailtrap
|
|
4
|
+
# Data Transfer Object for an inbound forward outcome
|
|
5
|
+
# @see https://docs.mailtrap.io/developers/inbound
|
|
6
|
+
# @attr_reader rule_id [Integer] The forward rule ID
|
|
7
|
+
# @attr_reader rule_name [String, nil] The forward rule name
|
|
8
|
+
# @attr_reader destination [String] The destination address
|
|
9
|
+
# @attr_reader status [String] forwarded or rejected
|
|
10
|
+
# @attr_reader reason [String, nil] The rejection reason
|
|
11
|
+
# @attr_reader message_id [String, nil] The forwarded message ID
|
|
12
|
+
InboundForwardOutcome = Struct.new(
|
|
13
|
+
:rule_id,
|
|
14
|
+
:rule_name,
|
|
15
|
+
:destination,
|
|
16
|
+
:status,
|
|
17
|
+
:reason,
|
|
18
|
+
:message_id,
|
|
19
|
+
keyword_init: true
|
|
20
|
+
)
|
|
21
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailtrap
|
|
4
|
+
# Data Transfer Object for an inbound forward rule
|
|
5
|
+
# @see https://docs.mailtrap.io/developers/inbound
|
|
6
|
+
# @attr_reader id [Integer] The forward rule ID
|
|
7
|
+
# @attr_reader name [String] The rule name
|
|
8
|
+
# @attr_reader created_at [String] Creation timestamp
|
|
9
|
+
# @attr_reader updated_at [String] Last update timestamp
|
|
10
|
+
# @attr_reader conditions [Array<InboundForwardRuleCondition>] The rule conditions
|
|
11
|
+
# @attr_reader destinations [Array<InboundForwardRuleDestination>] The rule destinations
|
|
12
|
+
InboundForwardRule = Struct.new(
|
|
13
|
+
:id,
|
|
14
|
+
:name,
|
|
15
|
+
:created_at,
|
|
16
|
+
:updated_at,
|
|
17
|
+
:conditions,
|
|
18
|
+
:destinations,
|
|
19
|
+
keyword_init: true
|
|
20
|
+
)
|
|
21
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailtrap
|
|
4
|
+
# Data Transfer Object for an inbound forward rule condition
|
|
5
|
+
# @see https://docs.mailtrap.io/developers/inbound
|
|
6
|
+
# @attr_reader match_type [String] The match type
|
|
7
|
+
# @attr_reader operator [String] The comparison operator
|
|
8
|
+
# @attr_reader value [String, nil] The value to compare against
|
|
9
|
+
# @attr_reader header_key [String, nil] The header name
|
|
10
|
+
InboundForwardRuleCondition = Struct.new(
|
|
11
|
+
:match_type,
|
|
12
|
+
:operator,
|
|
13
|
+
:value,
|
|
14
|
+
:header_key,
|
|
15
|
+
keyword_init: true
|
|
16
|
+
)
|
|
17
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailtrap
|
|
4
|
+
# Data Transfer Object for an inbound forward rule destination
|
|
5
|
+
# @see https://docs.mailtrap.io/developers/inbound
|
|
6
|
+
# @attr_reader email [String] The destination email address
|
|
7
|
+
InboundForwardRuleDestination = Struct.new(
|
|
8
|
+
:email,
|
|
9
|
+
keyword_init: true
|
|
10
|
+
)
|
|
11
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base_api'
|
|
4
|
+
require_relative 'inbound_forward_rule'
|
|
5
|
+
require_relative 'inbound_forward_rule_condition'
|
|
6
|
+
require_relative 'inbound_forward_rule_destination'
|
|
7
|
+
|
|
8
|
+
module Mailtrap
|
|
9
|
+
class InboundForwardRulesAPI
|
|
10
|
+
include BaseAPI
|
|
11
|
+
|
|
12
|
+
self.supported_options = %i[name conditions destinations]
|
|
13
|
+
self.response_class = InboundForwardRule
|
|
14
|
+
|
|
15
|
+
# @param client [Mailtrap::Client] The client instance
|
|
16
|
+
def initialize(client = Mailtrap::Client.new)
|
|
17
|
+
@client = client
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Lists forward rules in an inbox
|
|
21
|
+
# @param inbox_id [Integer] The inbox ID
|
|
22
|
+
# @return [Array<InboundForwardRule>] Array of forward rules
|
|
23
|
+
# @!macro api_errors
|
|
24
|
+
def list(inbox_id)
|
|
25
|
+
response = client.get(forward_rules_path(inbox_id))
|
|
26
|
+
Array(response[:data]).map { |item| build_rule(item) }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Retrieves a specific forward rule
|
|
30
|
+
# @param inbox_id [Integer] The inbox ID
|
|
31
|
+
# @param forward_rule_id [Integer] The forward rule ID
|
|
32
|
+
# @return [InboundForwardRule] Forward rule object
|
|
33
|
+
# @!macro api_errors
|
|
34
|
+
def get(inbox_id, forward_rule_id)
|
|
35
|
+
handle_response(client.get("#{forward_rules_path(inbox_id)}/#{forward_rule_id}"))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Creates a new forward rule
|
|
39
|
+
# @param inbox_id [Integer] The inbox ID
|
|
40
|
+
# @param [Hash] options The parameters to create
|
|
41
|
+
# @option options [String] :name The rule name
|
|
42
|
+
# @option options [Array<Hash>] :conditions The rule conditions
|
|
43
|
+
# @option options [Array<Hash>] :destinations The rule destinations
|
|
44
|
+
# @return [InboundForwardRule] Created forward rule
|
|
45
|
+
# @!macro api_errors
|
|
46
|
+
# @raise [ArgumentError] If invalid options are provided
|
|
47
|
+
def create(inbox_id, options)
|
|
48
|
+
validate_options!(options, supported_options)
|
|
49
|
+
handle_response(client.post(forward_rules_path(inbox_id), options))
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Updates a forward rule
|
|
53
|
+
# @param inbox_id [Integer] The inbox ID
|
|
54
|
+
# @param forward_rule_id [Integer] The forward rule ID
|
|
55
|
+
# @param [Hash] options The parameters to update
|
|
56
|
+
# @option options [String] :name The rule name
|
|
57
|
+
# @option options [Array<Hash>] :conditions The rule conditions
|
|
58
|
+
# @option options [Array<Hash>] :destinations The rule destinations
|
|
59
|
+
# @return [InboundForwardRule] Updated forward rule
|
|
60
|
+
# @!macro api_errors
|
|
61
|
+
# @raise [ArgumentError] If invalid options are provided
|
|
62
|
+
def update(inbox_id, forward_rule_id, options)
|
|
63
|
+
validate_options!(options, supported_options)
|
|
64
|
+
handle_response(client.patch("#{forward_rules_path(inbox_id)}/#{forward_rule_id}", options))
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Deletes a forward rule
|
|
68
|
+
# @param inbox_id [Integer] The inbox ID
|
|
69
|
+
# @param forward_rule_id [Integer] The forward rule ID
|
|
70
|
+
# @return nil
|
|
71
|
+
# @!macro api_errors
|
|
72
|
+
def delete(inbox_id, forward_rule_id)
|
|
73
|
+
client.delete("#{forward_rules_path(inbox_id)}/#{forward_rule_id}")
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def forward_rules_path(inbox_id)
|
|
79
|
+
"/api/inbound/inboxes/#{inbox_id}/forward_rules"
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def handle_response(response)
|
|
83
|
+
build_rule(response[:data])
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def build_rule(hash)
|
|
87
|
+
attrs = hash.slice(*InboundForwardRule.members)
|
|
88
|
+
attrs[:conditions] = build_conditions(attrs[:conditions]) if attrs[:conditions]
|
|
89
|
+
attrs[:destinations] = build_destinations(attrs[:destinations]) if attrs[:destinations]
|
|
90
|
+
|
|
91
|
+
InboundForwardRule.new(**attrs)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def build_conditions(conditions)
|
|
95
|
+
Array(conditions).map do |condition|
|
|
96
|
+
InboundForwardRuleCondition.new(**condition.slice(*InboundForwardRuleCondition.members))
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def build_destinations(destinations)
|
|
101
|
+
Array(destinations).map do |destination|
|
|
102
|
+
InboundForwardRuleDestination.new(**destination.slice(*InboundForwardRuleDestination.members))
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
@@ -25,6 +25,7 @@ module Mailtrap
|
|
|
25
25
|
# @attr_reader raw_message_expires_at [String, nil] When the raw message URL expires (only when fetched by ID)
|
|
26
26
|
# @attr_reader html_body [String, nil] Decoded HTML body (only when fetched by ID)
|
|
27
27
|
# @attr_reader text_body [String, nil] Decoded text body (only when fetched by ID)
|
|
28
|
+
# @attr_reader forwards [Array<InboundForwardOutcome>] The forward outcomes
|
|
28
29
|
# rubocop:disable Lint/StructNewOverride -- +size+ is an API field that shadows Struct#size
|
|
29
30
|
InboundMessage = Struct.new(
|
|
30
31
|
:id,
|
|
@@ -49,6 +50,7 @@ module Mailtrap
|
|
|
49
50
|
:raw_message_expires_at,
|
|
50
51
|
:html_body,
|
|
51
52
|
:text_body,
|
|
53
|
+
:forwards,
|
|
52
54
|
keyword_init: true
|
|
53
55
|
)
|
|
54
56
|
# rubocop:enable Lint/StructNewOverride
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require_relative 'base_api'
|
|
4
4
|
require_relative 'inbound_message'
|
|
5
5
|
require_relative 'inbound_attachment'
|
|
6
|
+
require_relative 'inbound_forward_outcome'
|
|
6
7
|
require_relative 'inbound_messages_list_response'
|
|
7
8
|
require_relative 'inbound_send_result'
|
|
8
9
|
|
|
@@ -100,6 +101,7 @@ module Mailtrap
|
|
|
100
101
|
def build_message(hash)
|
|
101
102
|
attrs = hash.slice(*InboundMessage.members)
|
|
102
103
|
attrs[:attachments] = build_attachments(attrs[:attachments]) if attrs[:attachments]
|
|
104
|
+
attrs[:forwards] = build_forwards(attrs[:forwards]) if attrs[:forwards]
|
|
103
105
|
|
|
104
106
|
InboundMessage.new(**attrs)
|
|
105
107
|
end
|
|
@@ -109,5 +111,11 @@ module Mailtrap
|
|
|
109
111
|
InboundAttachment.new(**attachment.slice(*InboundAttachment.members))
|
|
110
112
|
end
|
|
111
113
|
end
|
|
114
|
+
|
|
115
|
+
def build_forwards(forwards)
|
|
116
|
+
Array(forwards).map do |forward|
|
|
117
|
+
InboundForwardOutcome.new(**forward.slice(*InboundForwardOutcome.members))
|
|
118
|
+
end
|
|
119
|
+
end
|
|
112
120
|
end
|
|
113
121
|
end
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module Mailtrap
|
|
4
4
|
# Data Transfer Object for a message inside an inbound thread.
|
|
5
|
-
# Only +visibility_status+ and +direction+ are always present; +placeholder+ entries omit the rest
|
|
6
|
-
# and the delivery lifecycle fields are only set on available outbound messages.
|
|
5
|
+
# Only +visibility_status+ and +direction+ are always present; +placeholder+ entries omit the rest.
|
|
7
6
|
# @see https://docs.mailtrap.io/developers/inbound
|
|
8
7
|
# @attr_reader visibility_status [String] available or placeholder
|
|
9
8
|
# @attr_reader direction [String] inbound or outbound
|
|
@@ -23,9 +22,8 @@ module Mailtrap
|
|
|
23
22
|
# @attr_reader text_body [String, nil] Decoded text body
|
|
24
23
|
# @attr_reader html_body [String, nil] Decoded HTML body
|
|
25
24
|
# @attr_reader attachments [Array<InboundAttachment>, nil] The message attachments
|
|
26
|
-
# @attr_reader
|
|
27
|
-
# @attr_reader
|
|
28
|
-
# @attr_reader bounced_at [String, nil] Bounce timestamp (outbound messages only)
|
|
25
|
+
# @attr_reader delivery [InboundThreadMessageDelivery, nil] Delivery outcome (outbound messages only)
|
|
26
|
+
# @attr_reader forwards [Array<InboundForwardOutcome>, nil] Forward outcomes (inbound messages only)
|
|
29
27
|
InboundThreadMessage = Struct.new(
|
|
30
28
|
:visibility_status,
|
|
31
29
|
:direction,
|
|
@@ -45,9 +43,8 @@ module Mailtrap
|
|
|
45
43
|
:text_body,
|
|
46
44
|
:html_body,
|
|
47
45
|
:attachments,
|
|
48
|
-
:
|
|
49
|
-
:
|
|
50
|
-
:bounced_at,
|
|
46
|
+
:delivery,
|
|
47
|
+
:forwards,
|
|
51
48
|
keyword_init: true
|
|
52
49
|
)
|
|
53
50
|
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailtrap
|
|
4
|
+
# Data Transfer Object for the delivery of an outbound message inside an inbound thread
|
|
5
|
+
# @see https://docs.mailtrap.io/developers/inbound
|
|
6
|
+
# @attr_reader to [String] The recipient address
|
|
7
|
+
# @attr_reader status [String] The delivery status
|
|
8
|
+
# @attr_reader delivered_at [String, nil] Delivery timestamp
|
|
9
|
+
# @attr_reader bounced_at [String, nil] Bounce timestamp
|
|
10
|
+
InboundThreadMessageDelivery = Struct.new(
|
|
11
|
+
:to,
|
|
12
|
+
:status,
|
|
13
|
+
:delivered_at,
|
|
14
|
+
:bounced_at,
|
|
15
|
+
keyword_init: true
|
|
16
|
+
)
|
|
17
|
+
end
|
|
@@ -4,6 +4,8 @@ require_relative 'base_api'
|
|
|
4
4
|
require_relative 'inbound_thread'
|
|
5
5
|
require_relative 'inbound_thread_message'
|
|
6
6
|
require_relative 'inbound_attachment'
|
|
7
|
+
require_relative 'inbound_forward_outcome'
|
|
8
|
+
require_relative 'inbound_thread_message_delivery'
|
|
7
9
|
require_relative 'inbound_threads_list_response'
|
|
8
10
|
|
|
9
11
|
module Mailtrap
|
|
@@ -20,10 +22,11 @@ module Mailtrap
|
|
|
20
22
|
# Lists threads in an inbox (cursor-paginated)
|
|
21
23
|
# @param inbox_id [Integer] The inbox ID
|
|
22
24
|
# @param last_id [String, nil] Cursor from the previous response's +last_id+ for the next page
|
|
25
|
+
# @param search [String, nil] Search query
|
|
23
26
|
# @return [InboundThreadsListResponse] data, total_count, and last_id
|
|
24
27
|
# @!macro api_errors
|
|
25
|
-
def list(inbox_id, last_id: nil)
|
|
26
|
-
query_params =
|
|
28
|
+
def list(inbox_id, last_id: nil, search: nil)
|
|
29
|
+
query_params = { last_id:, search: }.compact
|
|
27
30
|
response = client.get(threads_path(inbox_id), query_params)
|
|
28
31
|
|
|
29
32
|
InboundThreadsListResponse.new(
|
|
@@ -69,6 +72,8 @@ module Mailtrap
|
|
|
69
72
|
Array(messages).map do |message|
|
|
70
73
|
attrs = message.slice(*InboundThreadMessage.members)
|
|
71
74
|
attrs[:attachments] = build_attachments(attrs[:attachments]) if attrs[:attachments]
|
|
75
|
+
attrs[:delivery] = build_delivery(attrs[:delivery]) if attrs[:delivery]
|
|
76
|
+
attrs[:forwards] = build_forwards(attrs[:forwards]) if attrs[:forwards]
|
|
72
77
|
|
|
73
78
|
InboundThreadMessage.new(**attrs)
|
|
74
79
|
end
|
|
@@ -79,5 +84,15 @@ module Mailtrap
|
|
|
79
84
|
InboundAttachment.new(**attachment.slice(*InboundAttachment.members))
|
|
80
85
|
end
|
|
81
86
|
end
|
|
87
|
+
|
|
88
|
+
def build_delivery(delivery)
|
|
89
|
+
InboundThreadMessageDelivery.new(**delivery.slice(*InboundThreadMessageDelivery.members))
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def build_forwards(forwards)
|
|
93
|
+
Array(forwards).map do |forward|
|
|
94
|
+
InboundForwardOutcome.new(**forward.slice(*InboundForwardOutcome.members))
|
|
95
|
+
end
|
|
96
|
+
end
|
|
82
97
|
end
|
|
83
98
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailtrap
|
|
4
|
+
# Data Transfer Object for Template
|
|
5
|
+
# @attr_reader id [Integer] The template ID
|
|
6
|
+
# @attr_reader uuid [String] The template UUID
|
|
7
|
+
# @attr_reader name [String] The template name
|
|
8
|
+
# @attr_reader subject [String] The email subject
|
|
9
|
+
# @attr_reader category [String] The template category
|
|
10
|
+
# @attr_reader body_html [String] The HTML content
|
|
11
|
+
# @attr_reader body_text [String] The plain text content
|
|
12
|
+
# @attr_reader created_at [String] The creation timestamp
|
|
13
|
+
# @attr_reader updated_at [String] The last update timestamp
|
|
14
|
+
Template = Struct.new(
|
|
15
|
+
:id,
|
|
16
|
+
:uuid,
|
|
17
|
+
:name,
|
|
18
|
+
:subject,
|
|
19
|
+
:category,
|
|
20
|
+
:body_html,
|
|
21
|
+
:body_text,
|
|
22
|
+
:created_at,
|
|
23
|
+
:updated_at,
|
|
24
|
+
keyword_init: true
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
# Response from listing templates (paginated)
|
|
28
|
+
# @attr_reader data [Array<Template>] Page of templates
|
|
29
|
+
# @attr_reader pagination [Hash] Page-token pagination metadata
|
|
30
|
+
# (+token+, +prev_token+, +next_token+, +first_url+, +prev_url+, +current_url+, +next_url+)
|
|
31
|
+
TemplatesListResponse = Struct.new(
|
|
32
|
+
:data,
|
|
33
|
+
:pagination,
|
|
34
|
+
keyword_init: true
|
|
35
|
+
)
|
|
36
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base_api'
|
|
4
|
+
require_relative 'template'
|
|
5
|
+
|
|
6
|
+
module Mailtrap
|
|
7
|
+
# @note Experimental: the +/api/templates+ endpoints may change their request and response
|
|
8
|
+
# shapes before general availability.
|
|
9
|
+
class TemplatesAPI
|
|
10
|
+
include BaseAPI
|
|
11
|
+
|
|
12
|
+
self.supported_options = %i[name subject category body_html body_text]
|
|
13
|
+
|
|
14
|
+
self.response_class = Template
|
|
15
|
+
|
|
16
|
+
# Lists templates for the account, one page at a time. Unlike {EmailTemplatesAPI#list}, it does
|
|
17
|
+
# not return every template: pass +pagination[:next_token]+ with the same +per_page+ to get the
|
|
18
|
+
# next page.
|
|
19
|
+
# @param per_page [Integer, nil] Number of templates per page (max 100, default 50)
|
|
20
|
+
# @param token [Integer, nil] Page number to retrieve (page-token pagination, default 1)
|
|
21
|
+
# @return [TemplatesListResponse] The page of templates and pagination metadata
|
|
22
|
+
# @!macro api_errors
|
|
23
|
+
def list(per_page: nil, token: nil)
|
|
24
|
+
query_params = {}
|
|
25
|
+
query_params[:per_page] = per_page unless per_page.nil?
|
|
26
|
+
query_params[:token] = token unless token.nil?
|
|
27
|
+
|
|
28
|
+
response = client.get(base_path, query_params)
|
|
29
|
+
|
|
30
|
+
TemplatesListResponse.new(
|
|
31
|
+
data: Array(response[:data]).map { |item| build_entity(item, response_class) },
|
|
32
|
+
pagination: response[:pagination]
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Retrieves a specific template
|
|
37
|
+
# @param template_id [Integer] The template ID
|
|
38
|
+
# @return [Template] Template object
|
|
39
|
+
# @!macro api_errors
|
|
40
|
+
def get(template_id)
|
|
41
|
+
base_get(template_id)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Creates a new template
|
|
45
|
+
# @param [Hash] options The parameters to create
|
|
46
|
+
# @option options [String] :name The template name (required)
|
|
47
|
+
# @option options [String] :subject The email subject (required)
|
|
48
|
+
# @option options [String] :category The template category (required)
|
|
49
|
+
# @option options [String, nil] :body_html The HTML content. Default: nil.
|
|
50
|
+
# @option options [String, nil] :body_text The plain text content. Default: nil.
|
|
51
|
+
# @return [Template] Created template object
|
|
52
|
+
# @!macro api_errors
|
|
53
|
+
# @raise [ArgumentError] If invalid options are provided
|
|
54
|
+
def create(options)
|
|
55
|
+
base_create(options)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Updates an existing template. Only the provided attributes are changed.
|
|
59
|
+
# @param template_id [Integer] The template ID
|
|
60
|
+
# @param [Hash] options The parameters to update
|
|
61
|
+
# @option options [String] :name The template name
|
|
62
|
+
# @option options [String] :subject The email subject
|
|
63
|
+
# @option options [String] :category The template category
|
|
64
|
+
# @option options [String, nil] :body_html The HTML content
|
|
65
|
+
# @option options [String, nil] :body_text The plain text content
|
|
66
|
+
# @return [Template] Updated template object
|
|
67
|
+
# @!macro api_errors
|
|
68
|
+
# @raise [ArgumentError] If invalid options are provided
|
|
69
|
+
def update(template_id, options)
|
|
70
|
+
base_update(template_id, options)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Deletes a template
|
|
74
|
+
# @param template_id [Integer] The template ID
|
|
75
|
+
# @return [nil]
|
|
76
|
+
# @!macro api_errors
|
|
77
|
+
def delete(template_id)
|
|
78
|
+
base_delete(template_id)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
private
|
|
82
|
+
|
|
83
|
+
def base_path
|
|
84
|
+
"/api/accounts/#{account_id}/templates"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def handle_response(response)
|
|
88
|
+
build_entity(response[:data], response_class)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
data/lib/mailtrap/version.rb
CHANGED
data/lib/mailtrap.rb
CHANGED
|
@@ -11,6 +11,7 @@ require_relative 'mailtrap/permissions_api'
|
|
|
11
11
|
require_relative 'mailtrap/sub_accounts_api'
|
|
12
12
|
require_relative 'mailtrap/billing_api'
|
|
13
13
|
require_relative 'mailtrap/email_templates_api'
|
|
14
|
+
require_relative 'mailtrap/templates_api'
|
|
14
15
|
require_relative 'mailtrap/contacts_api'
|
|
15
16
|
require_relative 'mailtrap/contact_lists_api'
|
|
16
17
|
require_relative 'mailtrap/contact_fields_api'
|
|
@@ -34,6 +35,7 @@ require_relative 'mailtrap/inbound_folders_api'
|
|
|
34
35
|
require_relative 'mailtrap/inbound_inboxes_api'
|
|
35
36
|
require_relative 'mailtrap/inbound_messages_api'
|
|
36
37
|
require_relative 'mailtrap/inbound_threads_api'
|
|
38
|
+
require_relative 'mailtrap/inbound_forward_rules_api'
|
|
37
39
|
|
|
38
40
|
module Mailtrap
|
|
39
41
|
# @!macro api_errors
|
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
|
+
version: 2.18.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-
|
|
11
|
+
date: 2026-10-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -85,6 +85,11 @@ files:
|
|
|
85
85
|
- lib/mailtrap/inbound_attachment.rb
|
|
86
86
|
- lib/mailtrap/inbound_folder.rb
|
|
87
87
|
- lib/mailtrap/inbound_folders_api.rb
|
|
88
|
+
- lib/mailtrap/inbound_forward_outcome.rb
|
|
89
|
+
- lib/mailtrap/inbound_forward_rule.rb
|
|
90
|
+
- lib/mailtrap/inbound_forward_rule_condition.rb
|
|
91
|
+
- lib/mailtrap/inbound_forward_rule_destination.rb
|
|
92
|
+
- lib/mailtrap/inbound_forward_rules_api.rb
|
|
88
93
|
- lib/mailtrap/inbound_inbox.rb
|
|
89
94
|
- lib/mailtrap/inbound_inboxes_api.rb
|
|
90
95
|
- lib/mailtrap/inbound_message.rb
|
|
@@ -93,6 +98,7 @@ files:
|
|
|
93
98
|
- lib/mailtrap/inbound_send_result.rb
|
|
94
99
|
- lib/mailtrap/inbound_thread.rb
|
|
95
100
|
- lib/mailtrap/inbound_thread_message.rb
|
|
101
|
+
- lib/mailtrap/inbound_thread_message_delivery.rb
|
|
96
102
|
- lib/mailtrap/inbound_threads_api.rb
|
|
97
103
|
- lib/mailtrap/inbound_threads_list_response.rb
|
|
98
104
|
- lib/mailtrap/inbox.rb
|
|
@@ -117,6 +123,8 @@ files:
|
|
|
117
123
|
- lib/mailtrap/sub_accounts_api.rb
|
|
118
124
|
- lib/mailtrap/suppression.rb
|
|
119
125
|
- lib/mailtrap/suppressions_api.rb
|
|
126
|
+
- lib/mailtrap/template.rb
|
|
127
|
+
- lib/mailtrap/templates_api.rb
|
|
120
128
|
- lib/mailtrap/tracking_opt_out.rb
|
|
121
129
|
- lib/mailtrap/tracking_opt_outs_api.rb
|
|
122
130
|
- lib/mailtrap/tracking_opt_outs_list_response.rb
|