mailosaur 8.1.0 → 8.2.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: 3f9e68987fc63770ca61c94a5091b02ea932bb765ea6dfa1d2d3ca8603e58867
4
- data.tar.gz: 8683c7bb7ffe561fc491867bb2000437cd3b0541cec1c738d9733c649c6c2d1d
3
+ metadata.gz: 9e15e690f564a4062f112f14a72bd49fe52bc7853875294af84010b65e40e2bb
4
+ data.tar.gz: ad66cd3aa1bc0a793e1e9021faf25d77d85b2a29a5db5e95785380b7114b6156
5
5
  SHA512:
6
- metadata.gz: abb3db223ad672d31099e11284a928679c3a3c9db15b9e727c2fbd68119a23fe424bd75116b54b35c6a1b25ce9edb47f7a956baf444835b626a9acf904824bf0
7
- data.tar.gz: 7a556665627605e074ce413a02be0d839032454445e5592de4367ee1d05707c193205726940a20545edd752926b277da7801e6b1dac9db14b0f738402110a065
6
+ metadata.gz: 7b963ba016116dbe06b0f4f55c665dd4eebfa3f24937f8001d4ca6c97c5ad69e97366d3b0b9c40b6fe36fb41f549fd9259edf13dd204497a2049f35e1e1002fc
7
+ data.tar.gz: 1124748868ababe49581fb9b98f3e10dfb442733f21cf98206c445582acb289dd12b64dec9bd873bfa153646a31287c4a3160cda596e12334828ec86775d8425
data/README.md CHANGED
@@ -10,21 +10,32 @@ Mailosaur lets you automate email and SMS tests as part of software development
10
10
 
11
11
  This guide provides several key sections:
12
12
 
