mailslurp_client 8.2.2 → 8.2.4

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: 93232136e472641c4912032ba0ed4bc7f3c78ef341733304a196f3905e8cbd6b
4
- data.tar.gz: 10105fc33f340605cd60c26f8394cec9cdc3446866aff735ccd2d9111069d032
3
+ metadata.gz: 14c8172e82d0cc82bc46542483fb851b2777335c4eb54763a5468963faff7bd2
4
+ data.tar.gz: 8256fcef95c9dec144f7ab4b2e3e6ea16d624a3e19823f6d1f42b85b29510f02
5
5
  SHA512:
6
- metadata.gz: 2d13af2cffe00a7e7b1916e1e676a6a338e4559f9a1dc306212be8b026d60039afc03622ddd8e03096dff79988bb5adbd3f0b270274889521e19ee5f54e7edf0
7
- data.tar.gz: 102c0544b57ffd544cba06e9feadd9771470daa8c834aeebb8a3b6e17a21910d4497852a20e4c35985a17b5aa26fc2b39d5a7e3d6df4745c2d93afad766f38e3
6
+ metadata.gz: 8318ee26eb26b2851e543c5e1391da15b0222f11a914625ee064dbfd0f96cca44514a90496b2cf9f5aafab0705a3268829ecb4c45c630bb5b54972d669706356
7
+ data.tar.gz: b1e5948a5e6edd68b2b4b24d4d922c5d2b1fe3f45183137e38be5f8a999c91ab2aecb5b749912f76abba22cb3f56a1edc56983069bc148963f5b902535353171
data/README.md CHANGED
@@ -39,15 +39,23 @@ gem install mailslurp_client
39
39
  Or in your `Gemfile`:
40
40
 
41
41
  ```ruby
42
- gem 'mailslurp_client', '~> 7.0', '>= 7.0.8'
42
+ gem 'mailslurp_client', '~> 8.2', '>= 8.2.2'
43
43
  ```
44
44
 
45
+ And then run bundler install:
46
+
47
+ ```bash
48
+ gem install bundler
49
+ bundle install
50
+ ```
51
+
52
+
45
53
  ### Configure the client
46
54
 
47
55
  ```ruby
48
56
  require 'mailslurp_client'
49
57
 
50
- # configure the mailslurp client with an API Key
58
+ # configure mailslurp client globally with API key (or pass each controller a client instance)
51
59
  MailSlurpClient.configure do |config|
52
60
  config.api_key['x-api-key'] = "YOUR_API_KEY_HERE"
53
61
  end
@@ -80,6 +88,26 @@ it 'can create email addresses' do
80
88
  end
81
89
  ```
82
90
 
91
+ ### List inboxes
92
+
93
+ Inboxes you create can be listed in a paginated way.
94
+
95
+ ```ruby
96
+ it 'can list inboxes' do
97
+ inbox_controller = MailSlurpClient::InboxControllerApi.new
98
+ paged_inboxes = inbox_controller.get_all_inboxes({ page: 0, size: 20 })
99
+
100
+ # assert on pagination fields
101
+ expect(paged_inboxes.content).not_to be_empty
102
+ expect(paged_inboxes.number).to be(0)
103
+ expect(paged_inboxes.size).to be(20)
104
+
105
+ # can access inbox result
106
+ expect(paged_inboxes.content[0].id).not_to be_empty
107
+ end
108
+ ```
109
+
110
+
83
111
  ### Send emails
84
112
 
85
113
  You can send HTML emails easily with the inbox controller. First create an inbox then use its ID with the `send_email` method.
@@ -104,6 +132,24 @@ inbox_controller.send_email(inbox.id, {
104
132
  })
