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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/Gemfile.lock +1 -1
- data/README.md +42 -7
- data/lib/mailtrap/account_accesses_api.rb +2 -2
- data/lib/mailtrap/action_mailer/delivery_method.rb +13 -2
- data/lib/mailtrap/base_api.rb +6 -0
- data/lib/mailtrap/billing_usage.rb +1 -1
- data/lib/mailtrap/client.rb +23 -9
- data/lib/mailtrap/company_info.rb +1 -1
- data/lib/mailtrap/company_info_api.rb +14 -14
- data/lib/mailtrap/deprecation.rb +37 -0
- data/lib/mailtrap/domain.rb +48 -0
- data/lib/mailtrap/domains_api.rb +88 -0
- data/lib/mailtrap/email_campaign.rb +3 -3
- data/lib/mailtrap/email_campaigns_api.rb +4 -4
- data/lib/mailtrap/email_log_message.rb +1 -1
- data/lib/mailtrap/inbound_inbox.rb +1 -1
- data/lib/mailtrap/inbox.rb +5 -53
- data/lib/mailtrap/inboxes_api.rb +7 -108
- data/lib/mailtrap/marketing_stats.rb +39 -0
- data/lib/mailtrap/marketing_stats_api.rb +43 -0
- data/lib/mailtrap/project.rb +1 -1
- data/lib/mailtrap/projects_api.rb +2 -2
- data/lib/mailtrap/sandbox.rb +57 -0
- data/lib/mailtrap/sandbox_attachments_api.rb +15 -7
- data/lib/mailtrap/sandbox_message.rb +1 -1
- data/lib/mailtrap/sandbox_messages_api.rb +16 -8
- data/lib/mailtrap/sandboxes_api.rb +117 -0
- data/lib/mailtrap/sending_domain.rb +5 -44
- data/lib/mailtrap/sending_domains_api.rb +7 -80
- data/lib/mailtrap/stats_api.rb +7 -39
- data/lib/mailtrap/stats_query_params.rb +29 -0
- data/lib/mailtrap/sub_accounts_api.rb +13 -0
- data/lib/mailtrap/tracking_opt_out.rb +1 -1
- data/lib/mailtrap/tracking_opt_outs_api.rb +2 -2
- data/lib/mailtrap/version.rb +1 -1
- data/lib/mailtrap/webhook.rb +1 -1
- data/lib/mailtrap/webhooks_api.rb +1 -1
- data/lib/mailtrap.rb +3 -0
- metadata +10 -2
data/lib/mailtrap/inbox.rb
CHANGED
|
@@ -1,57 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'sandbox'
|
|
4
|
+
|
|
3
5
|
module Mailtrap
|
|
4
|
-
#
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
# @attr_reader name [String] The inbox name
|
|
8
|
-
# @attr_reader username [String] The inbox username
|
|
9
|
-
# @attr_reader password [String, nil] The inbox password
|
|
10
|
-
# @attr_reader max_size [Integer] The maximum inbox size in MB
|
|
11
|
-
# @attr_reader status [String] The inbox status
|
|
12
|
-
# @attr_reader email_username [String] The email username
|
|
13
|
-
# @attr_reader email_username_enabled [Boolean] Whether the email username is enabled
|
|
14
|
-
# @attr_reader sent_messages_count [Integer] The count of sent messages
|
|
15
|
-
# @attr_reader forwarded_messages_count [Integer] The count of forwarded messages
|
|
16
|
-
# @attr_reader used [Integer] The used inbox size in MB
|
|
17
|
-
# @attr_reader forward_from_email_address [String] The forwarding email address
|
|
18
|
-
# @attr_reader project_id [Integer] The associated project ID
|
|
19
|
-
# @attr_reader domain [String] The inbox domain
|
|
20
|
-
# @attr_reader pop3_domain [String] The POP3 domain
|
|
21
|
-
# @attr_reader email_domain [String] The email domain
|
|
22
|
-
# @attr_reader api_domain [String] The API domain
|
|
23
|
-
# @attr_reader emails_count [Integer] The total number of emails
|
|
24
|
-
# @attr_reader emails_unread_count [Integer] The number of unread emails
|
|
25
|
-
# @attr_reader last_message_sent_at [String, nil] The timestamp of the last sent message
|
|
26
|
-
# @attr_reader smtp_ports [Array<Integer>] The list of SMTP ports
|
|
27
|
-
# @attr_reader pop3_ports [Array<Integer>] The list of POP3 ports
|
|
28
|
-
# @attr_reader max_message_size [Integer] The maximum message size in MB
|
|
29
|
-
# @attr_reader permissions [Hash] List of permissions
|
|
30
|
-
Inbox = Struct.new(
|
|
31
|
-
:id,
|
|
32
|
-
:name,
|
|
33
|
-
:username,
|
|
34
|
-
:password,
|
|
35
|
-
:max_size,
|
|
36
|
-
:status,
|
|
37
|
-
:email_username,
|
|
38
|
-
:email_username_enabled,
|
|
39
|
-
:sent_messages_count,
|
|
40
|
-
:forwarded_messages_count,
|
|
41
|
-
:used,
|
|
42
|
-
:forward_from_email_address,
|
|
43
|
-
:project_id,
|
|
44
|
-
:domain,
|
|
45
|
-
:pop3_domain,
|
|
46
|
-
:email_domain,
|
|
47
|
-
:api_domain,
|
|
48
|
-
:emails_count,
|
|
49
|
-
:emails_unread_count,
|
|
50
|
-
:last_message_sent_at,
|
|
51
|
-
:smtp_ports,
|
|
52
|
-
:pop3_ports,
|
|
53
|
-
:max_message_size,
|
|
54
|
-
:permissions,
|
|
55
|
-
keyword_init: true
|
|
56
|
-
)
|
|
6
|
+
# @deprecated Use {Sandbox} instead.
|
|
7
|
+
Inbox = Sandbox
|
|
8
|
+
deprecate_constant :Inbox
|
|
57
9
|
end
|
data/lib/mailtrap/inboxes_api.rb
CHANGED
|
@@ -1,116 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative '
|
|
3
|
+
require_relative 'deprecation'
|
|
4
|
+
require_relative 'sandboxes_api'
|
|
4
5
|
require_relative 'inbox'
|
|
5
6
|
|
|
6
7
|
module Mailtrap
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
# Lists all Inboxes for the account
|
|
14
|
-
# @return [Array<Inbox>] Array of Inboxes
|
|
15
|
-
# @!macro api_errors
|
|
16
|
-
def list
|
|
17
|
-
base_list
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# Retrieves a specific inbox
|
|
21
|
-
# @param inbox_id [Integer] The inbox identifier
|
|
22
|
-
# @return [Inbox] Inbox object
|
|
23
|
-
# @!macro api_errors
|
|
24
|
-
def get(inbox_id)
|
|
25
|
-
base_get(inbox_id)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# Creates a new inbox
|
|
29
|
-
# @param [Hash] options The parameters to create
|
|
30
|
-
# @option options [String] :name The inbox name
|
|
31
|
-
# @return [Inbox] Created inbox object
|
|
32
|
-
# @!macro api_errors
|
|
33
|
-
# @raise [ArgumentError] If invalid options are provided
|
|
34
|
-
def create(options)
|
|
35
|
-
validate_options!(options, supported_options + [:project_id])
|
|
36
|
-
response = client.post("/api/accounts/#{account_id}/projects/#{options[:project_id]}/inboxes",
|
|
37
|
-
wrap_request(options))
|
|
38
|
-
handle_response(response)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# Deletes an inbox
|
|
42
|
-
# @param inbox_id [Integer] The Inbox identifier
|
|
43
|
-
# @return nil
|
|
44
|
-
# @!macro api_errors
|
|
45
|
-
def delete(inbox_id)
|
|
46
|
-
base_delete(inbox_id)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
# Updates an existing Inbox
|
|
50
|
-
# @param inbox_id [Integer] The Inbox identifier
|
|
51
|
-
# @param [Hash] options The parameters to update
|
|
52
|
-
# @option options [String] :name The inbox name
|
|
53
|
-
# @option options [String] :email_username The inbox email username
|
|
54
|
-
# @return [Inbox] Updated Inbox object
|
|
55
|
-
# @!macro api_errors
|
|
56
|
-
# @raise [ArgumentError] If invalid options are provided
|
|
57
|
-
def update(inbox_id, options)
|
|
58
|
-
base_update(inbox_id, options, supported_options + [:email_username])
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# Delete all messages (emails) from Inbox
|
|
62
|
-
# @param inbox_id [Integer] The Inbox identifier
|
|
63
|
-
# @return [Inbox] Updated Inbox object
|
|
64
|
-
# @!macro api_errors
|
|
65
|
-
def clean(inbox_id)
|
|
66
|
-
response = client.patch("#{base_path}/#{inbox_id}/clean")
|
|
67
|
-
handle_response(response)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
# Mark all messages in the inbox as read
|
|
71
|
-
# @param inbox_id [Integer] The Inbox identifier
|
|
72
|
-
# @return [Inbox] Updated Inbox object
|
|
73
|
-
# @!macro api_errors
|
|
74
|
-
def mark_as_read(inbox_id)
|
|
75
|
-
response = client.patch("#{base_path}/#{inbox_id}/all_read")
|
|
76
|
-
handle_response(response)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
# Reset SMTP credentials of the inbox
|
|
80
|
-
# @param inbox_id [Integer] The Inbox identifier
|
|
81
|
-
# @return [Inbox] Updated Inbox object
|
|
82
|
-
# @!macro api_errors
|
|
83
|
-
def reset_credentials(inbox_id)
|
|
84
|
-
response = client.patch("#{base_path}/#{inbox_id}/reset_credentials")
|
|
85
|
-
handle_response(response)
|
|
86
|
-
end
|
|
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
|
-
|
|
106
|
-
private
|
|
107
|
-
|
|
108
|
-
def wrap_request(options)
|
|
109
|
-
{ inbox: options }
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def base_path
|
|
113
|
-
"/api/accounts/#{account_id}/inboxes"
|
|
8
|
+
# @deprecated Use {SandboxesAPI} instead.
|
|
9
|
+
class InboxesAPI < SandboxesAPI
|
|
10
|
+
def initialize(*)
|
|
11
|
+
Deprecation.warn('Mailtrap::InboxesAPI', 'Mailtrap::SandboxesAPI')
|
|
12
|
+
super
|
|
114
13
|
end
|
|
115
14
|
end
|
|
116
15
|
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailtrap
|
|
4
|
+
# Data Transfer Object for Email Marketing Stats
|
|
5
|
+
#
|
|
6
|
+
# Aggregated metrics of the account's Email Marketing traffic (campaigns and automations) for
|
|
7
|
+
# the requested period and filters. Rates are fractions from 0 to 1. Every count and rate is +0+
|
|
8
|
+
# when nothing matched.
|
|
9
|
+
# @see https://docs.mailtrap.io/developers/email-marketing/marketing-stats
|
|
10
|
+
# @attr_reader delivery_count [Integer] Number of delivered messages
|
|
11
|
+
# @attr_reader delivery_rate [Float, Integer] Share of sent messages that were delivered (0–1)
|
|
12
|
+
# @attr_reader bounce_count [Integer] Number of bounced messages
|
|
13
|
+
# @attr_reader bounce_rate [Float, Integer] Share of sent messages that bounced (0–1)
|
|
14
|
+
# @attr_reader open_count [Integer] Number of opened messages
|
|
15
|
+
# @attr_reader open_rate [Float, Integer] Share of delivered messages that were opened (0–1)
|
|
16
|
+
# @attr_reader click_count [Integer] Number of clicked messages
|
|
17
|
+
# @attr_reader click_rate [Float, Integer] Share of delivered messages that were clicked (0–1)
|
|
18
|
+
# @attr_reader spam_count [Integer] Number of spam complaints
|
|
19
|
+
# @attr_reader spam_rate [Float, Integer] Share of delivered messages marked as spam (0–1)
|
|
20
|
+
# @attr_reader unsubscription_count [Integer] Number of unsubscriptions
|
|
21
|
+
# @attr_reader unsubscription_rate [Float, Integer] Share of delivered messages that unsubscribed (0–1)
|
|
22
|
+
# @attr_reader sent_count [Integer] Number of sent messages (delivered plus bounced)
|
|
23
|
+
MarketingStats = Struct.new(
|
|
24
|
+
:delivery_count,
|
|
25
|
+
:delivery_rate,
|
|
26
|
+
:bounce_count,
|
|
27
|
+
:bounce_rate,
|
|
28
|
+
:open_count,
|
|
29
|
+
:open_rate,
|
|
30
|
+
:click_count,
|
|
31
|
+
:click_rate,
|
|
32
|
+
:spam_count,
|
|
33
|
+
:spam_rate,
|
|
34
|
+
:unsubscription_count,
|
|
35
|
+
:unsubscription_rate,
|
|
36
|
+
:sent_count,
|
|
37
|
+
keyword_init: true
|
|
38
|
+
)
|
|
39
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base_api'
|
|
4
|
+
require_relative 'stats_query_params'
|
|
5
|
+
require_relative 'marketing_stats'
|
|
6
|
+
|
|
7
|
+
module Mailtrap
|
|
8
|
+
class MarketingStatsAPI
|
|
9
|
+
include BaseAPI
|
|
10
|
+
include StatsQueryParams
|
|
11
|
+
|
|
12
|
+
# @param client [Mailtrap::Client] The client instance
|
|
13
|
+
def initialize(client = Mailtrap::Client.new)
|
|
14
|
+
@client = client
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Get aggregated Email Marketing stats: campaigns and automations together, the same numbers
|
|
18
|
+
# as Email Marketing > Stats Overview in the app. Email API/SMTP traffic is reported by {StatsAPI}.
|
|
19
|
+
# @param start_date [String, Date, Time] Start of the period, inclusive (required)
|
|
20
|
+
# @param end_date [String, Date, Time] End of the period, inclusive (required)
|
|
21
|
+
# @param sending_domain_ids [Array<Integer>] Filter by domain IDs
|
|
22
|
+
# @param sources [Array<String>] Filter by source: +campaigns+ or +automations+;
|
|
23
|
+
# omit it, or pass both, to include campaigns and automations together
|
|
24
|
+
# @param email_service_providers [Array<String>] Filter by recipient email service providers
|
|
25
|
+
# @return [MarketingStats] Aggregated Email Marketing stats
|
|
26
|
+
# @!macro api_errors
|
|
27
|
+
# @raise [ArgumentError] If a date is not a Date, Time, or String in +YYYY-MM-DD+ format
|
|
28
|
+
def get(start_date:, end_date:, sending_domain_ids: nil, sources: nil, email_service_providers: nil)
|
|
29
|
+
query_params = build_query_params(
|
|
30
|
+
start_date, end_date,
|
|
31
|
+
{ sending_domain_ids:, sources:, email_service_providers: }
|
|
32
|
+
)
|
|
33
|
+
response = client.get(base_path, query_params)
|
|
34
|
+
build_entity(response[:data], MarketingStats)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def base_path
|
|
40
|
+
'/api/marketing/stats'
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
data/lib/mailtrap/project.rb
CHANGED
|
@@ -6,7 +6,7 @@ module Mailtrap
|
|
|
6
6
|
# @attr_reader id [Integer] The project ID
|
|
7
7
|
# @attr_reader name [String] The project name
|
|
8
8
|
# @attr_reader share_links [Hash] Admin and viewer share links
|
|
9
|
-
# @attr_reader inboxes [Array<Mailtrap::
|
|
9
|
+
# @attr_reader inboxes [Array<Mailtrap::Sandbox>] Array of the project's sandboxes
|
|
10
10
|
# @attr_reader permissions [Hash] List of permissions
|
|
11
11
|
#
|
|
12
12
|
Project = Struct.new(
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative 'base_api'
|
|
4
4
|
require_relative 'project'
|
|
5
|
-
require_relative '
|
|
5
|
+
require_relative 'sandbox'
|
|
6
6
|
|
|
7
7
|
module Mailtrap
|
|
8
8
|
class ProjectsAPI
|
|
@@ -60,7 +60,7 @@ module Mailtrap
|
|
|
60
60
|
def handle_response(response)
|
|
61
61
|
build_entity(
|
|
62
62
|
response.merge(
|
|
63
|
-
inboxes: response[:inboxes]&.map { |
|
|
63
|
+
inboxes: response[:inboxes]&.map { |sandbox| build_entity(sandbox, Mailtrap::Sandbox) }
|
|
64
64
|
),
|
|
65
65
|
response_class
|
|
66
66
|
)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailtrap
|
|
4
|
+
# Data Transfer Object for Sandbox
|
|
5
|
+
# @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/ee252e413d78a-create-project
|
|
6
|
+
# @attr_reader id [Integer] The sandbox ID
|
|
7
|
+
# @attr_reader name [String] The sandbox name
|
|
8
|
+
# @attr_reader username [String] The sandbox username
|
|
9
|
+
# @attr_reader password [String, nil] The sandbox password
|
|
10
|
+
# @attr_reader max_size [Integer] The maximum sandbox size in MB
|
|
11
|
+
# @attr_reader status [String] The sandbox status
|
|
12
|
+
# @attr_reader email_username [String] The email username
|
|
13
|
+
# @attr_reader email_username_enabled [Boolean] Whether the email username is enabled
|
|
14
|
+
# @attr_reader sent_messages_count [Integer] The count of sent messages
|
|
15
|
+
# @attr_reader forwarded_messages_count [Integer] The count of forwarded messages
|
|
16
|
+
# @attr_reader used [Boolean] Whether the sandbox has been used
|
|
17
|
+
# @attr_reader forward_from_email_address [String] The forwarding email address
|
|
18
|
+
# @attr_reader project_id [Integer] The associated project ID
|
|
19
|
+
# @attr_reader domain [String] The sandbox domain
|
|
20
|
+
# @attr_reader pop3_domain [String] The POP3 domain
|
|
21
|
+
# @attr_reader email_domain [String] The email domain
|
|
22
|
+
# @attr_reader api_domain [String] The API domain
|
|
23
|
+
# @attr_reader emails_count [Integer] The total number of emails
|
|
24
|
+
# @attr_reader emails_unread_count [Integer] The number of unread emails
|
|
25
|
+
# @attr_reader last_message_sent_at [String, nil] The timestamp of the last sent message
|
|
26
|
+
# @attr_reader smtp_ports [Array<Integer>] The list of SMTP ports
|
|
27
|
+
# @attr_reader pop3_ports [Array<Integer>] The list of POP3 ports
|
|
28
|
+
# @attr_reader max_message_size [Integer] The maximum message size in bytes
|
|
29
|
+
# @attr_reader permissions [Hash] List of permissions
|
|
30
|
+
Sandbox = Struct.new(
|
|
31
|
+
:id,
|
|
32
|
+
:name,
|
|
33
|
+
:username,
|
|
34
|
+
:password,
|
|
35
|
+
:max_size,
|
|
36
|
+
:status,
|
|
37
|
+
:email_username,
|
|
38
|
+
:email_username_enabled,
|
|
39
|
+
:sent_messages_count,
|
|
40
|
+
:forwarded_messages_count,
|
|
41
|
+
:used,
|
|
42
|
+
:forward_from_email_address,
|
|
43
|
+
:project_id,
|
|
44
|
+
:domain,
|
|
45
|
+
:pop3_domain,
|
|
46
|
+
:email_domain,
|
|
47
|
+
:api_domain,
|
|
48
|
+
:emails_count,
|
|
49
|
+
:emails_unread_count,
|
|
50
|
+
:last_message_sent_at,
|
|
51
|
+
:smtp_ports,
|
|
52
|
+
:pop3_ports,
|
|
53
|
+
:max_message_size,
|
|
54
|
+
:permissions,
|
|
55
|
+
keyword_init: true
|
|
56
|
+
)
|
|
57
|
+
end
|
|
@@ -1,32 +1,40 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative 'base_api'
|
|
4
|
+
require_relative 'deprecation'
|
|
4
5
|
require_relative 'sandbox_attachment'
|
|
5
6
|
|
|
6
7
|
module Mailtrap
|
|
7
8
|
class SandboxAttachmentsAPI
|
|
8
9
|
include BaseAPI
|
|
9
10
|
|
|
10
|
-
attr_reader :
|
|
11
|
+
attr_reader :sandbox_id, :sandbox_message_id
|
|
11
12
|
|
|
12
13
|
self.response_class = SandboxAttachment
|
|
13
14
|
|
|
14
15
|
# @param account_id [Integer] The account ID
|
|
15
|
-
# @param
|
|
16
|
+
# @param sandbox_id [Integer] The sandbox ID
|
|
16
17
|
# @param sandbox_message_id [Integer] The message ID
|
|
17
18
|
# @param client [Mailtrap::Client] The client instance
|
|
18
19
|
# @raise [ArgumentError] If account_id is nil
|
|
19
|
-
# @raise [ArgumentError] If
|
|
20
|
-
def initialize(account_id,
|
|
21
|
-
raise ArgumentError, '
|
|
20
|
+
# @raise [ArgumentError] If sandbox_id is nil
|
|
21
|
+
def initialize(account_id, sandbox_id, sandbox_message_id, client = Mailtrap::Client.new)
|
|
22
|
+
raise ArgumentError, 'sandbox_id is required' if sandbox_id.nil?
|
|
22
23
|
raise ArgumentError, 'sandbox_message_id is required' if sandbox_message_id.nil?
|
|
23
24
|
|
|
24
|
-
@
|
|
25
|
+
@sandbox_id = sandbox_id
|
|
25
26
|
@sandbox_message_id = sandbox_message_id
|
|
26
27
|
|
|
27
28
|
super(account_id, client)
|
|
28
29
|
end
|
|
29
30
|
|
|
31
|
+
# @deprecated Use {#sandbox_id} instead.
|
|
32
|
+
# @return [Integer] The sandbox ID
|
|
33
|
+
def inbox_id
|
|
34
|
+
Deprecation.warn('Mailtrap::SandboxAttachmentsAPI#inbox_id', 'Mailtrap::SandboxAttachmentsAPI#sandbox_id')
|
|
35
|
+
sandbox_id
|
|
36
|
+
end
|
|
37
|
+
|
|
30
38
|
# Retrieves a specific sandbox attachment
|
|
31
39
|
# @param sandbox_attachment_id [Integer] The sandbox attachment ID
|
|
32
40
|
# @return [SandboxAttachment] Sandbox attachment object
|
|
@@ -45,7 +53,7 @@ module Mailtrap
|
|
|
45
53
|
private
|
|
46
54
|
|
|
47
55
|
def base_path
|
|
48
|
-
"/api/accounts/#{account_id}/inboxes/#{
|
|
56
|
+
"/api/accounts/#{account_id}/inboxes/#{sandbox_id}/messages/#{sandbox_message_id}/attachments"
|
|
49
57
|
end
|
|
50
58
|
end
|
|
51
59
|
end
|
|
@@ -4,7 +4,7 @@ module Mailtrap
|
|
|
4
4
|
# Data Transfer Object for Sandbox Message
|
|
5
5
|
# @see https://docs.mailtrap.io/developers/email-sandbox/email-sandbox-api/messages
|
|
6
6
|
# @attr_reader id [Integer] The message ID
|
|
7
|
-
# @attr_reader inbox_id [Integer] The
|
|
7
|
+
# @attr_reader inbox_id [Integer] The sandbox ID
|
|
8
8
|
# @attr_reader subject [String] The message subject
|
|
9
9
|
# @attr_reader sent_at [String] The timestamp when the message was sent
|
|
10
10
|
# @attr_reader from_email [String] The sender's email address
|
|
@@ -1,32 +1,40 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative 'base_api'
|
|
4
|
+
require_relative 'deprecation'
|
|
4
5
|
require_relative 'sandbox_message'
|
|
5
6
|
|
|
6
7
|
module Mailtrap
|
|
7
8
|
class SandboxMessagesAPI
|
|
8
9
|
include BaseAPI
|
|
9
10
|
|
|
10
|
-
attr_reader :
|
|
11
|
+
attr_reader :sandbox_id
|
|
11
12
|
|
|
12
13
|
self.supported_options = %i[is_read]
|
|
13
14
|
|
|
14
15
|
self.response_class = SandboxMessage
|
|
15
16
|
|
|
16
17
|
# @param account_id [Integer] The account ID
|
|
17
|
-
# @param
|
|
18
|
+
# @param sandbox_id [Integer] The sandbox ID
|
|
18
19
|
# @param client [Mailtrap::Client] The client instance
|
|
19
20
|
# @raise [ArgumentError] If account_id is nil
|
|
20
|
-
# @raise [ArgumentError] If
|
|
21
|
-
def initialize(account_id,
|
|
22
|
-
raise ArgumentError, '
|
|
21
|
+
# @raise [ArgumentError] If sandbox_id is nil
|
|
22
|
+
def initialize(account_id, sandbox_id, client = Mailtrap::Client.new)
|
|
23
|
+
raise ArgumentError, 'sandbox_id is required' if sandbox_id.nil?
|
|
23
24
|
|
|
24
|
-
@
|
|
25
|
+
@sandbox_id = sandbox_id
|
|
25
26
|
|
|
26
27
|
super(account_id, client)
|
|
27
28
|
end
|
|
28
29
|
|
|
29
|
-
#
|
|
30
|
+
# @deprecated Use {#sandbox_id} instead.
|
|
31
|
+
# @return [Integer] The sandbox ID
|
|
32
|
+
def inbox_id
|
|
33
|
+
Deprecation.warn('Mailtrap::SandboxMessagesAPI#inbox_id', 'Mailtrap::SandboxMessagesAPI#sandbox_id')
|
|
34
|
+
sandbox_id
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Retrieves a specific sandbox message
|
|
30
38
|
# @param message_id [Integer] The sandbox message ID
|
|
31
39
|
# @return [SandboxMessage] Sandbox message object
|
|
32
40
|
# @!macro api_errors
|
|
@@ -165,7 +173,7 @@ module Mailtrap
|
|
|
165
173
|
private
|
|
166
174
|
|
|
167
175
|
def base_path
|
|
168
|
-
"/api/accounts/#{account_id}/inboxes/#{
|
|
176
|
+
"/api/accounts/#{account_id}/inboxes/#{sandbox_id}/messages"
|
|
169
177
|
end
|
|
170
178
|
|
|
171
179
|
def wrap_request(options)
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base_api'
|
|
4
|
+
require_relative 'sandbox'
|
|
5
|
+
|
|
6
|
+
module Mailtrap
|
|
7
|
+
class SandboxesAPI
|
|
8
|
+
include BaseAPI
|
|
9
|
+
|
|
10
|
+
self.supported_options = %i[name]
|
|
11
|
+
self.response_class = Sandbox
|
|
12
|
+
|
|
13
|
+
# Lists all sandboxes for the account
|
|
14
|
+
# @return [Array<Sandbox>] Array of sandboxes
|
|
15
|
+
# @!macro api_errors
|
|
16
|
+
def list
|
|
17
|
+
base_list
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Retrieves a specific sandbox
|
|
21
|
+
# @param sandbox_id [Integer] The sandbox identifier
|
|
22
|
+
# @return [Sandbox] Sandbox object
|
|
23
|
+
# @!macro api_errors
|
|
24
|
+
def get(sandbox_id)
|
|
25
|
+
base_get(sandbox_id)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Creates a new sandbox
|
|
29
|
+
# @param [Hash] options The parameters to create
|
|
30
|
+
# @option options [String] :name The sandbox name
|
|
31
|
+
# @option options [Integer] :project_id The project ID. Required.
|
|
32
|
+
# @return [Sandbox] Created sandbox object
|
|
33
|
+
# @!macro api_errors
|
|
34
|
+
# @raise [ArgumentError] If invalid options are provided
|
|
35
|
+
def create(options)
|
|
36
|
+
validate_options!(options, supported_options + [:project_id])
|
|
37
|
+
response = client.post("/api/accounts/#{account_id}/projects/#{options[:project_id]}/inboxes",
|
|
38
|
+
wrap_request(options))
|
|
39
|
+
handle_response(response)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Deletes a sandbox
|
|
43
|
+
# @param sandbox_id [Integer] The sandbox identifier
|
|
44
|
+
# @return [Hash, nil] Deleted sandbox data, or nil when the API returns no content
|
|
45
|
+
# @!macro api_errors
|
|
46
|
+
def delete(sandbox_id)
|
|
47
|
+
base_delete(sandbox_id)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Updates an existing sandbox
|
|
51
|
+
# @param sandbox_id [Integer] The sandbox identifier
|
|
52
|
+
# @param [Hash] options The parameters to update
|
|
53
|
+
# @option options [String] :name The sandbox name
|
|
54
|
+
# @option options [String] :email_username The sandbox email username
|
|
55
|
+
# @return [Sandbox] Updated sandbox object
|
|
56
|
+
# @!macro api_errors
|
|
57
|
+
# @raise [ArgumentError] If invalid options are provided
|
|
58
|
+
def update(sandbox_id, options)
|
|
59
|
+
base_update(sandbox_id, options, supported_options + [:email_username])
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Delete all messages (emails) from the sandbox
|
|
63
|
+
# @param sandbox_id [Integer] The sandbox identifier
|
|
64
|
+
# @return [Sandbox] Updated sandbox object
|
|
65
|
+
# @!macro api_errors
|
|
66
|
+
def clean(sandbox_id)
|
|
67
|
+
response = client.patch("#{base_path}/#{sandbox_id}/clean")
|
|
68
|
+
handle_response(response)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Mark all messages in the sandbox as read
|
|
72
|
+
# @param sandbox_id [Integer] The sandbox identifier
|
|
73
|
+
# @return [Sandbox] Updated sandbox object
|
|
74
|
+
# @!macro api_errors
|
|
75
|
+
def mark_as_read(sandbox_id)
|
|
76
|
+
response = client.patch("#{base_path}/#{sandbox_id}/all_read")
|
|
77
|
+
handle_response(response)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Reset SMTP credentials of the sandbox
|
|
81
|
+
# @param sandbox_id [Integer] The sandbox identifier
|
|
82
|
+
# @return [Sandbox] Updated sandbox object
|
|
83
|
+
# @!macro api_errors
|
|
84
|
+
def reset_credentials(sandbox_id)
|
|
85
|
+
response = client.patch("#{base_path}/#{sandbox_id}/reset_credentials")
|
|
86
|
+
handle_response(response)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Turn the email address of the sandbox on/off
|
|
90
|
+
# @param sandbox_id [Integer] The sandbox identifier
|
|
91
|
+
# @return [Sandbox] Updated sandbox object
|
|
92
|
+
# @!macro api_errors
|
|
93
|
+
def toggle_email_username(sandbox_id)
|
|
94
|
+
response = client.patch("#{base_path}/#{sandbox_id}/toggle_email_username")
|
|
95
|
+
handle_response(response)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Reset username of email address per sandbox
|
|
99
|
+
# @param sandbox_id [Integer] The sandbox identifier
|
|
100
|
+
# @return [Sandbox] Updated sandbox object
|
|
101
|
+
# @!macro api_errors
|
|
102
|
+
def reset_email_username(sandbox_id)
|
|
103
|
+
response = client.patch("#{base_path}/#{sandbox_id}/reset_email_username")
|
|
104
|
+
handle_response(response)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
private
|
|
108
|
+
|
|
109
|
+
def wrap_request(options)
|
|
110
|
+
{ inbox: options }
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def base_path
|
|
114
|
+
"/api/accounts/#{account_id}/inboxes"
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
@@ -1,48 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'domain'
|
|
4
|
+
|
|
3
5
|
module Mailtrap
|
|
4
|
-
#
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
# @attr_reader domain_name [String] The sending domain name
|
|
8
|
-
# @attr_reader demo [Boolean] Whether the sending domain is a demo domain
|
|
9
|
-
# @attr_reader compliance_status [String] The compliance status of the sending domain
|
|
10
|
-
# @attr_reader dns_verified [Boolean] Whether the DNS records are verified
|
|
11
|
-
# @attr_reader dns_verified_at [String, nil] The timestamp when DNS was verified
|
|
12
|
-
# @attr_reader dns_records [Array] The DNS records for the sending domain
|
|
13
|
-
# @attr_reader open_tracking_enabled [Boolean] Whether open tracking is enabled
|
|
14
|
-
# @attr_reader click_tracking_enabled [Boolean] Whether click tracking is enabled
|
|
15
|
-
# @attr_reader tracking_opt_out_enabled [Boolean] Whether the tracking opt-out link is enabled
|
|
16
|
-
# @attr_reader auto_unsubscribe_link_enabled [Boolean] Whether auto unsubscribe link is enabled
|
|
17
|
-
# @attr_reader custom_domain_tracking_enabled [Boolean] Whether custom domain tracking is enabled
|
|
18
|
-
# @attr_reader health_alerts_enabled [Boolean] Whether health alerts are enabled
|
|
19
|
-
# @attr_reader critical_alerts_enabled [Boolean] Whether critical alerts are enabled
|
|
20
|
-
# @attr_reader alert_recipient_email [String, nil] The email address for alert recipients
|
|
21
|
-
# @attr_reader inbound_enabled [Boolean] Whether inbound email is enabled for this domain
|
|
22
|
-
# @attr_reader inbound_verified [Boolean] Whether the domain's inbound MX records are verified
|
|
23
|
-
# @attr_reader permissions [Hash] The permissions for the sending domain
|
|
24
|
-
#
|
|
25
|
-
SendingDomain = Struct.new(
|
|
26
|
-
:id,
|
|
27
|
-
:domain_name,
|
|
28
|
-
:demo,
|
|
29
|
-
:compliance_status,
|
|
30
|
-
:dns_verified,
|
|
31
|
-
:dns_verified_at,
|
|
32
|
-
:dns_records,
|
|
33
|
-
:open_tracking_enabled,
|
|
34
|
-
:click_tracking_enabled,
|
|
35
|
-
:tracking_opt_out_enabled,
|
|
36
|
-
:auto_unsubscribe_link_enabled,
|
|
37
|
-
:custom_domain_tracking_enabled,
|
|
38
|
-
:health_alerts_enabled,
|
|
39
|
-
:critical_alerts_enabled,
|
|
40
|
-
:alert_recipient_email,
|
|
41
|
-
:inbound_enabled,
|
|
42
|
-
:inbound_verified,
|
|
43
|
-
:permissions,
|
|
44
|
-
:created_at,
|
|
45
|
-
:updated_at,
|
|
46
|
-
keyword_init: true
|
|
47
|
-
)
|
|
6
|
+
# @deprecated Use {Domain} instead.
|
|
7
|
+
SendingDomain = Domain
|
|
8
|
+
deprecate_constant :SendingDomain
|
|
48
9
|
end
|