mailtrap 2.5.0 → 2.6.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: 7cfe51fc46a03cac98509b38611a60c5c7280c96055346d557590e3a59a17de9
4
- data.tar.gz: 5a8acfa518abf2903105f4a2a2df8d850532419e961372078ea0bd691ea898e2
3
+ metadata.gz: 38c84a79ba87b360caf02839703e51e1e1af2cb84092e03b995677805dd09c16
4
+ data.tar.gz: 2a6e502ff5876367d35ecc5907d4aaa3fd32689f342d6e91c3f54dd189cdcaea
5
5
  SHA512:
6
- metadata.gz: f0381884cc8e03c59523f87b2e4ec35872ddf514b135e9e5f72ce6d6752d37ae531dc8a91b40c8ed3b2a66f4b4e1cc1dbac95638dd94382a625145b24271d0d9
7
- data.tar.gz: 54da492c1a517820087101305e0efbfa07b5e4a6a297aba561bfe778504984cca563e45da710dc0df520d0890e80e8c58446408eac4e2c1eae6d035ed9b05083
6
+ metadata.gz: 927ef7bb197ea1636462a5e926eb273d8703e383ddee5e66b578252cb6d51cc7cb1e2afba194c70186980d67d32488cf3115c529146a6fedb02a8a5b4f0ae699
7
+ data.tar.gz: abcba3b12d50ae4b292c6fcdfd5e4b1786dafbfe02dfbe20528662dd3f2fc12b6fd2b14bd53b7ab09082a51a006e58003c9d8a989616cc5827d14ee89263c32f
data/.rubocop.yml CHANGED
@@ -1,4 +1,4 @@
1
- require:
1
+ plugins:
2
2
  - rubocop-rake
3
3
  - rubocop-rspec
4
4
 
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## [2.6.0] - 2026-01-27
2
+ - Add Inboxes API
3
+ - Add Projects API
4
+ - Models' `to_h` now returns all fields without compacting
5
+
1
6
  ## [2.5.0] - 2025-11-10
2
7
  - Add Contact Imports API
3
8
  - Add Suppressions API
data/Gemfile CHANGED
@@ -8,11 +8,11 @@ gem 'appraisal'
8
8
  gem 'irb'
9
9
  gem 'mail'
10
10
  gem 'net-smtp'
11
- gem 'rake', '~> 13.0'
12
- gem 'rdoc', '~> 6.13.0'
13
- gem 'rspec', '~> 3.0'
11
+ gem 'rake', '~> 13.3'
12
+ gem 'rdoc', '~> 7.1.0'
13
+ gem 'rspec', '~> 3'
14
14
  gem 'rspec-its'
15
- gem 'rubocop', '~> 1.21'
15
+ gem 'rubocop', '~> 1.82'
16
16
  gem 'rubocop-rake', require: false
17
17
  gem 'rubocop-rspec', require: false
18
18
  gem 'vcr'
data/Gemfile.lock CHANGED
@@ -1,88 +1,93 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mailtrap (2.5.0)
4
+ mailtrap (2.6.0)
5
5
  base64
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- addressable (2.8.7)
11
- public_suffix (>= 2.0.2, < 7.0)
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 (3.1.8)
19
- crack (1.0.0)
18
+ bigdecimal (4.0.1)
19
+ crack (1.0.1)
20
20
  bigdecimal
21
21
  rexml
22
- date (3.4.1)
23
- diff-lcs (1.5.1)
24
- hashdiff (1.1.0)
25
- io-console (0.8.0)
26
- irb (1.15.2)
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.12.2)
31
+ json (2.18.0)
31
32
  language_server-protocol (3.17.0.5)
32
33
  lint_roller (1.1.0)
33
- mail (2.8.1)
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.5.7)
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.0)
49
+ net-smtp (0.5.1)
47
50
  net-protocol
48
51
  parallel (1.27.0)
49
- parser (3.3.8.0)
52
+ parser (3.3.10.1)
50
53
  ast (~> 2.4.1)
51
54
  racc
52
- pp (0.6.2)
55
+ pp (0.6.3)
53
56
  prettyprint
