mailosaur 8.1.1 → 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 +4 -4
- data/lib/Mailosaur/files.rb +5 -6
- data/lib/Mailosaur/messages.rb +6 -7
- data/lib/Mailosaur/polling.rb +19 -0
- data/lib/Mailosaur/version.rb +1 -1
- data/lib/mailosaur.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9e15e690f564a4062f112f14a72bd49fe52bc7853875294af84010b65e40e2bb
|
|
4
|
+
data.tar.gz: ad66cd3aa1bc0a793e1e9021faf25d77d85b2a29a5db5e95785380b7114b6156
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7b963ba016116dbe06b0f4f55c665dd4eebfa3f24937f8001d4ca6c97c5ad69e97366d3b0b9c40b6fe36fb41f549fd9259edf13dd204497a2049f35e1e1002fc
|
|
7
|
+
data.tar.gz: 1124748868ababe49581fb9b98f3e10dfb442733f21cf98206c445582acb289dd12b64dec9bd873bfa153646a31287c4a3160cda596e12334828ec86775d8425
|
data/lib/Mailosaur/files.rb
CHANGED
|
@@ -2,6 +2,8 @@ module Mailosaur
|
|
|
2
2
|
# Operations for downloading the raw content associated with a message — file attachments,
|
|
3
3
|
# the full EML source of an email, and rendered email previews. Accessed via +client.files+.
|
|
4
4
|
class Files
|
|
5
|
+
include Polling
|
|
6
|
+
|
|
5
7
|
#
|
|
6
8
|
# Creates and initializes a new instance of the Files class.
|
|
7
9
|
# @param conn [Faraday::Connection] The client connection.
|
|
@@ -55,7 +57,7 @@ module Mailosaur
|
|
|
55
57
|
def get_preview(id)
|
|
56
58
|
timeout = 120_000
|
|
57
59
|
poll_count = 0
|
|
58
|
-
start_time =
|
|
60
|
+
start_time = now
|
|
59
61
|
|
|
60
62
|
loop do
|
|
61
63
|
response = conn.get "api/files/screenshots/#{id}"
|
|
@@ -64,14 +66,11 @@ module Mailosaur
|
|
|
64
66
|
|
|
65
67
|
@handle_http_error.call(response) unless response.status == 202
|
|
66
68
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
delay = poll_count >= delay_pattern.length ? delay_pattern[delay_pattern.length - 1] : delay_pattern[poll_count]
|
|
70
|
-
|
|
69
|
+
delay = poll_delay(response.headers['x-ms-delay'], poll_count)
|
|
71
70
|
poll_count += 1
|
|
72
71
|
|
|
73
72
|
## Stop if timeout will be exceeded
|
|
74
|
-
if ((
|
|
73
|
+
if ((now - start_time) * 1000) + delay > timeout
|
|
75
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)
|
|
76
75
|
raise Mailosaur::MailosaurError.new(msg, 'preview_timeout')
|
|
77
76
|
end
|
data/lib/Mailosaur/messages.rb
CHANGED
|
@@ -4,6 +4,8 @@ module Mailosaur
|
|
|
4
4
|
# Operations for finding, retrieving, creating, forwarding, replying to, and deleting the
|
|
5
5
|
# email and SMS messages received by your Mailosaur inboxes (servers). Accessed via +client.messages+.
|
|
6
6
|
class Messages
|
|
7
|
+
include Polling
|
|
8
|
+
|
|
7
9
|
#
|
|
8
10
|
# Creates and initializes a new instance of the Messages class.
|
|
9
11
|
# @param conn [Faraday::Connection] The client connection.
|
|
@@ -153,7 +155,7 @@ module Mailosaur
|
|
|
153
155
|
url += dir ? "&dir=#{dir}" : ''
|
|
154
156
|
|
|
155
157
|
poll_count = 0
|
|
156
|
-
start_time =
|
|
158
|
+
start_time = now
|
|
157
159
|
|
|
158
160
|
loop do
|
|
159
161
|
response = conn.post url, criteria.to_json
|
|
@@ -163,14 +165,11 @@ module Mailosaur
|
|
|
163
165
|
model = JSON.parse(response.body)
|
|
164
166
|
return Mailosaur::Models::MessageListResult.new(model) if timeout.to_i.zero? || !model['items'].empty?
|
|
165
167
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
delay = poll_count >= delay_pattern.length ? delay_pattern[delay_pattern.length - 1] : delay_pattern[poll_count]
|
|
169
|
-
|
|
168
|
+
delay = poll_delay(response.headers['x-ms-delay'], poll_count)
|
|
170
169
|
poll_count += 1
|
|
171
170
|
|
|
172
171
|
## Stop if timeout will be exceeded
|
|
173
|
-
if ((
|
|
172
|
+
if ((now - start_time) * 1000) + delay > timeout
|
|
174
173
|
return Mailosaur::Models::MessageListResult.new(model) unless error_on_timeout
|
|
175
174
|
|
|
176
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',
|
|
@@ -178,7 +177,7 @@ module Mailosaur
|
|
|
178
177
|
raise Mailosaur::MailosaurError.new(msg, 'search_timeout')
|
|
179
178
|
end
|
|
180
179
|
|
|
181
|
-
sleep(delay / 1000)
|
|
180
|
+
sleep(delay / 1000.0)
|
|
182
181
|
end
|
|
183
182
|
end
|
|
184
183
|
|
|
@@ -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
|
data/lib/Mailosaur/version.rb
CHANGED
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'
|
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.
|
|
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-
|
|
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
|