13
+ - [Mailosaur - Ruby library · ](#mailosaur---ruby-library--)
13
14
  - [Get Started](#get-started)
14
- - [Installation](#installation)
15
- - [Set your API key](#set-your-api-key)
16
- - [Create your code](#create-your-code)
17
- - [API Reference](#api-reference)
15
+ - [Installation](#installation)
16
+ - [Set your API key](#set-your-api-key)
17
+ - [Create your code](#create-your-code)
18
+ - [API Reference](#api-reference)
18
19
  - [Creating an account](#creating-an-account)
19
20
  - [Test email addresses with Mailosaur](#test-email-addresses-with-mailosaur)
20
21
  - [Find an email](#find-an-email)
22
+ - [What is this code doing?](#what-is-this-code-doing)
23
+ - [My email wasn't found](#my-email-wasnt-found)
21
24
  - [Find an SMS message](#find-an-sms-message)
22
25
  - [Testing plain text content](#testing-plain-text-content)
26
+ - [Extracting verification codes from plain text](#extracting-verification-codes-from-plain-text)
23
27
  - [Testing HTML content](#testing-html-content)
28
+ - [Working with HTML using Nokogiri](#working-with-html-using-nokogiri)
24
29
  - [Working with hyperlinks](#working-with-hyperlinks)
30
+ - [Links in plain text (including SMS messages)](#links-in-plain-text-including-sms-messages)
25
31
  - [Working with attachments](#working-with-attachments)
32
+ - [Writing an attachment to disk](#writing-an-attachment-to-disk)
26
33
  - [Working with images and web beacons](#working-with-images-and-web-beacons)
34
+ - [Remotely-hosted images](#remotely-hosted-images)
35
+ - [Triggering web beacons](#triggering-web-beacons)
27
36
  - [Spam checking](#spam-checking)
37
+ - [Development](#development)
38
+ - [Contacting us](#contacting-us)
28
39
 
29
40
  You can find the full [Mailosaur documentation](https://mailosaur.com/docs/) on the website.
30
41
 
@@ -32,7 +43,7 @@ If you get stuck, just contact us at support@mailosaur.com.
32
43
 
33
44
  ### Installation
34
45
 
35
- ```
46
+ ```sh
36
47
  gem install mailosaur
37
48
  ```
38
49
 
@@ -46,11 +57,11 @@ export MAILOSAUR_API_KEY='your-api-key-here'
46
57
 
47
58
  ### Create your code
48
59
 
49
- Then import the library into your code:
60
+ Now import the library and create a client:
50
61
 
51
62
  ```ruby
52
63
  require 'mailosaur'
53
- mailosaur = Mailosaur::MailosaurClient.new()
64
+ mailosaur = Mailosaur::MailosaurClient.new
54
65
  ```
55
66
 
56
67
  ### API Reference
@@ -58,17 +69,17 @@ mailosaur = Mailosaur::MailosaurClient.new()
58
69
  This library is powered by the Mailosaur [email & SMS testing API](https://mailosaur.com/docs/api/). You can easily check out the API itself by looking at our [API reference documentation](https://mailosaur.com/docs/api/) or via our Postman or Insomnia collections:
59
70
 
60
71
  [![Run in Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/6961255-6cc72dff-f576-451a-9023-b82dec84f95d?action=collection%2Ffork&collection-url=entityId%3D6961255-6cc72dff-f576-451a-9023-b82dec84f95d%26entityType%3Dcollection%26workspaceId%3D386a4af1-4293-4197-8f40-0eb49f831325)
61
- [![Run in Insomnia}](https://insomnia.rest/images/run.svg)](https://insomnia.rest/run/?label=Mailosaur&uri=https%3A%2F%2Fmailosaur.com%2Finsomnia.json)
72
+ [![Run in Insomnia](https://insomnia.rest/images/run.svg)](https://insomnia.rest/run/?label=Mailosaur&uri=https%3A%2F%2Fmailosaur.com%2Finsomnia.json)
62
73
 
63
74
  ## Creating an account
64
75
 
65
76
  Create a [free trial account](https://mailosaur.com/app/signup) for Mailosaur via the website.
66
77
 
67
- Once you have this, navigate to the [API tab](https://mailosaur.com/app/project/api) to find the following values:
78
+ To start testing you'll need three things:
68
79
 
69
- - **Server ID** - Servers act like projects, which group your tests together. You need this ID whenever you interact with a server via the API.
70
- - **Server Domain** - Every server has its own domain name. You'll need this to send email to your server.
71
- - **API Key** - You can create an API key per server (recommended), or an account-level API key to use across your whole account. [Learn more about API keys](https://mailosaur.com/docs/managing-your-account/api-keys/).
80
+ - **API key** - [manage API keys within the Mailosaur Dashboard](https://mailosaur.com/app/keys). You can scope a key to a single inbox (server) — recommended — or create an account-level key. [Learn more about API keys](https://mailosaur.com/docs/managing-your-account/api-keys/).
81
+ - **Inbox (server) domain** - open [your inbox](https://mailosaur.com/app/servers/default) (server) within the Mailosaur Dashboard to see its domain name (e.g. `abc123.mailosaur.net`). You'll need this to send email to the inbox (server).
82
+ - **Inbox (server) ID** - the first part of the inbox (server) domain. For `abc123.mailosaur.net` the ID is `abc123`. You need this whenever you interact with the inbox (server) via the API.
72
83
 
73
84
  ## Test email addresses with Mailosaur
74
85
 
@@ -76,13 +87,13 @@ Mailosaur gives you an **unlimited number of test email addresses** - with no se
76
87
 
77
88
  Here's how it works:
78
89
 
79
- * When you create an account, you are given a server.
80
- * Every server has its own **Server Domain** name (e.g. `abc123.mailosaur.net`)
90
+ * When you create an account, you are given an inbox (server).
91
+ * Every inbox (server) has its own domain name (e.g. `abc123.mailosaur.net`)
81
92
  * Any email address that ends with `@{YOUR_SERVER_DOMAIN}` will work with Mailosaur without any special setup. For example:
82
93
  * `build-423@abc123.mailosaur.net`
83
94
  * `john.smith@abc123.mailosaur.net`
84
95
  * `rAnDoM63423@abc123.mailosaur.net`
85
- * You can create more servers when you need them. Each one will have its own domain name.
96
+ * You can create more inboxes (servers) when you need them. Each one will have its own domain name.
86
97
 
87
98
  ***Can't use test email addresses?** You can also [use SMTP to test email](https://mailosaur.com/docs/email-testing/sending-to-mailosaur/#sending-via-smtp). By connecting your product or website to Mailosaur via SMTP, Mailosaur will catch all email your application sends, regardless of the email address.*
88
99
 
@@ -93,13 +104,12 @@ In automated tests you will want to wait for a new email to arrive. This library
93
104
  ```ruby
94
105
  require 'mailosaur'
95
106
 
96
- mailosaur = Mailosaur::MailosaurClient.new()
107
+ mailosaur = Mailosaur::MailosaurClient.new
97
108
 
98
- # See https://mailosaur.com/app/project/api
99
109
  server_id = "abc123"
100
110
  server_domain = "abc123.mailosaur.net"
101
111
 
102
- criteria = Mailosaur::Models::SearchCriteria.new()
112
+ criteria = Mailosaur::Models::SearchCriteria.new
103
113
  criteria.sent_to = "anything@" + server_domain
104
114
 
105
115
  email = mailosaur.messages.get(server_id, criteria)
@@ -109,10 +119,27 @@ puts(email.subject) # "Hello world!"
109
119
 
110
120
  ### What is this code doing?
111
121
 
112
- 1. Sets up an instance of `MailosaurClient` using the `MAILOSAUR_API_KEY` environment variable.
113
- 2. Waits for an email to arrive at the server with ID `abc123`.
122
+ 1. Sets up an instance of `MailosaurClient`, reading the API key from the `MAILOSAUR_API_KEY` environment variable.
123
+ 2. Waits for an email to arrive at the inbox (server) with ID `abc123`.
114
124
  3. Outputs the subject line of the email.
115
125
 
126
+ ### My email wasn't found
127
+
128
+ First, check that the email you sent is visible in the [Mailosaur Dashboard](https://mailosaur.com/app/project/messages).
129
+
130
+ If it is, the likely reason is that by default, `messages.get` only searches emails received by Mailosaur in the last 1 hour. You can override this behavior (see the `received_after` argument below), however we only recommend doing this during setup, as your tests will generally run faster with the default settings:
131
+
132
+ ```ruby
133
+ require 'date'
134
+
135
+ email = mailosaur.messages.get(
136
+ server_id,
137
+ criteria,
138
+ # Override received_after to search all messages since Jan 1st
139
+ received_after: DateTime.new(2021, 1, 1)
140
+ )
141
+ ```
142
+
116
143
  ## Find an SMS message
117
144
 
118
145
  **Important:** Trial accounts do not automatically have SMS access. Please contact our support team to enable a trial of SMS functionality.
@@ -122,11 +149,12 @@ If your account has [SMS testing](https://mailosaur.com/sms-testing/) enabled, y
122
149
  ```ruby
123
150
  require 'mailosaur'
124
151
 
125
- mailosaur = Mailosaur::MailosaurClient.new()
152
+ mailosaur = Mailosaur::MailosaurClient.new
126
153
 
127
154
  server_id = "abc123"
155
+ server_domain = "abc123.mailosaur.net"
128
156
 
129
- criteria = Mailosaur::Models::SearchCriteria.new()
157
+ criteria = Mailosaur::Models::SearchCriteria.new
130
158
  criteria.sent_to = "4471235554444"
131
159
 
132
160
  sms = mailosaur.messages.get(server_id, criteria)
@@ -148,18 +176,15 @@ end
148
176
 
149
177
  ### Extracting verification codes from plain text
150
178
 
151
- You may have an email or SMS message that contains an account verification code, or some other one-time passcode. You can extract content like this using a simple regex.
152
-
153
- Here is how to extract a 6-digit numeric code:
179
+ You may have an email or SMS message that contains an account verification code, or some other one-time passcode. Mailosaur automatically extracts these for you and makes them available via the `codes` array on the message content:
154
180
 
155
181
  ```ruby
156
182
  puts(message.text.body) # "Your access code is 243546."
157
183
 
158
- match = message.text.body.match(/([0-9]{6})/)
159
- puts(match[0]) # "243546"
184
+ puts(message.text.codes[0].value) # "243546"
160
185
  ```
161
186
 
162
- [Read more](https://mailosaur.com/docs/test-cases/text-content/)
187
+ [Read more](https://mailosaur.com/docs/automation/codes)
163
188
 
164
189
  ## Testing HTML content
165
190
 
@@ -169,9 +194,9 @@ Most emails also have an HTML body, as well as the plain text content. You can a
169
194
  puts(message.html.body) # "<html><head ..."
170
195
  ```
171
196
 
172
- ### Working with HTML using nokogiri
197
+ ### Working with HTML using Nokogiri
173
198
 
174
- If you need to traverse the HTML content of an email. For example, finding an element via a CSS selector, you can use the [nokogiri](https://rubygems.org/gems/nokogiri) library.
199
+ If you need to traverse the HTML content of an email — for example, finding an element via a CSS selector — you can use the [Nokogiri](https://rubygems.org/gems/nokogiri) library.
175
200
 
176
201
  ```sh
177
202
  gem install nokogiri
@@ -182,12 +207,12 @@ require 'nokogiri'
182
207
 
183
208
  # ...
184
209
 
185
- @doc = Nokogiri::HTML(message.html.body)
186
- el = @doc.css(".verification-code")
210
+ doc = Nokogiri::HTML(message.html.body)
211
+ el = doc.at_css(".verification-code")
187
212
 
188
213
  verification_code = el.text
189
214
 
190
- puts verification_code # "542163"
215
+ puts(verification_code) # "542163"
191
216
  ```
192
217
 
193
218
  [Read more](https://mailosaur.com/docs/test-cases/html-content/)
@@ -207,7 +232,7 @@ puts(first_link.text) # "Google Search"
207
232
  puts(first_link.href) # "https://www.google.com/"
208
233
  ```
209
234
 
210
- **Important:** To ensure you always have valid emails. Mailosaur only extracts links that have been correctly marked up with `<a>` or `<area>` tags.
235
+ **Important:** To ensure you always have valid emails, Mailosaur only extracts links that have been correctly marked up with `<a>` or `<area>` tags.
211
236
 
212
237
  ### Links in plain text (including SMS messages)
213
238
 
@@ -245,6 +270,15 @@ first_attachment = message.attachments[0]
245
270
  puts(first_attachment.length) # 4028
246
271
  ```
247
272
 
273
+ ### Writing an attachment to disk
274
+
275
+ ```ruby
276
+ first_attachment = message.attachments[1]
277
+
278
+ file_bytes = mailosaur.files.get_attachment(first_attachment.id)
279
+ File.binwrite(first_attachment.file_name, file_bytes)
280
+ ```
281
+
248
282
  ## Working with images and web beacons
249
283
 
250
284
  The `html.images` property of a message contains an array of images found within the HTML content of an email. The length of this array corresponds to the number of images found within an email:
@@ -1,8 +1,11 @@
1
1
  module Mailosaur
2
+ # Operations for analyzing the content and deliverability of an email, including SpamAssassin
3
+ # scoring and per-provider deliverability reports. Accessed via +client.analysis+.
2
4
  class Analysis
3
5
  #
4
6
  # Creates and initializes a new instance of the Analysis class.
5
- # @param conn client connection.
7
+ # @param conn [Faraday::Connection] The client connection.
8
+ # @param handle_http_error [Method] Callback used to convert HTTP error responses into errors.
6
9
  #
7
10
  def initialize(conn, handle_http_error)
8
11
  @conn = conn
@@ -13,13 +16,11 @@ module Mailosaur
13
16
  attr_reader :conn
14
17
 
15
18
  #
16
- # Perform a spam test
19
+ # Perform a spam analysis of an email.
17
20
  #
18
- # Perform spam testing on the specified email
21
+ # @param email [String] The identifier of the message to be analyzed.
19
22
  #
20
- # @param email The identifier of the email to be analyzed.
21
- #
22
- # @return [SpamAnalysisResult] operation results.
23
+ # @return [Mailosaur::Models::SpamAnalysisResult] The spam score and filter results.
23
24
  #
24
25
  def spam(email)
25
26
  response = conn.get "api/analysis/spam/#{email}"
@@ -29,13 +30,11 @@ module Mailosaur
29
30
  end
30
31
 
31
32
  #
32
- # Perform a deliverability report
33
- #
34
- # Perform deliverability test on the specified email
33
+ # Perform a deliverability report of an email.
35
34
  #
36
- # @param email The identifier of the email to be analyzed.
35
+ # @param email [String] The identifier of the message to be analyzed.
37
36
  #
38
- # @return [DeliverabilityReport] operation results.
37
+ # @return [Mailosaur::Models::DeliverabilityReport] The deliverability report for the email.
39
38
  #
40
39
  def deliverability(email)
41
40
  response = conn.get "api/analysis/deliverability/#{email}"
@@ -1,8 +1,12 @@
1
1
  module Mailosaur
2
+ # Operations for managing virtual security devices and retrieving their current one-time
3
+ # passwords (OTPs), used to automate testing of app-based multi-factor authentication.
4
+ # Accessed via +client.devices+.
2
5
  class Devices
3
6
  #
4
7
  # Creates and initializes a new instance of the Devices class.
5
- # @param client connection.
8
+ # @param conn [Faraday::Connection] The client connection.
9
+ # @param handle_http_error [Method] Callback used to convert HTTP error responses into errors.
6
10
  #
7
11
  def initialize(conn, handle_http_error)
8
12
  @conn = conn
@@ -12,12 +16,10 @@ module Mailosaur
12
16
  # @return [Connection] the client connection.
13
17
  attr_reader :conn
14
18
 
15
- #
16
- # List all devices
17
19
  #
18
20
  # Returns a list of your virtual security devices.
19
21
  #
20
- # @return [DeviceListResult] operation results.
22
+ # @return [Mailosaur::Models::DeviceListResult] Your devices.
21
23
  #
22
24
  def list
23
25
  response = conn.get 'api/devices'
@@ -27,13 +29,12 @@ module Mailosaur
27
29
  end
28
30
 
29
31
  #
30
- # Create a device
31
- #
32
- # Creates a new virtual security device and returns it.
32
+ # Creates a new virtual security device.
33
33
  #
34
- # @param device_create_options [DeviceCreateOptions]
34
+ # @param device_create_options [Mailosaur::Models::DeviceCreateOptions] Options used to
35
+ # create a new Mailosaur virtual security device.
35
36
  #
36
- # @return [Device] operation results.
37
+ # @return [Mailosaur::Models::Device] The newly-created device.
37
38
  #
38
39
  def create(device_create_options)
39
40
  response = conn.post 'api/devices', device_create_options.to_json
@@ -43,13 +44,13 @@ module Mailosaur
43
44
  end
44
45
 
45
46
  #
46
- # Retrieve OTP
47
- #
48
- # Retrieves the current one-time password for a saved device, or given base32-encoded shared secret.
47
+ # Retrieves the current one-time password for a saved device, or given base32-encoded
48
+ # shared secret.
49
49
  #
50
- # @param query [String] Either the unique identifier of the device, or a base32-encoded shared secret.
50
+ # @param query [String] Either the unique identifier of the device, or a base32-encoded
51
+ # shared secret.
51
52
  #
52
- # @return [OtpResult] operation results.
53
+ # @return [Mailosaur::Models::OtpResult] The current one-time password.
53
54
  #
54
55
  def otp(query)
55
56
  if query.include? '-'
@@ -68,11 +69,11 @@ module Mailosaur
68
69
  end
69
70
 
70
71
  #
71
- # Delete a device
72
+ # Permanently delete a virtual security device. This operation cannot be undone.
72
73
  #
73
- # Permanently deletes a device. This operation cannot be undone.
74
+ # @param id [String] The unique identifier of the device.
74
75
  #
75
- # @param id [String] The identifier of the device to be deleted.
76
+ # @return [nil] Once the device has been deleted.
76
77
  #
77
78
  def delete(id)
78
79
  response = conn.delete "api/devices/#{id}"
@@ -1,8 +1,13 @@
1
1
  module Mailosaur
2
+ # Operations for downloading the raw content associated with a message — file attachments,
3
+ # the full EML source of an email, and rendered email previews. Accessed via +client.files+.
2
4
  class Files
5
+ include Polling
6
+
3
7
  #
4
8
  # Creates and initializes a new instance of the Files class.
5
- # @param client connection.
9
+ # @param conn [Faraday::Connection] The client connection.
10
+ # @param handle_http_error [Method] Callback used to convert HTTP error responses into errors.
6
11
  #
7
12
  def initialize(conn, handle_http_error)
8
13
  @conn = conn
@@ -13,14 +18,11 @@ module Mailosaur
13
18
  attr_reader :conn
14
19
 
15
20
  #
16
- # Download an attachment
17
- #
18
- # Downloads a single attachment. Simply supply the unique identifier for the
19
- # required attachment.
21
+ # Downloads a single attachment.
20
22
  #
21
- # @param id The identifier of the attachment to be downloaded.
23
+ # @param id [String] The identifier for the required attachment.
22
24
  #
23
- # @return [NOT_IMPLEMENTED] operation results.
25
+ # @return [String] The attachment's binary content.
24
26
  #
25
27
  def get_attachment(id)
26
28
  response = conn.get "api/files/attachments/#{id}"
@@ -29,14 +31,11 @@ module Mailosaur
29
31
  end
30
32
 
31
33
  #
32
- # Download EML
34
+ # Downloads an EML file representing the specified email.
33
35
  #
34
- # Downloads an EML file representing the specified email. Simply supply the
35
- # unique identifier for the required email.
36
+ # @param id [String] The identifier for the required message.
36
37
  #
37
- # @param id The identifier of the email to be downloaded.
38
- #
39
- # @return [NOT_IMPLEMENTED] operation results.
38
+ # @return [String] The raw EML content of the email.
40
39
  #
41
40
  def get_email(id)
42
41
  response = conn.get "api/files/email/#{id}"
@@ -44,20 +43,21 @@ module Mailosaur
44
43
  response.body
45
44
  end
46
45
 
47
- #
48
- # Download an email preview
49
46
  #
50
47
  # Downloads a screenshot of your email rendered in a real email client. Simply supply
51
48
  # the unique identifier for the required preview.
52
49
  #
53
- # @param id The identifier of the email preview to be downloaded.
50
+ # @param id [String] The identifier of the email preview to be downloaded.
54
51
  #
55
- # @return [NOT_IMPLEMENTED] operation results.
52
+ # @return [String] The preview screenshot image content.
53
+ #
54
+ # @raise [Mailosaur::MailosaurError] With error code +preview_timeout+ if the preview is
55
+ # not generated within the time limit.
56
56
  #
57
57
  def get_preview(id)
58
58
  timeout = 120_000
59
59
  poll_count = 0
60
- start_time = Time.now.to_f
60
+ start_time = now
61
61
 
62
62
  loop do
63
63
  response = conn.get "api/files/screenshots/#{id}"
@@ -66,14 +66,11 @@ module Mailosaur
66
66
 
67
67
  @handle_http_error.call(response) unless response.status == 202
68
68
 
69
- delay_pattern = (response.headers['x-ms-delay'] || '1000').split(',').map(&:to_i)
70
-
71
- delay = poll_count >= delay_pattern.length ? delay_pattern[delay_pattern.length - 1] : delay_pattern[poll_count]
72
-
69
+ delay = poll_delay(response.headers['x-ms-delay'], poll_count)
73
70
  poll_count += 1
74
71
 
75
72
  ## Stop if timeout will be exceeded
76
- if ((1000 * (Time.now.to_f - start_time).to_i) + delay) > timeout
73
+ if ((now - start_time) * 1000) + delay > timeout
77
74
  msg = format('An email preview was not generated in time. The email client may not be available, or the preview ID [%s] may be incorrect.', id)
78
75
  raise Mailosaur::MailosaurError.new(msg, 'preview_timeout')
79
76
  end
@@ -1,10 +1,15 @@
1
1
  require 'uri'
2
2
 
3
3
  module Mailosaur
4
+ # Operations for finding, retrieving, creating, forwarding, replying to, and deleting the
5
+ # email and SMS messages received by your Mailosaur inboxes (servers). Accessed via +client.messages+.
4
6
  class Messages
7
+ include Polling
8
+
5
9
  #
6
10
  # Creates and initializes a new instance of the Messages class.
7
- # @param client connection.
11
+ # @param conn [Faraday::Connection] The client connection.
12
+ # @param handle_http_error [Method] Callback used to convert HTTP error responses into errors.
8
13
  #
9
14
  def initialize(conn, handle_http_error)
10
15
  @conn = conn
@@ -15,22 +20,24 @@ module Mailosaur
15
20
  attr_reader :conn
16
21
 
17
22
  #
18
- # Retrieve a message using search criteria
19
- #
20
- # Returns as soon as a message matching the specified search criteria is
21
- # found. This is the most efficient method of looking up a message.
23
+ # Waits for a message to be found. Returns as soon as a message matching the specified
24
+ # search criteria is found. This is the most efficient method of looking up a message,
25
+ # therefore we recommend using it wherever possible.
22
26
  #
23
- # @param server [String] The identifier of the server hosting the message.
24
- # @param criteria [SearchCriteria] The search criteria to use in order to find
25
- # a match.
27
+ # @param server [String] The unique identifier of the containing inbox (server).
28
+ # @param criteria [Mailosaur::Models::SearchCriteria] The criteria with which to find
29
+ # messages during a search.
26
30
  # @param timeout [Integer] Specify how long to wait for a matching result
27
- # (in milliseconds).
31
+ # (in milliseconds).
28
32
  # @param received_after [DateTime] Limits results to only messages received
29
- # after this date/time.
30
- # @param dir [String] Optionally limits results based on the direction (`Sent`
31
- # or `Received`), with the default being `Received`.
33
+ # after this date/time.
34
+ # @param dir [String] Optionally limits results based on the direction (+Sent+
35
+ # or +Received+), with the default being +Received+.
32
36
  #
33
- # @return [Message] operation results.
37
+ # @return [Mailosaur::Models::Message] The first message matching the criteria.
38
+ #
39
+ # @raise [Mailosaur::MailosaurError] With error code +no_messages_found+ if no matching
40
+ # message exists, or +search_timeout+ if no matching message arrives before the timeout elapses.
34
41
  #
35
42
  def get(server, criteria, timeout: 10_000, received_after: DateTime.now - (1.0 / 24), dir: nil)
36
43
  # Defaults timeout to 10s, receivedAfter to 1h
@@ -41,14 +48,12 @@ module Mailosaur
41
48
  end
42
49
 
43
50
  #
44
- # Retrieve a message
45
- #
46
- # Retrieves the detail for a single email message. Simply supply the unique
47
- # identifier for the required message.
51
+ # Retrieves the detail for a single message. Must be used in conjunction with either
52
+ # {#list} or {#search} in order to get the unique identifier for the required message.
48
53
  #
49
- # @param id The identifier of the email message to be retrieved.
54
+ # @param id [String] The unique identifier of the message to be retrieved.
50
55
  #
51
- # @return [Message] operation results.
56
+ # @return [Mailosaur::Models::Message] The full message.
52
57
  #
53
58
  def get_by_id(id)
54
59
  response = conn.get "api/messages/#{id}"
@@ -58,12 +63,12 @@ module Mailosaur
58
63
  end
59
64
 
60
65
  #
61
- # Delete a message
66
+ # Permanently deletes a message. Also deletes any attachments related to the message.
67
+ # This operation cannot be undone.
62
68
  #
63
- # Permanently deletes a message. This operation cannot be undone. Also deletes
64
- # any attachments related to the message.
69
+ # @param id [String] The identifier for the message.
65
70
  #
66
- # @param id The identifier of the message to be deleted.
71
+ # @return [nil] Once the message has been deleted.
67
72
  #
68
73
  def delete(id)
69
74
  response = conn.delete "api/messages/#{id}"
@@ -71,24 +76,22 @@ module Mailosaur
71
76
  nil
72
77
  end
73
78
 
74
- #
75
- # List all messages
76
79
  #
77
80
  # Returns a list of your messages in summary form. The summaries are returned
78
81
  # sorted by received date, with the most recently-received messages appearing
79
82
  # first.
80
83
  #
81
- # @param server [String] The identifier of the server hosting the messages.
82
- # @param page [Integer] Used in conjunction with `itemsPerPage` to support
83
- # pagination.
84
+ # @param server [String] The unique identifier of the required inbox (server).
85
+ # @param page [Integer] Used in conjunction with +items_per_page+ to support
86
+ # pagination.
84
87
  # @param items_per_page [Integer] A limit on the number of results to be
85
- # returned per page. Can be set between 1 and 1000 items, the default is 50.
88
+ # returned per page. Can be set between 1 and 1000 items, the default is 50.
86
89
  # @param received_after [DateTime] Limits results to only messages received
87
- # after this date/time.
88
- # @param dir [String] Optionally limits results based on the direction (`Sent`
89
- # or `Received`), with the default being `Received`.
90
+ # after this date/time.
91
+ # @param dir [String] Optionally limits results based on the direction (+Sent+
92
+ # or +Received+), with the default being +Received+.
90
93
  #
91
- # @return [MessageListResult] operation results.
94
+ # @return [Mailosaur::Models::MessageListResult] The message summaries.
92
95
  #
93
96
  def list(server, page: nil, items_per_page: nil, received_after: nil, dir: nil)
94
97
  url = "api/messages?server=#{server}"
@@ -106,12 +109,11 @@ module Mailosaur
106
109
  end
107
110
 
108
111
  #
109
- # Delete all messages
112
+ # Permanently delete all messages within an inbox (server). This operation cannot be undone.
110
113
  #
111
- # Permanently deletes all messages held by the specified server. This operation
112
- # cannot be undone. Also deletes any attachments related to each message.
114
+ # @param server [String] The unique identifier of the inbox (server).
113
115
  #
114
- # @param server [String] The identifier of the server to be emptied.
116
+ # @return [nil] Once all messages within the inbox (server) have been deleted.
115
117
  #
116
118
  def delete_all(server)
117
119
  response = conn.delete "api/messages?server=#{server}"
@@ -119,30 +121,31 @@ module Mailosaur
119
121
  nil
120
122
  end
121
123
 
122
- #
123
- # Search for messages
124
124
  #
125
125
  # Returns a list of messages matching the specified search criteria, in summary
126
126
  # form. The messages are returned sorted by received date, with the most
127
127
  # recently-received messages appearing first.
128
128
  #
129
- # @param server [String] The identifier of the server hosting the messages.
130
- # @param criteria [SearchCriteria] The search criteria to match results
131
- # against.
132
- # @param page [Integer] Used in conjunction with `itemsPerPage` to support
133
- # pagination.
129
+ # @param server [String] The unique identifier of the inbox (server) to search.
130
+ # @param criteria [Mailosaur::Models::SearchCriteria] The criteria with which to find
131
+ # messages during a search.
132
+ # @param page [Integer] Used in conjunction with +items_per_page+ to support
133
+ # pagination.
134
134
  # @param items_per_page [Integer] A limit on the number of results to be
135
- # returned per page. Can be set between 1 and 1000 items, the default is 50.
135
+ # returned per page. Can be set between 1 and 1000 items, the default is 50.
136
136
  # @param timeout [Integer] Specify how long to wait for a matching result
137
- # (in milliseconds).
137
+ # (in milliseconds).
138
138
  # @param received_after [DateTime] Limits results to only messages received
139
- # after this date/time.
139
+ # after this date/time.
140
140
  # @param error_on_timeout [Boolean] When set to false, an error will not be
141
- # throw if timeout is reached (default: true).
142
- # @param dir [String] Optionally limits results based on the direction (`Sent`
143
- # or `Received`), with the default being `Received`.
141
+ # raised if the timeout is reached (default: true).
142
+ # @param dir [String] Optionally limits results based on the direction (+Sent+
143
+ # or +Received+), with the default being +Received+.
144
+ #
145
+ # @return [Mailosaur::Models::MessageListResult] The matching message summaries.
144
146
  #
145
- # @return [MessageListResult] operation results.
147
+ # @raise [Mailosaur::MailosaurError] With error code +search_timeout+ if no matching message
148
+ # is found before the timeout elapses, unless +error_on_timeout+ is set to false.
146
149
  #
147
150
  def search(server, criteria, page: nil, items_per_page: nil, timeout: nil, received_after: nil, error_on_timeout: true, dir: nil)
148
151
  url = "api/messages/search?server=#{server}"
@@ -152,7 +155,7 @@ module Mailosaur
152
155
  url += dir ? "&dir=#{dir}" : ''
153
156
 
154
157
  poll_count = 0
155
- start_time = Time.now.to_f
158
+ start_time = now
156
159
 
157
160
  loop do
158
161
  response = conn.post url, criteria.to_json
@@ -162,14 +165,11 @@ module Mailosaur
162
165
  model = JSON.parse(response.body)
163
166
  return Mailosaur::Models::MessageListResult.new(model) if timeout.to_i.zero? || !model['items'].empty?
164
167
 
165
- delay_pattern = (response.headers['x-ms-delay'] || '1000').split(',').map(&:to_i)
166
-
167
- delay = poll_count >= delay_pattern.length ? delay_pattern[delay_pattern.length - 1] : delay_pattern[poll_count]
168
-
168
+ delay = poll_delay(response.headers['x-ms-delay'], poll_count)
169
169
  poll_count += 1
170
170
 
171
171
  ## Stop if timeout will be exceeded
172
- if ((1000 * (Time.now.to_f - start_time).to_i) + delay) > timeout
172
+ if ((now - start_time) * 1000) + delay > timeout
173
173
  return Mailosaur::Models::MessageListResult.new(model) unless error_on_timeout
174
174
 
175
175
  msg = format('No matching messages found in time. By default, only messages received in the last hour are checked (use receivedAfter to override this). The search criteria used for this query was [%s] which timed out after %sms',
@@ -177,21 +177,20 @@ module Mailosaur
177
177
  raise Mailosaur::MailosaurError.new(msg, 'search_timeout')
178
178
  end
179
179
 
180
- sleep(delay / 1000)
180
+ sleep(delay / 1000.0)
181
181
  end
182
182
  end
183
183
 
184
- #
185
- # Create a message.
186
184
  #
187
185
  # Creates a new message that can be sent to a verified email address. This is
188
186
  # useful in scenarios where you want an email to trigger a workflow in your
189
- # product
187
+ # product.
190
188
  #
191
- # @param server [String] The identifier of the server to create the message in.
192
- # @param options [MessageCreateOptions] The options with which to create the message.
189
+ # @param server [String] The unique identifier of the required inbox (server).
190
+ # @param message_create_options [Mailosaur::Models::MessageCreateOptions] Options to use
191
+ # when creating a new message.
193
192
  #
194
- # @return [Message] operation result.
193
+ # @return [Mailosaur::Models::Message] The newly-created message.
195
194
  #
196
195
  def create(server, message_create_options)
197
196
  response = conn.post "api/messages?server=#{server}", message_create_options.to_json
@@ -201,15 +200,14 @@ module Mailosaur
201
200
  end
202
201
 
203
202
  #
204
- # Forward an email.
203
+ # Forwards the specified message to a verified email address. This is useful for
204
+ # simulating a user forwarding one of your email messages.
205
205
  #
206
- # Forwards the specified email to a verified email address.
206
+ # @param id [String] The unique identifier of the message to be forwarded.
207
+ # @param message_forward_options [Mailosaur::Models::MessageForwardOptions] Options to use
208
+ # when forwarding a message.
207
209
  #
208
- # @param id [String] The identifier of the email to forward.
209
- # @param options [MessageForwardOptions] The options with which to forward the email.
210
- # against.
211
- #
212
- # @return [Message] operation result.
210
+ # @return [Mailosaur::Models::Message] The forwarded message.
213
211
  #
214
212
  def forward(id, message_forward_options)
215
213
  response = conn.post "api/messages/#{id}/forward", message_forward_options.to_json
@@ -219,16 +217,14 @@ module Mailosaur
219
217
  end
220
218
 
221
219
  #
222
- # Reply to an email.
223
- #
224
- # Sends a reply to the specified email. This is useful for when simulating a user
225
- # replying to one of your emails.
220
+ # Sends a reply to the specified message. This is useful for when simulating a user
221
+ # replying to one of your email or SMS messages.
226
222
  #
227
- # @param id [String] The identifier of the email to reply to.
228
- # @param options [MessageReplyOptions] The options with which to reply to the email.
229
- # against.
223
+ # @param id [String] The unique identifier of the message to be replied to.
224
+ # @param message_reply_options [Mailosaur::Models::MessageReplyOptions] Options to use
225
+ # when replying to a message.
230
226
  #
231
- # @return [Message] operation result.
227
+ # @return [Mailosaur::Models::Message] The reply message.
232
228
  #
233
229
  def reply(id, message_reply_options)
234
230
  response = conn.post "api/messages/#{id}/reply", message_reply_options.to_json
@@ -237,15 +233,14 @@ module Mailosaur
237
233
  Mailosaur::Models::Message.new(model)
238
234
  end
239
235
 
240
- #
241
- # Generate email previews.
242
236
  #
243
237
  # Generates screenshots of an email rendered in the specified email clients.
244
238
  #
245
239
  # @param id [String] The identifier of the email to preview.
246
- # @param options [PreviewRequestOptions] The options with which to generate previews.
240
+ # @param options [Mailosaur::Models::PreviewRequestOptions] The options with which to
241
+ # generate previews.
247
242
  #
248
- # @return [PreviewListResult] operation result.
243
+ # @return [Mailosaur::Models::PreviewListResult] The generated previews.
249
244
  #
250
245
  def generate_previews(id, options)
251
246
  response = conn.post "api/messages/#{id}/screenshots", options.to_json
@@ -63,7 +63,7 @@ module Mailosaur
63
63
  # @return [Metadata]
64
64
  attr_accessor :metadata
65
65
 
66
- # @return [String] Identifier for the server in which the message is
66
+ # @return [String] Identifier for the inbox (server) in which the message is
67
67
  # located.
68
68
  attr_accessor :server
69
69
  end
@@ -8,17 +8,17 @@ module Mailosaur
8
8
  @messages = data['messages']
9
9
  end
10
10
 
11
- # @return [String] Unique identifier for the server. Used as username for
11
+ # @return [String] Unique identifier for the inbox (server). Used as username for
12
12
  # SMTP/POP3 authentication.
13
13
  attr_accessor :id
14
14
 
15
- # @return [String] A name used to identify the server.
15
+ # @return [String] A name used to identify the inbox (server).
16
16
  attr_accessor :name
17
17
 
18
- # @return Users (excluding administrators) who have access to the server.
18
+ # @return Users (excluding administrators) who have access to the inbox (server) when access is restricted.
19
19
  attr_accessor :users
20
20
 
21
- # @return [Integer] The number of messages currently in the server.
21
+ # @return [Integer] The number of messages currently in the inbox (server).
22
22
  attr_accessor :messages
23
23
  end
24
24
  end
@@ -5,7 +5,7 @@ module Mailosaur
5
5
  @name = data['name']
6
6
  end
7
7
 
8
- # @return [String] A name used to identify the server.
8
+ # @return [String] A name used to identify the inbox (server).
9
9
  attr_accessor :name
10
10
  end
11
11
  end
@@ -6,9 +6,9 @@ module Mailosaur
6
6
  (data['items'] || []).each do |i| @items << Mailosaur::Models::Server.new(i) end
7
7
  end
8
8
 
9
- # @return [Array<Server>] The individual servers forming the result.
10
- # Servers are returned sorted by creation date, with the most
11
- # recently-created server appearing first.
9
+ # @return [Array<Server>] The individual inboxes (servers) forming the result.
10
+ # Inboxes (servers) are returned sorted by creation date, with the most
11
+ # recently-created inbox (server) appearing first.
12
12
  attr_accessor :items
13
13
  end
14
14
  end
@@ -0,0 +1,19 @@
1
+ module Mailosaur
2
+ module Polling
3
+ private
4
+
5
+ def poll_delay(header, poll_count)
6
+ entries = header.to_s.split(',', -1).map(&:strip)
7
+ return 1000 if entries.empty?
8
+
9
+ entry = entries[[poll_count, entries.length - 1].min]
10
+ entry.match?(/\A\d+\z/) ? entry.to_i : 1000
11
+ end
12
+
13
+ def now
14
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
15
+ end
16
+ end
17
+
18
+ private_constant :Polling
19
+ end
@@ -1,8 +1,11 @@
1
1
  module Mailosaur
2
+ # Operations for discovering the email clients available for generating email previews
3
+ # (screenshots of an email rendered in real clients). Accessed via +client.previews+.
2
4
  class Previews
3
5
  #
4
6
  # Creates and initializes a new instance of the Previews class.
5
- # @param client connection.
7
+ # @param conn [Faraday::Connection] The client connection.
8
+ # @param handle_http_error [Method] Callback used to convert HTTP error responses into errors.
6
9
  #
7
10
  def initialize(conn, handle_http_error)
8
11
  @conn = conn
@@ -15,9 +18,7 @@ module Mailosaur
15
18
  #
16
19
  # List all email clients that can be used to generate email previews.
17
20
  #
18
- # Returns a list of available email clients.
19
- #
20
- # @return [EmailClientListResult] operation results.
21
+ # @return [Mailosaur::Models::EmailClientListResult] The available email clients.
21
22
  #
22
23
  def list_email_clients
23
24
  response = conn.get 'api/screenshots/clients'
@@ -1,8 +1,12 @@
1
1
  module Mailosaur
2
+ # Operations for creating and managing your Mailosaur inboxes (servers) — they
3
+ # group your tests together, each with its own domain and SMTP/POP3/IMAP credentials.
4
+ # Accessed via +client.servers+.
2
5
  class Servers
3
6
  #
4
7
  # Creates and initializes a new instance of the Servers class.
5
- # @param client connection.
8
+ # @param conn [Faraday::Connection] The client connection.
9
+ # @param handle_http_error [Method] Callback used to convert HTTP error responses into errors.
6
10
  #
7
11
  def initialize(conn, handle_http_error)
8
12
  @conn = conn
@@ -13,12 +17,10 @@ module Mailosaur
13
17
  attr_reader :conn
14
18
 
15
19
  #
16
- # List all servers
17
- #
18
- # Returns a list of your virtual SMTP servers. Servers are returned sorted in
20
+ # Returns a list of your inboxes (servers). Inboxes (servers) are returned sorted in
19
21
  # alphabetical order.
20
22
  #
21
- # @return [ServerListResult] operation results.
23
+ # @return [Mailosaur::Models::ServerListResult] Your inboxes (servers).
22
24
  #
23
25
  def list
24
26
  response = conn.get 'api/servers'
@@ -28,13 +30,12 @@ module Mailosaur
28
30
  end
29
31
 
30
32
  #
31
- # Create a server
32
- #
33
- # Creates a new virtual SMTP server and returns it.
33
+ # Creates a new inbox (server).
34
34
  #
35
- # @param server_create_options [ServerCreateOptions]
35
+ # @param server_create_options [Mailosaur::Models::ServerCreateOptions] Options used to
36
+ # create a new Mailosaur inbox (server).
36
37
  #
37
- # @return [Server] operation results.
38
+ # @return [Mailosaur::Models::Server] The newly-created inbox (server).
38
39
  #
39
40
  def create(server_create_options)
40
41
  response = conn.post 'api/servers', server_create_options.to_json
@@ -44,14 +45,11 @@ module Mailosaur
44
45
  end
45
46
 
46
47
  #
47
- # Retrieve a server
48
- #
49
- # Retrieves the detail for a single server. Simply supply the unique identifier
50
- # for the required server.
48
+ # Retrieves the detail for a single inbox (server).
51
49
  #
52
- # @param id [String] The identifier of the server to be retrieved.
50
+ # @param id [String] The unique identifier of the inbox (server).
53
51
  #
54
- # @return [Server] operation results.
52
+ # @return [Mailosaur::Models::Server] The inbox (server).
55
53
  #
56
54
  def get(id)
57
55
  response = conn.get "api/servers/#{id}"
@@ -61,14 +59,12 @@ module Mailosaur
61
59
  end
62
60
 
63
61
  #
64
- # Retrieve server password
62
+ # Retrieves the password for an inbox (server). This password can be used for SMTP, POP3, and
63
+ # IMAP connectivity.
65
64
  #
66
- # Retrieves the password for use with SMTP and POP3 for a single server.
67
- # Simply supply the unique identifier for the required server.
65
+ # @param id [String] The unique identifier of the inbox (server).
68
66
  #
69
- # @param id [String] The identifier of the server.
70
- #
71
- # @return [String] Server password.
67
+ # @return [String] The password for the inbox (server).
72
68
  #
73
69
  def get_password(id)
74
70
  response = conn.get "api/servers/#{id}/password"
@@ -78,14 +74,12 @@ module Mailosaur
78
74
  end
79
75
 
80
76
  #
81
- # Update a server
82
- #
83
- # Updats a single server and returns it.
77
+ # Updates the attributes of an inbox (server).
84
78
  #
85
- # @param id [String] The identifier of the server to be updated.
86
- # @param server [Server]
79
+ # @param id [String] The unique identifier of the inbox (server).
80
+ # @param server [Mailosaur::Models::Server] The updated inbox (server).
87
81
  #
88
- # @return [Server] operation results.
82
+ # @return [Mailosaur::Models::Server] The updated inbox (server).
89
83
  #
90
84
  def update(id, server)
91
85
  response = conn.put "api/servers/#{id}", server.to_json
@@ -95,12 +89,12 @@ module Mailosaur
95
89
  end
96
90
 
97
91
  #
98
- # Delete a server
92
+ # Permanently delete an inbox (server). This will also delete all messages, associated attachments,
93
+ # etc. within the inbox (server). This operation cannot be undone.
99
94
  #
100
- # Permanently deletes a server. This operation cannot be undone. Also deletes
101
- # all messages and associated attachments within the server.
95
+ # @param id [String] The unique identifier of the inbox (server).
102
96
  #
103
- # @param id [String] The identifier of the server to be deleted.
97
+ # @return [nil] Once the inbox (server) has been deleted.
104
98
  #
105
99
  def delete(id)
106
100
  response = conn.delete "api/servers/#{id}"
@@ -108,6 +102,14 @@ module Mailosaur
108
102
  nil
109
103
  end
110
104
 
105
+ #
106
+ # Generates a random email address by appending a random string in front of the
107
+ # domain name of the inbox (server).
108
+ #
109
+ # @param server [String] The identifier of the inbox (server).
110
+ #
111
+ # @return [String] A random email address ending in the domain of the inbox (server).
112
+ #
111
113
  def generate_email_address(server)
112
114
  host = ENV['MAILOSAUR_SMTP_HOST'] || 'mailosaur.net'
113
115
  format('%s@%s.%s', SecureRandom.hex(3), server, host)
@@ -1,8 +1,11 @@
1
1
  module Mailosaur
2
+ # Operations for inspecting your account's usage limits and recent transactional usage.
3
+ # These endpoints require authentication with an account-level API key. Accessed via +client.usage+.
2
4
  class Usage
3
5
  #
4
6
  # Creates and initializes a new instance of the Usage class.
5
- # @param client connection.
7
+ # @param conn [Faraday::Connection] The client connection.
8
+ # @param handle_http_error [Method] Callback used to convert HTTP error responses into errors.
6
9
  #
7
10
  def initialize(conn, handle_http_error)
8
11
  @conn = conn
@@ -13,11 +16,10 @@ module Mailosaur
13
16
  attr_reader :conn
14
17
 
15
18
  #
16
- # Retrieve account usage limits.
19
+ # Retrieve account usage limits. Details the current limits and usage for your account.
20
+ # This endpoint requires authentication with an account-level API key.
17
21
  #
18
- # Details the current limits and usage for your account.
19
- #
20
- # @return [UsageAccountLimits] operation results.
22
+ # @return [Mailosaur::Models::UsageAccountLimits] The usage limits for your account.
21
23
  #
22
24
  def limits
23
25
  response = conn.get 'api/usage/limits'
@@ -27,9 +29,10 @@ module Mailosaur
27
29
  end
28
30
 
29
31
  #
30
- # List account transactions. Retrieves the last 31 days of transactional usage.
32
+ # Retrieves the last 31 days of transactional usage.
33
+ # This endpoint requires authentication with an account-level API key.
31
34
  #
32
- # @return [UsageTransactionListResult] operation results.
35
+ # @return [Mailosaur::Models::UsageTransactionListResult] The transactional usage for the last 31 days.
33
36
  #
34
37
  def transactions
35
38
  response = conn.get 'api/usage/transactions'
@@ -1,3 +1,3 @@
1
1
  module Mailosaur
2
- VERSION = '8.1.0'.freeze
2
+ VERSION = '8.2.0'.freeze
3
3
  end
data/lib/mailosaur.rb CHANGED
@@ -17,6 +17,7 @@ module Mailosaur
17
17
  autoload :Devices, 'Mailosaur/devices.rb'
18
18
  autoload :Previews, 'Mailosaur/previews.rb'
19
19
  autoload :MailosaurError, 'Mailosaur/mailosaur_error.rb'
20
+ autoload :Polling, 'Mailosaur/polling.rb'
20
21
 
21
22
  module Models
22
23
  autoload :MessageHeader, 'Mailosaur/models/message_header.rb'
@@ -62,11 +63,16 @@ module Mailosaur
62
63
  autoload :BaseModel, 'Mailosaur/models/base_model.rb'
63
64
  end
64
65
 
66
+ # The Mailosaur client — the main entry point to the Mailosaur API. Construct an instance with
67
+ # your API key (or set the +MAILOSAUR_API_KEY+ environment variable), then use the operations
68
+ # namespaces (+messages+, +servers+, +files+, +devices+, +analysis+, +previews+, +usage+) to
69
+ # automate email and SMS testing.
65
70
  class MailosaurClient
66
71
  #
67
- # Creates initializes a new instance of the MailosaurClient class.
72
+ # Returns an instance of the Mailosaur client.
68
73
  # @param api_key [String] Optional API key. Overrides the MAILOSAUR_API_KEY environment variable if set.
69
- # @param base_url [String] the base URI of the service.
74
+ # @param base_url [String] Optionally overrides the base URL of the Mailosaur service.
75
+ # @raise [ArgumentError] If no API key is provided and the MAILOSAUR_API_KEY environment variable is not set.
70
76
  #
71
77
  def initialize(api_key = nil, base_url: 'https://mailosaur.com/')
72
78
  resolved_api_key = api_key || ENV['MAILOSAUR_API_KEY']
@@ -77,37 +83,44 @@ module Mailosaur
77
83
  @base_url = base_url
78
84
  end
79
85
 
80
- # @return [Analysis] analysis
86
+ # Operations for analyzing email content and deliverability, including spam scoring.
87
+ # @return [Analysis] the analysis operations namespace.
81
88
  def analysis
82
89
  @analysis ||= Analysis.new(connection, method(:handle_http_error))
83
90
  end
84
91
 
85
- # @return [Files] files
92
+ # Operations for downloading attachments, EML source, and email preview screenshots.
93
+ # @return [Files] the files operations namespace.
86
94
  def files
87
95
  @files ||= Files.new(connection, method(:handle_http_error))
88
96
  end
89
97
 
90
- # @return [Messages] messages
98
+ # Operations for finding, retrieving, creating, and managing email and SMS messages.
99
+ # @return [Messages] the messages operations namespace.
91
100
  def messages
92
101
  @messages ||= Messages.new(connection, method(:handle_http_error))
93
102
  end
94
103
 
95
- # @return [Servers] servers
104
+ # Operations for creating and managing your Mailosaur inboxes (servers).
105
+ # @return [Servers] the servers operations namespace.
96
106
  def servers
97
107
  @servers ||= Servers.new(connection, method(:handle_http_error))
98
108
  end
99
109
 
100
- # @return [Usage] usage
110
+ # Operations for inspecting account usage limits and recent transactional usage.
111
+ # @return [Usage] the usage operations namespace.
101
112
  def usage
102
113
  @usage ||= Usage.new(connection, method(:handle_http_error))
103
114
  end
104
115
 
105
- # @return [Devices] devices
116
+ # Operations for managing virtual security devices and retrieving their one-time passwords.
117
+ # @return [Devices] the devices operations namespace.
106
118
  def devices
107
119
  @devices ||= Devices.new(connection, method(:handle_http_error))
108
120
  end
109
121
 
110
- # @return [Previews] previews
122
+ # Operations for discovering the email clients available for generating email previews.
123
+ # @return [Previews] the previews operations namespace.
111
124
  def previews
112
125
  @previews ||= Previews.new(connection, method(:handle_http_error))
113
126
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailosaur
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.0
4
+ version: 8.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mailosaur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-03-06 00:00:00.000000000 Z
11
+ date: 2026-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -188,6 +188,7 @@ files:
188
188
  - lib/Mailosaur/models/usage_transaction.rb
189
189
  - lib/Mailosaur/models/usage_transaction_list_result.rb
190
190
  - lib/Mailosaur/module_definition.rb
191
+ - lib/Mailosaur/polling.rb
191
192
  - lib/Mailosaur/previews.rb
192
193
  - lib/Mailosaur/servers.rb
193
194
  - lib/Mailosaur/usage.rb