105
133
  ```
106
134
 
135
+ You can also use objects for most method options:
136
+
137
+ ```ruby
138
+ # for send options see https://github.com/mailslurp/mailslurp-client-ruby/blob/master/docs/SendEmailOptions.md
139
+ opts = {
140
+ send_email_options: MailSlurpClient::SendEmailOptions.new(
141
+ {
142
+ to: [inbox_2.email_address],
143
+ subject: 'Test email',
144
+ from: inbox_1.email_address,
145
+ body: 'Test email content',
146
+ is_html: true,
147
+ attachments: attachment_ids
148
+ }
149
+ )
150
+ }
151
+ inbox_controller.send_email(inbox_1.id, opts)
152
+ ```
107
153
  ### Receive emails
108
154
 
109
155
  You can use MailSlurp to wait for at least 1 unread email in an inbox and return it.
@@ -111,13 +157,159 @@ If a timeout is exceeded it will throw an error instead:
111
157
 
112
158
  ```ruby
113
159
  waitfor_controller = MailSlurpClient::WaitForControllerApi.new
114
- email = waitfor_controller.wait_for_latest_email({ inbox_id: inbox.id, unread_only: true })
160
+ email = waitfor_controller.wait_for_latest_email({ inbox_id: inbox.id, unread_only: true, timeout: 30_000 })
115
161
 
116
162
  # verify email contents
117
163
  expect(email.subject).to include("Test")
118
164
  expect(email.body).to include("Your email body")
