mailslurp_client 8.2.1 → 8.2.7
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc32874bf10e7c9c49626c99e69e421891c34df4136a201b8b902485287ec36c
|
4
|
+
data.tar.gz: '086b46c10d486705f9a400be470cba8bc313623d05a666028f735f76f4882234'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c16d687eaa9984297f262b08cec0325216bcdf56625677f55675da44b6bda7a9013237632b369fd64bfcd3fde01180b5d40029c9d3b51918578a1ef6d79b37fa
|
7
|
+
data.tar.gz: b25787efbe06f5ca9f2864a8e5ab48c50066ac484cb517b863d407f356a836c37a8a259191f94ca04a5a8250d9b88dd717a0a95ffd0b7485ca104c9e98694217
|
data/README.md
CHANGED
@@ -13,11 +13,13 @@ MailSlurp is an email API service that lets you create real email addresses in c
|
|
13
13
|
## Get started
|
14
14
|
|
15
15
|
::: tip
|
16
|
+
|
16
17
|
This section describes how to get up and running with the Ruby client.
|
17
18
|
|
18
19
|
See the [examples page](https://www.mailslurp.com/examples/) for more examples and use with common frameworks such as Rails and RSpec.
|
19
20
|
|
20
21
|
See the method documentation for a [list of all functions](./docs)
|
22
|
+
|
21
23
|
:::
|
22
24
|
|
23
25
|
### Create API Key
|
@@ -39,15 +41,23 @@ gem install mailslurp_client
|
|
39
41
|
Or in your `Gemfile`:
|
40
42
|
|
41
43
|
```ruby
|
42
|
-
gem 'mailslurp_client', '~>
|
44
|
+
gem 'mailslurp_client', '~> 8.2', '>= 8.2.2'
|
45
|
+
```
|
46
|
+
|
47
|
+
And then run bundler install:
|
48
|
+
|
49
|
+
```bash
|
50
|
+
gem install bundler
|
51
|
+
bundle install
|
43
52
|
```
|
44
53
|
|
54
|
+
|
45
55
|
### Configure the client
|
46
56
|
|
47
57
|
```ruby
|
48
58
|
require 'mailslurp_client'
|
49
59
|
|
50
|
-
# configure
|
60
|
+
# configure mailslurp client globally with API key (or pass each controller a client instance)
|
51
61
|
MailSlurpClient.configure do |config|
|
52
62
|
config.api_key['x-api-key'] = "YOUR_API_KEY_HERE"
|
53
63
|
end
|
@@ -80,6 +90,26 @@ it 'can create email addresses' do
|
|
80
90
|
end
|
81
91
|
```
|
82
92
|
|
93
|
+
### List inboxes
|
94
|
+
|
95
|
+
Inboxes you create can be listed in a paginated way.
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
it 'can list inboxes' do
|
99
|
+
inbox_controller = MailSlurpClient::InboxControllerApi.new
|
100
|
+
paged_inboxes = inbox_controller.get_all_inboxes({ page: 0, size: 20 })
|
101
|
+
|
102
|
+
# assert on pagination fields
|
103
|
+
expect(paged_inboxes.content).not_to be_empty
|
104
|
+
expect(paged_inboxes.number).to be(0)
|
105
|
+
expect(paged_inboxes.size).to be(20)
|
106
|
+
|
107
|
+
# can access inbox result
|
108
|
+
expect(paged_inboxes.content[0].id).not_to be_empty
|
109
|
+
end
|
110
|
+
```
|
111
|
+
|
112
|
+
|
83
113
|
### Send emails
|
84
114
|
|
85
115
|
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 +134,24 @@ inbox_controller.send_email(inbox.id, {
|
|
104
134
|
})
|
105
135
|
```
|
106
136
|
|
137
|
+
You can also use objects for most method options:
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
# for send options see https://github.com/mailslurp/mailslurp-client-ruby/blob/master/docs/SendEmailOptions.md
|
141
|
+
opts = {
|
142
|
+
send_email_options: MailSlurpClient::SendEmailOptions.new(
|
143
|
+
{
|
144
|
+
to: [inbox_2.email_address],
|
145
|
+
subject: 'Test email',
|
146
|
+
from: inbox_1.email_address,
|
147
|
+
body: 'Test email content',
|
148
|
+
is_html: true,
|
149
|
+
attachments: attachment_ids
|
150
|
+
}
|
151
|
+
)
|
152
|
+
}
|
153
|
+
inbox_controller.send_email(inbox_1.id, opts)
|
154
|
+
```
|
107
155
|
### Receive emails
|
108
156
|
|
109
157
|
You can use MailSlurp to wait for at least 1 unread email in an inbox and return it.
|
@@ -111,13 +159,161 @@ If a timeout is exceeded it will throw an error instead:
|
|
111
159
|
|
112
160
|
```ruby
|
113
161
|
waitfor_controller = MailSlurpClient::WaitForControllerApi.new
|
114
|
-
email = waitfor_controller.wait_for_latest_email({ inbox_id: inbox.id, unread_only: true })
|
162
|
+
email = waitfor_controller.wait_for_latest_email({ inbox_id: inbox.id, unread_only: true, timeout: 30_000 })
|
115
163
|
|
116
164
|
# verify email contents
|
117
165
|
expect(email.subject).to include("Test")
|
118
166
|
expect(email.body).to include("Your email body")
|
119
167
|
```
|
120
168
|
|
169
|
+
### Attachments
|
170
|
+
|
171
|
+
You can send attachments by first uploading files with the `AttachmentControllerApi` then using the returned attachment IDs in the send email method.
|
172
|
+
|
173
|
+
::: tip
|
174
|
+
|
175
|
+
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.
|
176
|
+
|
177
|
+
:::
|
178
|
+
|
179
|
+
#### Upload and send
|
180
|
+
```ruby
|
181
|
+
# upload a file to mailslurp to use as attachment
|
182
|
+
# @return [Array<String>]
|
183
|
+
def upload_file
|
184
|
+
# read a file to upload
|
185
|
+
data = File.open(PATH_TO_ATTACHMENT).read
|
186
|
+
|
187
|
+
# encode the data as base64 string (must be strict to avoid ruby adding new line characters)
|
188
|
+
encoded = Base64.strict_encode64(data)
|
189
|
+
|
190
|
+
attachment_controller = MailSlurpClient::AttachmentControllerApi.new
|
191
|
+
upload_options = MailSlurpClient::UploadAttachmentOptions.new(
|
192
|
+
{
|
193
|
+
base64_contents: encoded,
|
194
|
+
content_type: 'text/plain',
|
195
|
+
filename: 'attachment.txt'
|
196
|
+
}
|
197
|
+
)
|
198
|
+
|
199
|
+
# return list of attachment ids
|
200
|
+
attachment_controller.upload_attachment(upload_options)
|
201
|
+
end
|
202
|
+
```
|
203
|
+
|
204
|
+
To send attachments
|
205
|
+
|
206
|
+
```ruby
|
207
|
+
attachment_ids = upload_file
|
208
|
+
|
209
|
+
opts = {
|
210
|
+
send_email_options: MailSlurpClient::SendEmailOptions.new(
|
211
|
+
{
|
212
|
+
to: [inbox_2.email_address],
|
213
|
+
subject: 'Test email',
|
214
|
+
from: inbox_1.email_address,
|
215
|
+
body: 'Test email content',
|
216
|
+
is_html: true,
|
217
|
+
attachments: attachment_ids
|
218
|
+
}
|
219
|
+
)
|
220
|
+
}
|
221
|
+
inbox_controller.send_email(inbox_1.id, opts)
|
222
|
+
```
|
223
|
+
|
224
|
+
#### Download received attachments
|
225
|
+
```ruby
|
226
|
+
# wait for the email to arrive (or fetch directly using email controller if you know it is there)
|
227
|
+
wait_opts = {
|
228
|
+
inbox_id: inbox_2.id,
|
229
|
+
timeout: 30_000,
|
230
|
+
unread_only: true
|
231
|
+
}
|
232
|
+
email = wait_controller.wait_for_latest_email(wait_opts)
|
233
|
+
|
234
|
+
# find the attachments on the email object
|
235
|
+
expect(email.attachments.size).to be(1)
|
236
|
+
|
237
|
+
# download the attachment
|
238
|
+
email_controller = MailSlurpClient::EmailControllerApi.new
|
239
|
+
downloaded_attachment = email_controller.download_attachment_base64(email.attachments[0], email.id)
|
240
|
+
|
241
|
+
# extract attachment content
|
242
|
+
expect(downloaded_attachment.content_type).to eq("text/plain")
|
243
|
+
expect(downloaded_attachment.size_bytes).to be_truthy
|
244
|
+
expect(downloaded_attachment.base64_file_contents).to be_truthy
|
245
|
+
```
|
246
|
+
|
247
|
+
## Examples
|
248
|
+
|
249
|
+
### Send email between two inboxes
|
250
|
+
|
251
|
+
It is common to use MailSlurp in test environments. Here is an example RSpec test:
|
252
|
+
|
253
|
+
```ruby
|
254
|
+
|
255
|
+
require 'mailslurp_client'
|
256
|
+
|
257
|
+
# read mailslurp api key from environment variables
|
258
|
+
API_KEY = ENV['API_KEY']
|
259
|
+
|
260
|
+
describe 'use MailSlurp ruby sdk to create email addresses then send and receive email' do
|
261
|
+
before(:all) do
|
262
|
+
expect(API_KEY).to be_truthy
|
263
|
+
|
264
|
+
# configure mailslurp with API key
|
265
|
+
MailSlurpClient.configure do |config|
|
266
|
+
config.api_key['x-api-key'] = API_KEY
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'can an inbox with an email address' do
|
271
|
+
# create a new email address
|
272
|
+
inbox_controller = MailSlurpClient::InboxControllerApi.new
|
273
|
+
inbox = inbox_controller.create_inbox
|
274
|
+
|
275
|
+
# has a mailslurp email address
|
276
|
+
expect(inbox.id).to be_truthy
|
277
|
+
expect(inbox.email_address).to include('@mailslurp.com')
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'can send and receive emails' do
|
281
|
+
inbox_controller = MailSlurpClient::InboxControllerApi.new
|
282
|
+
wait_controller = MailSlurpClient::WaitForControllerApi.new
|
283
|
+
|
284
|
+
# create two inboxes
|
285
|
+
inbox_1 = inbox_controller.create_inbox
|
286
|
+
inbox_2 = inbox_controller.create_inbox
|
287
|
+
|
288
|
+
# send email from inbox 1 to inbox 2 (you can send emails to any address)
|
289
|
+
# for send options see https://github.com/mailslurp/mailslurp-client-ruby/blob/master/docs/SendEmailOptions.md
|
290
|
+
opts = {
|
291
|
+
send_email_options: MailSlurpClient::SendEmailOptions.new(
|
292
|
+
{
|
293
|
+
to: [inbox_2.email_address],
|
294
|
+
subject: 'Test email',
|
295
|
+
from: inbox_1.email_address,
|
296
|
+
body: 'Test email content',
|
297
|
+
is_html: true
|
298
|
+
}
|
299
|
+
)
|
300
|
+
}
|
301
|
+
inbox_controller.send_email(inbox_1.id, opts)
|
302
|
+
|
303
|
+
expect(inbox_2.id).to be_truthy
|
304
|
+
|
305
|
+
# now wait for the email to arrive
|
306
|
+
wait_opts = {
|
307
|
+
inbox_id: inbox_2.id,
|
308
|
+
timeout: 30_000,
|
309
|
+
unread_only: true
|
310
|
+
}
|
311
|
+
email = wait_controller.wait_for_latest_email(wait_opts)
|
312
|
+
expect(email.body).to include('Test email content')
|
313
|
+
end
|
314
|
+
end
|
315
|
+
```
|
316
|
+
|
121
317
|
## SDK Documentation
|
122
318
|
|
123
319
|
See the [examples page](https://www.mailslurp.com/examples/) or the full [Method Documentation](./docs) on Github.
|
@@ -19,7 +19,7 @@ module MailSlurpClient
|
|
19
19
|
def initialize(api_client = ApiClient.default)
|
20
20
|
@api_client = api_client
|
21
21
|
end
|
22
|
-
# Upload an attachment for sending
|
22
|
+
# Upload an attachment for sending using base64 file encoding
|
23
23
|
# When sending emails with attachments first upload each attachment with this endpoint. Record the returned attachment IDs. Then use these attachment IDs in the SendEmailOptions when sending an email. This means that attachments can easily be reused.
|
24
24
|
# @param upload_options [UploadAttachmentOptions] uploadOptions
|
25
25
|
# @param [Hash] opts the optional parameters
|
@@ -29,7 +29,7 @@ module MailSlurpClient
|
|
29
29
|
data
|
30
30
|
end
|
31
31
|
|
32
|
-
# Upload an attachment for sending
|
32
|
+
# Upload an attachment for sending using base64 file encoding
|
33
33
|
# When sending emails with attachments first upload each attachment with this endpoint. Record the returned attachment IDs. Then use these attachment IDs in the SendEmailOptions when sending an email. This means that attachments can easily be reused.
|
34
34
|
# @param upload_options [UploadAttachmentOptions] uploadOptions
|
35
35
|
# @param [Hash] opts the optional parameters
|
@@ -83,6 +83,66 @@ module MailSlurpClient
|
|
83
83
|
return data, status_code, headers
|
84
84
|
end
|
85
85
|
|
86
|
+
# Upload an attachment for sending using file byte stream input octet stream
|
87
|
+
# When sending emails with attachments first upload each attachment with this endpoint. Record the returned attachment IDs. Then use these attachment IDs in the SendEmailOptions when sending an email. This means that attachments can easily be reused.
|
88
|
+
# @param [Hash] opts the optional parameters
|
89
|
+
# @option opts [String] :filename Optional filename to save upload with
|
90
|
+
# @return [Array<String>]
|
91
|
+
def upload_attachment_bytes(opts = {})
|
92
|
+
data, _status_code, _headers = upload_attachment_bytes_with_http_info(opts)
|
93
|
+
data
|
94
|
+
end
|
95
|
+
|
96
|
+
# Upload an attachment for sending using file byte stream input octet stream
|
97
|
+
# When sending emails with attachments first upload each attachment with this endpoint. Record the returned attachment IDs. Then use these attachment IDs in the SendEmailOptions when sending an email. This means that attachments can easily be reused.
|
98
|
+
# @param [Hash] opts the optional parameters
|
99
|
+
# @option opts [String] :filename Optional filename to save upload with
|
100
|
+
# @return [Array<(Array<String>, Integer, Hash)>] Array<String> data, response status code and response headers
|
101
|
+
def upload_attachment_bytes_with_http_info(opts = {})
|
102
|
+
if @api_client.config.debugging
|
103
|
+
@api_client.config.logger.debug 'Calling API: AttachmentControllerApi.upload_attachment_bytes ...'
|
104
|
+
end
|
105
|
+
# resource path
|
106
|
+
local_var_path = '/attachments/bytes'
|
107
|
+
|
108
|
+
# query parameters
|
109
|
+
query_params = opts[:query_params] || {}
|
110
|
+
|
111
|
+
# header parameters
|
112
|
+
header_params = opts[:header_params] || {}
|
113
|
+
# HTTP header 'Accept' (if needed)
|
114
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
115
|
+
# HTTP header 'Content-Type'
|
116
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/octet-stream'])
|
117
|
+
|
118
|
+
# form parameters
|
119
|
+
form_params = opts[:form_params] || {}
|
120
|
+
|
121
|
+
# http body (model)
|
122
|
+
post_body = opts[:body] || @api_client.object_to_http_body(opts[:'filename'])
|
123
|
+
|
124
|
+
# return_type
|
125
|
+
return_type = opts[:return_type] || 'Array<String>'
|
126
|
+
|
127
|
+
# auth_names
|
128
|
+
auth_names = opts[:auth_names] || ['API_KEY']
|
129
|
+
|
130
|
+
new_options = opts.merge(
|
131
|
+
:header_params => header_params,
|
132
|
+
:query_params => query_params,
|
133
|
+
:form_params => form_params,
|
134
|
+
:body => post_body,
|
135
|
+
:auth_names => auth_names,
|
136
|
+
:return_type => return_type
|
137
|
+
)
|
138
|
+
|
139
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
140
|
+
if @api_client.config.debugging
|
141
|
+
@api_client.config.logger.debug "API called: AttachmentControllerApi#upload_attachment_bytes\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
142
|
+
end
|
143
|
+
return data, status_code, headers
|
144
|
+
end
|
145
|
+
|
86
146
|
# Upload an attachment for sending using Multipart Form
|
87
147
|
# When sending emails with attachments first upload each attachment with this endpoint. Record the returned attachment IDs. Then use these attachment IDs in the SendEmailOptions when sending an email. This means that attachments can easily be reused.
|
88
148
|
# @param file [File] file
|
@@ -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`
|
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.
|
4
|
+
version: 8.2.7
|
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-
|
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.
|