54
57
  prettyprint (0.2.0)
55
- prism (1.4.0)
56
- psych (5.2.6)
58
+ prism (1.9.0)
59
+ psych (5.3.1)
57
60
  date
58
61
  stringio
59
- public_suffix (5.1.1)
62
+ public_suffix (7.0.2)
60
63
  racc (1.8.1)
61
64
  rainbow (3.1.1)
62
- rake (13.2.1)
63
- rdoc (6.13.1)
65
+ rake (13.3.1)
66
+ rdoc (7.1.0)
67
+ erb
64
68
  psych (>= 4.0.0)
65
- regexp_parser (2.10.0)
66
- reline (0.6.1)
69
+ tsort
70
+ regexp_parser (2.11.3)
71
+ reline (0.6.3)
67
72
  io-console (~> 0.5)
68
- rexml (3.4.2)
69
- rspec (3.13.0)
73
+ rexml (3.4.4)
74
+ rspec (3.13.2)
70
75
  rspec-core (~> 3.13.0)
71
76
  rspec-expectations (~> 3.13.0)
72
77
  rspec-mocks (~> 3.13.0)
73
- rspec-core (3.13.0)
78
+ rspec-core (3.13.6)
74
79
  rspec-support (~> 3.13.0)
75
- rspec-expectations (3.13.1)
80
+ rspec-expectations (3.13.5)
76
81
  diff-lcs (>= 1.2.0, < 2.0)
77
82
  rspec-support (~> 3.13.0)
78
- rspec-its (1.3.0)
79
- rspec-core (>= 3.0.0)
80
- rspec-expectations (>= 3.0.0)
81
- rspec-mocks (3.13.1)
83
+ rspec-its (2.0.0)
84
+ rspec-core (>= 3.13.0)
85
+ rspec-expectations (>= 3.13.0)
86
+ rspec-mocks (3.13.7)
82
87
  diff-lcs (>= 1.2.0, < 2.0)
83
88
  rspec-support (~> 3.13.0)
84
- rspec-support (3.13.1)
85
- rubocop (1.78.0)
89
+ rspec-support (3.13.6)
90
+ rubocop (1.84.0)
86
91
  json (~> 2.3)
87
92
  language_server-protocol (~> 3.17.0.2)
88
93
  lint_roller (~> 1.1.0)
@@ -90,29 +95,32 @@ GEM
90
95
  parser (>= 3.3.0.2)
91
96
  rainbow (>= 2.2.2, < 4.0)
92
97
  regexp_parser (>= 2.9.3, < 3.0)
93
- rubocop-ast (>= 1.45.1, < 2.0)
98
+ rubocop-ast (>= 1.49.0, < 2.0)
94
99
  ruby-progressbar (~> 1.7)
95
100
  unicode-display_width (>= 2.4.0, < 4.0)
96
- rubocop-ast (1.45.1)
101
+ rubocop-ast (1.49.0)
97
102
  parser (>= 3.3.7.2)
98
- prism (~> 1.4)
99
- rubocop-rake (0.6.0)
100
- rubocop (~> 1.0)
101
- rubocop-rspec (3.0.2)
102
- rubocop (~> 1.61)
103
+ prism (~> 1.7)
104
+ rubocop-rake (0.7.1)
105
+ lint_roller (~> 1.1)
106
+ rubocop (>= 1.72.1)
107
+ rubocop-rspec (3.9.0)
108
+ lint_roller (~> 1.1)
109
+ rubocop (~> 1.81)
103
110
  ruby-progressbar (1.13.0)
104
- stringio (3.1.7)
105
- thor (1.4.0)
106
- timeout (0.4.3)
107
- unicode-display_width (3.1.4)
108
- unicode-emoji (~> 4.0, >= 4.0.4)
109
- unicode-emoji (4.0.4)
110
- vcr (6.2.0)
111
- webmock (3.23.1)
111
+ stringio (3.2.0)
112
+ thor (1.5.0)
113
+ timeout (0.6.0)
114
+ tsort (0.2.0)
115
+ unicode-display_width (3.2.0)
116
+ unicode-emoji (~> 4.1)
117
+ unicode-emoji (4.2.0)
118
+ vcr (6.4.0)
119
+ webmock (3.26.1)
112
120
  addressable (>= 2.8.0)