119
165
  ```
120
166
 
167
+ ### Attachments
168
+
169
+ You can send attachments by first uploading files with the `AttachmentControllerApi` then using the returned attachment IDs in the send email method.
170
+
171
+ ::: tip
172
+ MailSlurp endpoints use base64 string encoding for upload and download files. To encode or decode strings in Ruby make sure you use the **strict** variables that avoid added newlines.
173
+ :::
174
+
175
+ #### Upload and send
176
+ ```ruby
177
+ # upload a file to mailslurp to use as attachment
178
+ # @return [Array<String>]
179
+ def upload_file
180
+ # read a file to upload
181
+ data = File.open(PATH_TO_ATTACHMENT).read
182
+
183
+ # encode the data as base64 string (must be strict to avoid ruby adding new line characters)
184
+ encoded = Base64.strict_encode64(data)
185
+
186
+ attachment_controller = MailSlurpClient::AttachmentControllerApi.new
187
+ upload_options = MailSlurpClient::UploadAttachmentOptions.new(
188
+ {
189
+ base64_contents: encoded,
190
+ content_type: 'text/plain',
191
+ filename: 'attachment.txt'
192
+ }
193
+ )
194
+
195
+ # return list of attachment ids
196
+ attachment_controller.upload_attachment(upload_options)
197
+ end
198
+ ```
199
+
200
+ To send attachments
201
+
202
+ ```ruby
203
+ attachment_ids = upload_file
204
+
205
+ opts = {
206
+ send_email_options: MailSlurpClient::SendEmailOptions.new(
207
+ {
208
+ to: [inbox_2.email_address],
209
+ subject: 'Test email',
210
+ from: inbox_1.email_address,
211
+ body: 'Test email content',
212
+ is_html: true,
213
+ attachments: attachment_ids
214
+ }
215
+ )
216
+ }
217
+ inbox_controller.send_email(inbox_1.id, opts)
218
+ ```
219
+
220
+ #### Download received attachments
221
+ ```ruby
222
+ # wait for the email to arrive (or fetch directly using email controller if you know it is there)
223
+ wait_opts = {
224
+ inbox_id: inbox_2.id,
225
+ timeout: 30_000,
226
+ unread_only: true
227
+ }
228
+ email = wait_controller.wait_for_latest_email(wait_opts)
229
+
230
+ # find the attachments on the email object
231
+ expect(email.attachments.size).to be(1)
232
+
233
+ # download the attachment
234
+ email_controller = MailSlurpClient::EmailControllerApi.new
235
+ downloaded_attachment = email_controller.download_attachment_base64(email.attachments[0], email.id)
236
+
237
+ # extract attachment content
238
+ expect(downloaded_attachment.content_type).to eq("text/plain")
239
+ expect(downloaded_attachment.size_bytes).to be_truthy
240
+ expect(downloaded_attachment.base64_file_contents).to be_truthy
241
+ ```
242
+
243
+ ## Examples
244
+
245
+ ### Send email between two inboxes
246
+
247
+ It is common to use MailSlurp in test environments. Here is an example RSpec test:
248
+
249
+ ```ruby
250
+
251
+ require 'mailslurp_client'
252
+
253
+ # read mailslurp api key from environment variables
254
+ API_KEY = ENV['API_KEY']
255
+
256
+ describe 'use MailSlurp ruby sdk to create email addresses then send and receive email' do
257
+ before(:all) do
258
+ expect(API_KEY).to be_truthy
259
+
260
+ # configure mailslurp with API key
261
+ MailSlurpClient.configure do |config|
262
+ config.api_key['x-api-key'] = API_KEY
263
+ end
264
+ end
265
+
266
+ it 'can an inbox with an email address' do
267
+ # create a new email address
268
+ inbox_controller = MailSlurpClient::InboxControllerApi.new
269
+ inbox = inbox_controller.create_inbox
270
+
271
+ # has a mailslurp email address
272
+ expect(inbox.id).to be_truthy
273
+ expect(inbox.email_address).to include('@mailslurp.com')
274
+ end
275
+
276
+ it 'can send and receive emails' do
277
+ inbox_controller = MailSlurpClient::InboxControllerApi.new
278
+ wait_controller = MailSlurpClient::WaitForControllerApi.new
279
+
280
+ # create two inboxes
281
+ inbox_1 = inbox_controller.create_inbox
282
+ inbox_2 = inbox_controller.create_inbox
283
+
284
+ # send email from inbox 1 to inbox 2 (you can send emails to any address)
285
+ # for send options see https://github.com/mailslurp/mailslurp-client-ruby/blob/master/docs/SendEmailOptions.md
286
+ opts = {
287
+ send_email_options: MailSlurpClient::SendEmailOptions.new(
288
+ {
289
+ to: [inbox_2.email_address],
290
+ subject: 'Test email',
291
+ from: inbox_1.email_address,
292
+ body: 'Test email content',
293
+ is_html: true
294
+ }
295
+ )
296
+ }
297
+ inbox_controller.send_email(inbox_1.id, opts)
298
+
299
+ expect(inbox_2.id).to be_truthy
300
+
301
+ # now wait for the email to arrive
302
+ wait_opts = {
303
+ inbox_id: inbox_2.id,
304
+ timeout: 30_000,
305
+ unread_only: true
306
+ }
307
+ email = wait_controller.wait_for_latest_email(wait_opts)
308
+ expect(email.body).to include('Test email content')
309
+ end
310
+ end
311
+ ```
312
+
121
313
  ## SDK Documentation
122
314
 
123
315
  See the [examples page](https://www.mailslurp.com/examples/) or the full [Method Documentation](./docs) on Github.
@@ -15,7 +15,7 @@ require 'date'
15
15
  module MailSlurpClient
16
16
  # Options for uploading files for attachments. When sending emails with the API that require attachments first upload each attachment. Then use the returned attachment ID in your `SendEmailOptions` when sending an email. This way you can use attachments multiple times once they have been uploaded.
17
17
  class UploadAttachmentOptions
18
- # Base64 encoded string of file contents
18
+ # Base64 encoded string of file contents. Typically this means reading the bytes or string content of a file and then converting that to a base64 encoded string.
19
19
  attr_accessor :base64_contents
20
20
 
21
21
  # Optional contentType for file. For instance `application/pdf`
@@ -11,5 +11,5 @@ OpenAPI Generator version: 4.3.1
11
11
  =end
12
12
 
13
13
  module MailSlurpClient
14
- VERSION = '8.2.2'
14
+ VERSION = '8.2.4'
15
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailslurp_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.2.2
4
+ version: 8.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - mailslurp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-19 00:00:00.000000000 Z
11
+ date: 2020-11-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Create emails addresses in Ruby then send and receive real emails and
14
14
  attachments. See https://www.mailslurp.com/docs/ruby/ for full Ruby documentation.