mailtrap 2.5.0 → 2.7.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/.coderabbit.yaml +10 -0
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +11 -0
- data/Gemfile +7 -4
- data/Gemfile.lock +68 -53
- data/README.md +75 -29
- data/lib/mailtrap/account.rb +16 -0
- data/lib/mailtrap/accounts_api.rb +33 -0
- data/lib/mailtrap/client.rb +44 -28
- data/lib/mailtrap/contact.rb +0 -5
- data/lib/mailtrap/contact_field.rb +1 -6
- data/lib/mailtrap/contact_import.rb +1 -6
- data/lib/mailtrap/contact_list.rb +1 -6
- data/lib/mailtrap/email_template.rb +1 -6
- data/lib/mailtrap/inbox.rb +57 -0
- data/lib/mailtrap/inboxes_api.rb +98 -0
- data/lib/mailtrap/project.rb +20 -0
- data/lib/mailtrap/projects_api.rb +77 -0
- data/lib/mailtrap/sandbox_attachment.rb +34 -0
- data/lib/mailtrap/sandbox_attachments_api.rb +51 -0
- data/lib/mailtrap/sandbox_message.rb +59 -0
- data/lib/mailtrap/sandbox_messages_api.rb +155 -0
- data/lib/mailtrap/sending_domain.rb +42 -0
- data/lib/mailtrap/sending_domains_api.rb +67 -0
- data/lib/mailtrap/suppression.rb +1 -6
- data/lib/mailtrap/version.rb +1 -1
- data/lib/mailtrap.rb +6 -0
- metadata +16 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a56e52ebde096ddaa019f4c16e15f63fe37ace69d91892f4c92044c0727b3c3f
|
|
4
|
+
data.tar.gz: 79a7aca8251526389c4faa2f643ca8f7e58182de4dcbada0af2d8f9a5afe6464
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: df5e86fd7a0d31a5b717e189ae9637f6e0f413dad2d4fd2c9adbc56e7be5197ef5a59a759dc6eee9ff19a98c9196c7d5f1a984b3ee5f75ef69a5ca0f376a5519
|
|
7
|
+
data.tar.gz: 516e66780366eaf9f76b07f0957092b345fdd0262cd15dd997dcde5887276b7b37ba9c5c29971c6e7e53082e74db4deb5575ba1b4e0ebab4341fae05d7accc98
|
data/.coderabbit.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
|
|
2
|
+
language: en
|
|
3
|
+
reviews:
|
|
4
|
+
path_instructions:
|
|
5
|
+
- path: "spec/fixtures/vcr_cassettes/**/*.yml"
|
|
6
|
+
instructions: |
|
|
7
|
+
Act as a data privacy officer. Carefully read all the vcr cassettes
|
|
8
|
+
with recorded HTTP interactions and try to identify sensitive data that
|
|
9
|
+
could potentially be recorded. It can be anything from PII to
|
|
10
|
+
credentials. Ignore obvious placeholder values and real IDs in URLs.
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
## [2.7.0] - 2026-02-24
|
|
2
|
+
- Add Sandbox Messages API
|
|
3
|
+
- Add Sending Domains API
|
|
4
|
+
- Add Sandbox Attachments API
|
|
5
|
+
- Add Accounts API
|
|
6
|
+
|
|
7
|
+
## [2.6.0] - 2026-01-27
|
|
8
|
+
- Add Inboxes API
|
|
9
|
+
- Add Projects API
|
|
10
|
+
- Models' `to_h` now returns all fields without compacting
|
|
11
|
+
|
|
1
12
|
## [2.5.0] - 2025-11-10
|
|
2
13
|
- Add Contact Imports API
|
|
3
14
|
- Add Suppressions API
|
data/Gemfile
CHANGED
|
@@ -8,13 +8,16 @@ gem 'appraisal'
|
|
|
8
8
|
gem 'irb'
|
|
9
9
|
gem 'mail'
|
|
10
10
|
gem 'net-smtp'
|
|
11
|
-
gem '
|
|
12
|
-
gem '
|
|
13
|
-
gem '
|
|
11
|
+
gem 'rack'
|
|
12
|
+
gem 'rackup'
|
|
13
|
+
gem 'rake', '~> 13.3'
|
|
14
|
+
gem 'rdoc', '~> 7.1.0'
|
|
15
|
+
gem 'rspec', '~> 3'
|
|
14
16
|
gem 'rspec-its'
|
|
15
|
-
gem 'rubocop', '~> 1.
|
|
17
|
+
gem 'rubocop', '~> 1.82'
|
|
16
18
|
gem 'rubocop-rake', require: false
|
|
17
19
|
gem 'rubocop-rspec', require: false
|
|
18
20
|
gem 'vcr'
|
|
19
21
|
gem 'webmock'
|
|
22
|
+
gem 'webrick'
|
|
20
23
|
gem 'yard', '~> 0.9'
|
data/Gemfile.lock
CHANGED
|
@@ -1,88 +1,96 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
mailtrap (2.
|
|
4
|
+
mailtrap (2.7.0)
|
|
5
5
|
base64
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
addressable (2.8.
|
|
11
|
-
public_suffix (>= 2.0.2, <
|
|
10
|
+
addressable (2.8.8)
|
|
11
|
+
public_suffix (>= 2.0.2, < 8.0)
|
|
12
12
|
appraisal (2.5.0)
|
|
13
13
|
bundler
|
|
14
14
|
rake
|
|
15
15
|
thor (>= 0.14.0)
|
|
16
16
|
ast (2.4.3)
|
|
17
17
|
base64 (0.3.0)
|
|
18
|
-
bigdecimal (
|
|
19
|
-
crack (1.0.
|
|
18
|
+
bigdecimal (4.0.1)
|
|
19
|
+
crack (1.0.1)
|
|
20
20
|
bigdecimal
|
|
21
21
|
rexml
|
|
22
|
-
date (3.
|
|
23
|
-
diff-lcs (1.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
date (3.5.1)
|
|
23
|
+
diff-lcs (1.6.2)
|
|
24
|
+
erb (6.0.1)
|
|
25
|
+
hashdiff (1.2.1)
|
|
26
|
+
io-console (0.8.2)
|
|
27
|
+
irb (1.16.0)
|
|
27
28
|
pp (>= 0.6.0)
|
|
28
29
|
rdoc (>= 4.0.0)
|
|
29
30
|
reline (>= 0.4.2)
|
|
30
|
-
json (2.
|
|
31
|
+
json (2.18.0)
|
|
31
32
|
language_server-protocol (3.17.0.5)
|
|
32
33
|
lint_roller (1.1.0)
|
|
33
|
-
|
|
34
|
+
logger (1.7.0)
|
|
35
|
+
mail (2.9.0)
|
|
36
|
+
logger
|
|
34
37
|
mini_mime (>= 0.1.1)
|
|
35
38
|
net-imap
|
|
36
39
|
net-pop
|
|
37
40
|
net-smtp
|
|
38
41
|
mini_mime (1.1.5)
|
|
39
|
-
net-imap (0.
|
|
42
|
+
net-imap (0.6.2)
|
|
40
43
|
date
|
|
41
44
|
net-protocol
|
|
42
45
|
net-pop (0.1.2)
|
|
43
46
|
net-protocol
|
|
44
47
|
net-protocol (0.2.2)
|
|
45
48
|
timeout
|
|
46
|
-
net-smtp (0.5.
|
|
49
|
+
net-smtp (0.5.1)
|
|
47
50
|
net-protocol
|
|
48
51
|
parallel (1.27.0)
|
|
49
|
-
parser (3.3.
|
|
52
|
+
parser (3.3.10.1)
|
|
50
53
|
ast (~> 2.4.1)
|
|
51
54
|
racc
|
|
52
|
-
pp (0.6.
|
|
55
|
+
pp (0.6.3)
|
|
53
56
|
prettyprint
|
|
54
57
|
prettyprint (0.2.0)
|
|
55
|
-
prism (1.
|
|
56
|
-
psych (5.
|
|
58
|
+
prism (1.9.0)
|
|
59
|
+
psych (5.3.1)
|
|
57
60
|
date
|
|
58
61
|
stringio
|
|
59
|
-
public_suffix (
|
|
62
|
+
public_suffix (7.0.2)
|
|
60
63
|
racc (1.8.1)
|
|
64
|
+
rack (3.2.4)
|
|
65
|
+
rackup (2.3.1)
|
|
66
|
+
rack (>= 3)
|
|
61
67
|
rainbow (3.1.1)
|
|
62
|
-
rake (13.
|
|
63
|
-
rdoc (
|
|
68
|
+
rake (13.3.1)
|
|
69
|
+
rdoc (7.1.0)
|
|
70
|
+
erb
|
|
64
71
|
psych (>= 4.0.0)
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
tsort
|
|
73
|
+
regexp_parser (2.11.3)
|
|
74
|
+
reline (0.6.3)
|
|
67
75
|
io-console (~> 0.5)
|
|
68
|
-
rexml (3.4.
|
|
69
|
-
rspec (3.13.
|
|
76
|
+
rexml (3.4.4)
|
|
77
|
+
rspec (3.13.2)
|
|
70
78
|
rspec-core (~> 3.13.0)
|
|
71
79
|
rspec-expectations (~> 3.13.0)
|
|
72
80
|
rspec-mocks (~> 3.13.0)
|
|
73
|
-
rspec-core (3.13.
|
|
81
|
+
rspec-core (3.13.6)
|
|
74
82
|
rspec-support (~> 3.13.0)
|
|
75
|
-
rspec-expectations (3.13.
|
|
83
|
+
rspec-expectations (3.13.5)
|
|
76
84
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
77
85
|
rspec-support (~> 3.13.0)
|
|
78
|
-
rspec-its (
|
|
79
|
-
rspec-core (>= 3.
|
|
80
|
-
rspec-expectations (>= 3.
|
|
81
|
-
rspec-mocks (3.13.
|
|
86
|
+
rspec-its (2.0.0)
|
|
87
|
+
rspec-core (>= 3.13.0)
|
|
88
|
+
rspec-expectations (>= 3.13.0)
|
|
89
|
+
rspec-mocks (3.13.7)
|
|
82
90
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
83
91
|
rspec-support (~> 3.13.0)
|
|
84
|
-
rspec-support (3.13.
|
|
85
|
-
rubocop (1.
|
|
92
|
+
rspec-support (3.13.6)
|
|
93
|
+
rubocop (1.84.0)
|
|
86
94
|
json (~> 2.3)
|
|
87
95
|
language_server-protocol (~> 3.17.0.2)
|
|
88
96
|
lint_roller (~> 1.1.0)
|
|
@@ -90,29 +98,33 @@ GEM
|
|
|
90
98
|
parser (>= 3.3.0.2)
|
|
91
99
|
rainbow (>= 2.2.2, < 4.0)
|
|
92
100
|
regexp_parser (>= 2.9.3, < 3.0)
|
|
93
|
-
rubocop-ast (>= 1.
|
|
101
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
94
102
|
ruby-progressbar (~> 1.7)
|
|
95
103
|
unicode-display_width (>= 2.4.0, < 4.0)
|
|
96
|
-
rubocop-ast (1.
|
|
104
|
+
rubocop-ast (1.49.0)
|
|
97
105
|
parser (>= 3.3.7.2)
|
|
98
|
-
prism (~> 1.
|
|
99
|
-
rubocop-rake (0.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
106
|
+
prism (~> 1.7)
|
|
107
|
+
rubocop-rake (0.7.1)
|
|
108
|
+
lint_roller (~> 1.1)
|
|
109
|
+
rubocop (>= 1.72.1)
|
|
110
|
+
rubocop-rspec (3.9.0)
|
|
111
|
+
lint_roller (~> 1.1)
|
|
112
|
+
rubocop (~> 1.81)
|
|
103
113
|
ruby-progressbar (1.13.0)
|
|
104
|
-
stringio (3.
|
|
105
|
-
thor (1.
|
|
106
|
-
timeout (0.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
stringio (3.2.0)
|
|
115
|
+
thor (1.5.0)
|
|
116
|
+
timeout (0.6.0)
|
|
117
|
+
tsort (0.2.0)
|
|
118
|
+
unicode-display_width (3.2.0)
|
|
119
|
+
unicode-emoji (~> 4.1)
|
|
120
|
+
unicode-emoji (4.2.0)
|
|
121
|
+
vcr (6.4.0)
|
|
122
|
+
webmock (3.26.1)
|
|
112
123
|
addressable (>= 2.8.0)
|
|
113
124
|
crack (>= 0.3.2)
|
|
114
125
|
hashdiff (>= 0.4.0, < 2.0.0)
|
|
115
|
-
|
|
126
|
+
webrick (1.9.2)
|
|
127
|
+
yard (0.9.38)
|
|
116
128
|
|
|
117
129
|
PLATFORMS
|
|
118
130
|
ruby
|
|
@@ -123,15 +135,18 @@ DEPENDENCIES
|
|
|
123
135
|
mail
|
|
124
136
|
mailtrap!
|
|
125
137
|
net-smtp
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
138
|
+
rack
|
|
139
|
+
rackup
|
|
140
|
+
rake (~> 13.3)
|
|
141
|
+
rdoc (~> 7.1.0)
|
|
142
|
+
rspec (~> 3)
|
|
129
143
|
rspec-its
|
|
130
|
-
rubocop (~> 1.
|
|
144
|
+
rubocop (~> 1.82)
|
|
131
145
|
rubocop-rake
|
|
132
146
|
rubocop-rspec
|
|
133
147
|
vcr
|
|
134
148
|
webmock
|
|
149
|
+
webrick
|
|
135
150
|
yard (~> 0.9)
|
|
136
151
|
|
|
137
152
|
BUNDLED WITH
|
data/README.md
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
+
# Mailtrap Ruby client - Official
|
|
2
|
+
|
|
3
|
+

|
|
1
4
|
[](https://github.com/mailtrap/mailtrap-ruby/actions/workflows/main.yml)
|
|
2
5
|
[](https://rubydoc.info/gems/mailtrap)
|
|
3
6
|
[](https://rubygems.org/gems/mailtrap)
|
|
4
7
|
[](https://rubygems.org/gems/mailtrap)
|
|
5
8
|
|
|
9
|
+
This client uses API v2, for v1 refer to [this documentation](https://mailtrap.docs.apiary.io/)
|
|
6
10
|
|
|
7
11
|
|
|
8
|
-
|
|
12
|
+
## Prerequisites
|
|
9
13
|
|
|
10
|
-
|
|
14
|
+
To get the most out of this official Mailtrap.io Ruby SDK:
|
|
11
15
|
|
|
12
|
-
|
|
16
|
+
- [Create a Mailtrap account](https://mailtrap.io/signup)
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
- [Verify your domain](https://mailtrap.io/sending/domains)
|
|
15
19
|
|
|
16
20
|
## Installation
|
|
17
21
|
|
|
@@ -105,31 +109,27 @@ client.send_batch(
|
|
|
105
109
|
)
|
|
106
110
|
```
|
|
107
111
|
|
|
108
|
-
###
|
|
112
|
+
### Sandbox Sending
|
|
113
|
+
|
|
114
|
+
Send emails to your Sandbox for testing purposes:
|
|
109
115
|
|
|
110
116
|
```ruby
|
|
111
117
|
require 'mailtrap'
|
|
112
118
|
|
|
113
|
-
client = Mailtrap::Client.new(api_key: 'your-api-key')
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
client = Mailtrap::Client.new(api_key: 'your-api-key', sandbox: true, inbox_id: YOUR_INBOX_ID)
|
|
120
|
+
client.send(mail)
|
|
121
|
+
|
|
122
|
+
# You can also pass the request parameters directly
|
|
123
|
+
client.send(
|
|
124
|
+
from: { email: 'mailtrap@example.com', name: 'Mailtrap Test' },
|
|
125
|
+
to: [
|
|
126
|
+
{ email: 'your@email.com' }
|
|
127
|
+
],
|
|
128
|
+
subject: 'You are awesome!',
|
|
129
|
+
text: 'Congrats for sending test email with Mailtrap!'
|
|
122
130
|
)
|
|
123
131
|
```
|
|
124
132
|
|
|
125
|
-
Refer to the [`examples`](examples) folder for more examples:
|
|
126
|
-
|
|
127
|
-
- [Full](examples/full.rb)
|
|
128
|
-
- [Email template](examples/email_template.rb)
|
|
129
|
-
- [Batch Sending](examples/batch.rb)
|
|
130
|
-
- [ActionMailer](examples/action_mailer.rb)
|
|
131
|
-
- [Email Templates API](examples/email_templates_api.rb)
|
|
132
|
-
|
|
133
133
|
### Content-Transfer-Encoding
|
|
134
134
|
|
|
135
135
|
`mailtrap` gem uses Mailtrap API to send emails. Mailtrap API does not try to
|
|
@@ -148,7 +148,7 @@ configuration example.
|
|
|
148
148
|
|
|
149
149
|
You can configure two Mailtrap clients to operate simultaneously. This setup is
|
|
150
150
|
particularly useful when you need to send emails using both the transactional
|
|
151
|
-
and bulk APIs. Refer to the configuration
|
|
151
|
+
and bulk APIs. Refer to the configuration examples below.
|
|
152
152
|
|
|
153
153
|
```ruby
|
|
154
154
|
# config/application.rb
|
|
@@ -168,26 +168,72 @@ config.action_mailer.mailtrap_bulk_settings = {
|
|
|
168
168
|
mail(delivery_method: :mailtrap_bulk)
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
+
## Supported functionality & Examples
|
|
172
|
+
|
|
173
|
+
Refer to the [`examples`](examples) folder for more examples:
|
|
174
|
+
|
|
175
|
+
Email API:
|
|
176
|
+
|
|
177
|
+
- Full Email Sending – [`full.rb`](examples/full.rb)
|
|
178
|
+
- Batch Sending – [`batch.rb`](examples/batch.rb)
|
|
179
|
+
- Sending Domains API – [`sending_domains_api.rb`](examples/sending_domains_api.rb)
|
|
180
|
+
|
|
181
|
+
Email Sandbox (Testing):
|
|
182
|
+
|
|
183
|
+
- Projects CRUD – [`projects_api.rb`](examples/projects_api.rb)
|
|
184
|
+
- Inboxes CRUD - [`inboxes_api.rb`](examples/inboxes_api.rb)
|
|
185
|
+
- Sandbox Messages CRUD - [`sandbox_messages_api.rb`](examples/sandbox_messages_api.rb)
|
|
186
|
+
- Sandbox Attachments API - [`sandbox_attachments_api.rb`](examples/sandbox_attachments_api.rb)
|
|
187
|
+
|
|
188
|
+
Contact management:
|
|
189
|
+
|
|
190
|
+
- Contacts CRUD & Listing – [`contacts_api.rb`](examples/contacts_api.rb)
|
|
191
|
+
|
|
192
|
+
General:
|
|
193
|
+
|
|
194
|
+
- Templates CRUD – [`email_templates_api.rb`](examples/email_templates_api.rb)
|
|
195
|
+
- Action Mailer – [`action_mailer.rb`](examples/action_mailer.rb)
|
|
196
|
+
- Accounts API – [`accounts_api.rb`](examples/accounts_api.rb)
|
|
197
|
+
|
|
171
198
|
## Migration guide v1 → v2
|
|
172
199
|
|
|
173
200
|
Change `Mailtrap::Sending::Client` to `Mailtrap::Client`.
|
|
174
201
|
|
|
175
202
|
If you use classes which have `Sending` namespace, remove the namespace like in the example above.
|
|
176
203
|
|
|
204
|
+
## Contributing
|
|
205
|
+
|
|
206
|
+
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).
|
|
207
|
+
|
|
177
208
|
## Development
|
|
178
209
|
|
|
179
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
210
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
211
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
|
212
|
+
prompt that will allow you to experiment.
|
|
180
213
|
|
|
181
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
|
214
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
|
182
215
|
|
|
183
|
-
|
|
216
|
+
To release a new version, update the version number in `version.rb`, and then
|
|
217
|
+
run `bundle exec rake release`, which will create a git tag for the version,
|
|
218
|
+
push git commits and the created tag, and push the `.gem` file to
|
|
219
|
+
[rubygems.org](https://rubygems.org).
|
|
184
220
|
|
|
185
|
-
|
|
221
|
+
To run the documentation server, first generate the documentation with
|
|
222
|
+
`yard doc`, then run `yard server`.
|
|
223
|
+
|
|
224
|
+
All contributions are required to have rspec tests covering its functionality.
|
|
225
|
+
|
|
226
|
+
Please be sure to update [README](README.md) with new examples and features
|
|
227
|
+
when applicable.
|
|
186
228
|
|
|
187
229
|
## License
|
|
188
230
|
|
|
189
|
-
The
|
|
231
|
+
The package is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
190
232
|
|
|
191
233
|
## Code of Conduct
|
|
192
234
|
|
|
193
|
-
Everyone interacting in the Mailtrap project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
|
|
235
|
+
Everyone interacting in the Mailtrap project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
|
|
236
|
+
|
|
237
|
+
## Compatibility with previous releases
|
|
238
|
+
|
|
239
|
+
Versions of this package up to 2.0.2 were an [unofficial client](https://github.com/vchin/mailtrap-client) developed by [@vchin](https://github.com/vchin). Package version 3 is a completely new package.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mailtrap
|
|
4
|
+
# Data Transfer Object for Account
|
|
5
|
+
# @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/d26921ca2a48f-get-all-accounts
|
|
6
|
+
# @attr_reader id [Integer] The account ID
|
|
7
|
+
# @attr_reader name [String] The account name
|
|
8
|
+
# @attr_reader access_levels [Array] The account access levels
|
|
9
|
+
#
|
|
10
|
+
Account = Struct.new(
|
|
11
|
+
:id,
|
|
12
|
+
:name,
|
|
13
|
+
:access_levels,
|
|
14
|
+
keyword_init: true
|
|
15
|
+
)
|
|
16
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base_api'
|
|
4
|
+
require_relative 'account'
|
|
5
|
+
|
|
6
|
+
module Mailtrap
|
|
7
|
+
class AccountsAPI
|
|
8
|
+
include BaseAPI
|
|
9
|
+
|
|
10
|
+
self.response_class = Account
|
|
11
|
+
|
|
12
|
+
attr_reader :client
|
|
13
|
+
|
|
14
|
+
# @param client [Mailtrap::Client] The client instance
|
|
15
|
+
# @raise [ArgumentError] If account_id is nil
|
|
16
|
+
def initialize(client = Mailtrap::Client.new)
|
|
17
|
+
@client = client
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Lists all accounts
|
|
21
|
+
# @return [Array<Account>] Array of accounts
|
|
22
|
+
# @!macro api_errors
|
|
23
|
+
def list
|
|
24
|
+
base_list
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def base_path
|
|
30
|
+
'/api/accounts'
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
data/lib/mailtrap/client.rb
CHANGED
|
@@ -115,7 +115,7 @@ module Mailtrap
|
|
|
115
115
|
# )
|
|
116
116
|
# @param base [#to_json] The base email configuration for the batch.
|
|
117
117
|
# @param requests [Array<#to_json>] Array of individual email requests.
|
|
118
|
-
# @return [Hash]
|
|
118
|
+
# @return [Hash, String, nil] JSON response or raw response body from the API.
|
|
119
119
|
# @!macro api_errors
|
|
120
120
|
# @raise [Mailtrap::MailSizeError] If the message is too large.
|
|
121
121
|
def send_batch(base, requests)
|
|
@@ -153,7 +153,7 @@ module Mailtrap
|
|
|
153
153
|
# text: 'Congrats for sending test email with Mailtrap!'
|
|
154
154
|
# )
|
|
155
155
|
# @param mail [#to_json] The email to send
|
|
156
|
-
# @return [Hash]
|
|
156
|
+
# @return [Hash, String, nil] JSON response or raw response body
|
|
157
157
|
# @!macro api_errors
|
|
158
158
|
# @raise [Mailtrap::MailSizeError] If the message is too large
|
|
159
159
|
def send(mail)
|
|
@@ -168,7 +168,7 @@ module Mailtrap
|
|
|
168
168
|
# Performs a GET request to the specified path
|
|
169
169
|
# @param path [String] The request path
|
|
170
170
|
# @param query_params [Hash] Query parameters to append to the URL (optional)
|
|
171
|
-
# @return [Hash, nil]
|
|
171
|
+
# @return [Hash, String, nil] JSON response or raw response body
|
|
172
172
|
# @!macro api_errors
|
|
173
173
|
def get(path, query_params = {})
|
|
174
174
|
perform_request(
|
|
@@ -182,7 +182,7 @@ module Mailtrap
|
|
|
182
182
|
# Performs a POST request to the specified path
|
|
183
183
|
# @param path [String] The request path
|
|
184
184
|
# @param body [Hash] The request body
|
|
185
|
-
# @return [Hash, nil]
|
|
185
|
+
# @return [Hash, String, nil] JSON response or raw response body
|
|
186
186
|
# @!macro api_errors
|
|
187
187
|
def post(path, body = nil)
|
|
188
188
|
perform_request(
|
|
@@ -196,7 +196,7 @@ module Mailtrap
|
|
|
196
196
|
# Performs a PATCH request to the specified path
|
|
197
197
|
# @param path [String] The request path
|
|
198
198
|
# @param body [Hash] The request body
|
|
199
|
-
# @return [Hash, nil]
|
|
199
|
+
# @return [Hash, String, nil] JSON response or raw response body
|
|
200
200
|
# @!macro api_errors
|
|
201
201
|
def patch(path, body = nil)
|
|
202
202
|
perform_request(
|
|
@@ -209,7 +209,7 @@ module Mailtrap
|
|
|
209
209
|
|
|
210
210
|
# Performs a DELETE request to the specified path
|
|
211
211
|
# @param path [String] The request path
|
|
212
|
-
# @return [Hash, nil]
|
|
212
|
+
# @return [Hash, String, nil] JSON response or raw response body
|
|
213
213
|
# @!macro api_errors
|
|
214
214
|
def delete(path)
|
|
215
215
|
perform_request(
|
|
@@ -221,8 +221,11 @@ module Mailtrap
|
|
|
221
221
|
|
|
222
222
|
private
|
|
223
223
|
|
|
224
|
-
def
|
|
225
|
-
|
|
224
|
+
def validate_args!(api_key, api_port, bulk, sandbox, inbox_id)
|
|
225
|
+
raise ArgumentError, 'api_key is required' if api_key.nil?
|
|
226
|
+
raise ArgumentError, 'api_port is required' if api_port.nil?
|
|
227
|
+
raise ArgumentError, 'bulk stream is not applicable for sandbox API' if bulk && sandbox
|
|
228
|
+
raise ArgumentError, 'inbox_id is required for sandbox API' if sandbox && inbox_id.nil?
|
|
226
229
|
end
|
|
227
230
|
|
|
228
231
|
def select_api_host(bulk:, sandbox:)
|
|
@@ -235,14 +238,6 @@ module Mailtrap
|
|
|
235
238
|
end
|
|
236
239
|
end
|
|
237
240
|
|
|
238
|
-
def send_path
|
|
239
|
-
"/api/send#{"/#{inbox_id}" if sandbox}"
|
|
240
|
-
end
|
|
241
|
-
|
|
242
|
-
def batch_request_path
|
|
243
|
-
"/api/batch#{"/#{inbox_id}" if sandbox}"
|
|
244
|
-
end
|
|
245
|
-
|
|
246
241
|
def perform_request(method:, host:, path:, query_params: {}, body: nil)
|
|
247
242
|
http_client = http_client_for(host)
|
|
248
243
|
|
|
@@ -254,6 +249,10 @@ module Mailtrap
|
|
|
254
249
|
handle_response(response)
|
|
255
250
|
end
|
|
256
251
|
|
|
252
|
+
def http_client_for(host)
|
|
253
|
+
@http_clients[host] ||= Net::HTTP.new(host, api_port).tap { |client| client.use_ssl = true }
|
|
254
|
+
end
|
|
255
|
+
|
|
257
256
|
def setup_request(method, uri_or_path, body = nil)
|
|
258
257
|
request = case method
|
|
259
258
|
when :get
|
|
@@ -279,17 +278,17 @@ module Mailtrap
|
|
|
279
278
|
def handle_response(response) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
|
|
280
279
|
case response
|
|
281
280
|
when Net::HTTPOK, Net::HTTPCreated
|
|
282
|
-
|
|
281
|
+
parse_response(response)
|
|
283
282
|
when Net::HTTPNoContent
|
|
284
283
|
nil
|
|
285
284
|
when Net::HTTPBadRequest
|
|
286
285
|
raise Mailtrap::Error, ['bad request'] if response.body.empty?
|
|
287
286
|
|
|
288
|
-
raise Mailtrap::Error, response_errors(response
|
|
287
|
+
raise Mailtrap::Error, response_errors(response)
|
|
289
288
|
when Net::HTTPUnauthorized
|
|
290
|
-
raise Mailtrap::AuthorizationError, response_errors(response
|
|
289
|
+
raise Mailtrap::AuthorizationError, response_errors(response)
|
|
291
290
|
when Net::HTTPForbidden
|
|
292
|
-
raise Mailtrap::RejectionError, response_errors(response
|
|
291
|
+
raise Mailtrap::RejectionError, response_errors(response)
|
|
293
292
|
when Net::HTTPPayloadTooLarge
|
|
294
293
|
raise Mailtrap::MailSizeError, ['message too large']
|
|
295
294
|
when Net::HTTPTooManyRequests
|
|
@@ -303,20 +302,37 @@ module Mailtrap
|
|
|
303
302
|
end
|
|
304
303
|
end
|
|
305
304
|
|
|
306
|
-
def
|
|
307
|
-
|
|
308
|
-
|
|
305
|
+
def parse_response(response)
|
|
306
|
+
if json_response?(response)
|
|
307
|
+
json_response(response.body)
|
|
308
|
+
else
|
|
309
|
+
response.body
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
def response_errors(response)
|
|
314
|
+
if json_response?(response)
|
|
315
|
+
parsed_body = json_response(response.body)
|
|
316
|
+
Array(parsed_body[:errors] || parsed_body[:error])
|
|
317
|
+
else
|
|
318
|
+
[response.body]
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
def json_response?(response)
|
|
323
|
+
response.content_type == 'application/json'
|
|
309
324
|
end
|
|
310
325
|
|
|
311
326
|
def json_response(body)
|
|
312
327
|
JSON.parse(body, symbolize_names: true)
|
|
313
328
|
end
|
|
314
329
|
|
|
315
|
-
def
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
330
|
+
def send_path
|
|
331
|
+
"/api/send#{"/#{inbox_id}" if sandbox}"
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
def batch_request_path
|
|
335
|
+
"/api/batch#{"/#{inbox_id}" if sandbox}"
|
|
320
336
|
end
|
|
321
337
|
end
|
|
322
338
|
end
|
data/lib/mailtrap/contact.rb
CHANGED
|
@@ -9,10 +9,5 @@ module Mailtrap
|
|
|
9
9
|
# Allowed values: text, integer, float, boolean, date
|
|
10
10
|
# @attr_reader merge_tag [String] Personalize your campaigns by adding a merge tag.
|
|
11
11
|
# This field will be replaced with unique contact details for each recipient (max 80 characters)
|
|
12
|
-
ContactField = Struct.new(:id, :name, :data_type, :merge_tag, keyword_init: true)
|
|
13
|
-
# @return [Hash] The contact field attributes as a hash
|
|
14
|
-
def to_h
|
|
15
|
-
super.compact
|
|
16
|
-
end
|
|
17
|
-
end
|
|
12
|
+
ContactField = Struct.new(:id, :name, :data_type, :merge_tag, keyword_init: true)
|
|
18
13
|
end
|