113
121
  crack (>= 0.3.2)
114
122
  hashdiff (>= 0.4.0, < 2.0.0)
115
- yard (0.9.37)
123
+ yard (0.9.38)
116
124
 
117
125
  PLATFORMS
118
126
  ruby
@@ -123,11 +131,11 @@ DEPENDENCIES
123
131
  mail
124
132
  mailtrap!
125
133
  net-smtp
126
- rake (~> 13.0)
127
- rdoc (~> 6.13.0)
128
- rspec (~> 3.0)
134
+ rake (~> 13.3)
135
+ rdoc (~> 7.1.0)
136
+ rspec (~> 3)
129
137
  rspec-its
130
- rubocop (~> 1.21)
138
+ rubocop (~> 1.82)
131
139
  rubocop-rake
132
140
  rubocop-rspec
133
141
  vcr
data/README.md CHANGED
@@ -1,17 +1,21 @@
1
+ # Mailtrap Ruby client - Official
2
+
3
+ ![Ruby](https://img.shields.io/badge/Ruby-CC342D)
1
4
  [![test](https://github.com/mailtrap/mailtrap-ruby/actions/workflows/main.yml/badge.svg)](https://github.com/mailtrap/mailtrap-ruby/actions/workflows/main.yml)
2
5
  [![docs](https://shields.io/badge/docs-rubydoc.info-blue)](https://rubydoc.info/gems/mailtrap)
3
6
  [![gem](https://shields.io/gem/v/mailtrap)](https://rubygems.org/gems/mailtrap)
4
7
  [![downloads](https://shields.io/gem/dt/mailtrap)](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
- # Official Mailtrap Ruby client
12
+ ## Prerequisites
9
13
 
10
- This Ruby gem offers integration with the [official API](https://api-docs.mailtrap.io/) for [Mailtrap](https://mailtrap.io).
14
+ To get the most out of this official Mailtrap.io Ruby SDK:
11
15
 
12
- Quickly add email sending functionality to your Ruby application with Mailtrap.
16
+ - [Create a Mailtrap account](https://mailtrap.io/signup)
13
17
 
14
- (This client uses API v2, for v1 refer to [this documentation](https://mailtrap.docs.apiary.io/))
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
- ### Email Templates API
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
- templates = Mailtrap::EmailTemplatesAPI.new 3229, client
115
-
116
- templates.create(
117
- name: 'Welcome Email',
118
- subject: 'Welcome to Mailtrap!',
119
- body_html: '<h1>Hello</h1>',
120
- body_text: 'Hello',
121
- category: 'welcome'
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 example below:
151
+ and bulk APIs. Refer to the configuration examples below.
152
152
 
153
153
  ```ruby
154
154
  # config/application.rb
@@ -168,26 +168,60 @@ 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
+ - Full email sending – [`full.rb`](examples/full.rb)
177
+
178
+ - Batch sending – [`batch.rb`](examples/batch.rb)
179
+
180
+ Email Sandbox (Testing):
181
+
182
+ - Projects CRUD – [`projects_api.rb`](examples/projects_api.rb)
183
+ - Inboxes CRUD - [`inboxes_api.rb`](examples/inboxes_api.rb)
184
+
185
+ Contact management:
186
+
187
+ - Contacts CRUD & listing – [`contacts_api.rb`](examples/contacts_api.rb)
188
+
189
+ General API:
190
+
191
+ - Templates CRUD – [`email_templates_api.rb`](examples/email_templates_api.rb)
192
+
193
+ - Action Mailer – [`action_mailer.rb`](examples/action_mailer.rb)
194
+
171
195
  ## Migration guide v1 → v2
172
196
 
173
197
  Change `Mailtrap::Sending::Client` to `Mailtrap::Client`.
174
198
 
175
199
  If you use classes which have `Sending` namespace, remove the namespace like in the example above.
176
200
 
201
+ ## Contributing
202
+
203
+ 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).
204
+
177
205
  ## Development
178
206
 
179
207
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
180
208
 
181
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
209
+ To install this gem onto your local machine, run `bundle exec rake install`.
182
210
 
183
- ## Contributing
211
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
212
+
213
+ All contributions are required to have rspec tests covering its functionality.
184
214
 
185
- Bug reports and pull requests are welcome on [GitHub](https://github.com/mailtrap/mailtrap-ruby). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
215
+ Please be sure to update [README](README.md) with new examples and features when applicable.
186
216
 
187
217
  ## License
188
218
 
189
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
219
+ The package is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
190
220
 
191
221
  ## Code of Conduct
192
222
 
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).
223
+ 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).
224
+
225
+ ## Compatibility with previous releases
226
+
227
+ 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.
@@ -29,10 +29,5 @@ module Mailtrap
29
29
  def newly_created?
30
30
  @action != 'updated'
31
31
  end
32
-
33
- # @return [Hash] The contact attributes as a hash
34
- def to_h
35
- super.compact
36
- end
37
32
  end
38
33
  end
@@ -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) do
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
@@ -14,10 +14,5 @@ module Mailtrap
14
14
  :updated_contacts_count,
15
15
  :contacts_over_limit_count,
16
16
  keyword_init: true
17
- ) do
18
- # @return [Hash] The contact attributes as a hash
19
- def to_h
20
- super.compact
21
- end
22
- end
17
+ )
23
18
  end
@@ -5,10 +5,5 @@ module Mailtrap
5
5
  # @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/6ec7a37234af2-contact-list
6
6
  # @attr_reader id [Integer] The contact list ID
7
7
  # @attr_reader name [String] The name of the contact list
8
- ContactList = Struct.new(:id, :name, keyword_init: true) do
9
- # @return [Hash] The contact list attributes as a hash
10
- def to_h
11
- super.compact
12
- end
13
- end
8
+ ContactList = Struct.new(:id, :name, keyword_init: true)
14
9
  end
@@ -26,10 +26,5 @@ module Mailtrap
26
26
  :created_at,
27
27
  :updated_at,
28
28
  keyword_init: true
29
- ) do
30
- # @return [Hash] The template attributes as a hash
31
- def to_h
32
- super.compact
33
- end
34
- end
29
+ )
35
30
  end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailtrap
4
+ # Data Transfer Object for Inbox
5
+ # @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/ee252e413d78a-create-project
6
+ # @attr_reader id [Integer] The inbox ID
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
+ )
57
+ end
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_api'
4
+ require_relative 'inbox'
5
+
6
+ module Mailtrap
7
+ class InboxesAPI
8
+ include BaseAPI
9
+
10
+ self.supported_options = %i[name]
11
+ self.response_class = Inbox
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
+ private
89
+
90
+ def wrap_request(options)
91
+ { inbox: options }
92
+ end
93
+
94
+ def base_path
95
+ "/api/accounts/#{account_id}/inboxes"
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mailtrap
4
+ # Data Transfer Object for Project
5
+ # @see https://api-docs.mailtrap.io/docs/mailtrap-api-docs/ee252e413d78a-create-project
6
+ # @attr_reader id [Integer] The project ID
7
+ # @attr_reader name [String] The project name
8
+ # @attr_reader share_links [Hash] Admin and viewer share links
9
+ # @attr_reader inboxes [Array<Mailtrap::Inbox>] Array of inboxes
10
+ # @attr_reader permissions [Hash] List of permissions
11
+ #
12
+ Project = Struct.new(
13
+ :id,
14
+ :name,
15
+ :share_links,
16
+ :inboxes,
17
+ :permissions,
18
+ keyword_init: true
19
+ )
20
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base_api'
4
+ require_relative 'project'
5
+ require_relative 'inbox'
6
+
7
+ module Mailtrap
8
+ class ProjectsAPI
9
+ include BaseAPI
10
+
11
+ self.supported_options = %i[name]
12
+
13
+ self.response_class = Project
14
+
15
+ # Lists all projects for the account
16
+ # @return [Array<Project>] Array of projects
17
+ # @!macro api_errors
18
+ def list
19
+ base_list
20
+ end
21
+
22
+ # Retrieves a specific project
23
+ # @param project_id [Integer] The project ID
24
+ # @return [Project] Project object
25
+ # @!macro api_errors
26
+ def get(project_id)
27
+ base_get(project_id)
28
+ end
29
+
30
+ # Creates a new project
31
+ # @param [Hash] options The parameters to create
32
+ # @option options [String] :name The project name
33
+ # @return [Project] Created project object
34
+ # @!macro api_errors
35
+ # @raise [ArgumentError] If invalid options are provided
36
+ def create(options)
37
+ base_create(options)
38
+ end
39
+
40
+ # Updates an existing project
41
+ # @param project_id [Integer] The project ID
42
+ # @param [Hash] options The parameters to update
43
+ # @return [Project] Updated project object
44
+ # @!macro api_errors
45
+ # @raise [ArgumentError] If invalid options are provided
46
+ def update(project_id, options)
47
+ base_update(project_id, options)
48
+ end
49
+
50
+ # Deletes a project
51
+ # @param project_id [Integer] The project ID
52
+ # @return nil
53
+ # @!macro api_errors
54
+ def delete(project_id)
55
+ base_delete(project_id)
56
+ end
57
+
58
+ private
59
+
60
+ def handle_response(response)
61
+ build_entity(
62
+ response.merge(
63
+ inboxes: response[:inboxes]&.map { |inbox| build_entity(inbox, Mailtrap::Inbox) }
64
+ ),
65
+ response_class
66
+ )
67
+ end
68
+
69
+ def base_path
70
+ "/api/accounts/#{account_id}/projects"
71
+ end
72
+
73
+ def wrap_request(options)
74
+ { project: options }
75
+ end
76
+ end
77
+ end
@@ -37,10 +37,5 @@ module Mailtrap
37
37
  :message_sender_email,
38
38
  :message_subject,
39
39
  keyword_init: true
40
- ) do
41
- # @return [Hash] The suppression attributes as a hash
42
- def to_h
43
- super.compact
44
- end
45
- end
40
+ )
46
41
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mailtrap
4
- VERSION = '2.5.0'
4
+ VERSION = '2.6.0'
5
5
  end
data/lib/mailtrap.rb CHANGED
@@ -10,6 +10,8 @@ require_relative 'mailtrap/contact_lists_api'
10
10
  require_relative 'mailtrap/contact_fields_api'
11
11
  require_relative 'mailtrap/contact_imports_api'
12
12
  require_relative 'mailtrap/suppressions_api'
13
+ require_relative 'mailtrap/projects_api'
14
+ require_relative 'mailtrap/inboxes_api'
13
15
 
14
16
  module Mailtrap
15
17
  # @!macro api_errors
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailtrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Railsware Products Studio LLC
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-11-10 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: base64
@@ -59,9 +59,13 @@ files:
59
59
  - lib/mailtrap/email_template.rb
60
60
  - lib/mailtrap/email_templates_api.rb
61
61
  - lib/mailtrap/errors.rb
62
+ - lib/mailtrap/inbox.rb
63
+ - lib/mailtrap/inboxes_api.rb
62
64
  - lib/mailtrap/mail.rb
63
65
  - lib/mailtrap/mail/base.rb
64
66
  - lib/mailtrap/mail/from_template.rb
67
+ - lib/mailtrap/project.rb
68
+ - lib/mailtrap/projects_api.rb
65
69
  - lib/mailtrap/suppression.rb
66
70
  - lib/mailtrap/suppressions_api.rb
67
71
  - lib/mailtrap/version.rb
@@ -88,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
92
  - !ruby/object:Gem::Version
89
93
  version: '0'
90
94
  requirements: []
91
- rubygems_version: 3.6.2
95
+ rubygems_version: 3.6.9
92
96
  specification_version: 4
93
97
  summary: Official mailtrap.io API client
94
98
  test_files: []