mailosaur 8.1.1 → 8.2.1

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: 073b2f6c745fe6ad8d815c0039bfcc8a39547a805c6615a00b037ca1ec415760
4
- data.tar.gz: e6427526ae18e2bb269ec25a37149e4f74c2b1ef36d4b71dc13f6b1e70f98bc4
3
+ metadata.gz: 0a2502a574b04e3127bedfe08d3f2f6b6b9b1c82897becb48633010fbb3dcd60
4
+ data.tar.gz: ff8c32621a30213b922079d32453c932b9979074d16c63b4c92a35f8bcda40d2
5
5
  SHA512:
6
- metadata.gz: 886ccbcd88720e84729cbad7259d4a71436610710e7123ca1f5b4993852a8721ce4ba6a7d55849cbeb8d058f8e5098e3c610b97d08651b6c8791d847e6f6fbd1
7
- data.tar.gz: d24a3505d18503da0a53790e0237c93e74a744657db5aeba4ae47e7936b61fadf6aa4771ff67bc0c355762f83f425fc4bd08ca09f2fcbb6a1eceb7af236dbe24
6
+ metadata.gz: 03c5fa1d3d9ec4c01049d28ce5d78ef042cedfa8f77a08ed4dc5921ebd1d356ed9cbb68bbc1a519631b0a28245e2cdb655cec5a89c62b3b9784913f2bbb215e0
7
+ data.tar.gz: 62a076881660b02a71c7eb62e7c11ddc7bb091b65ba477dc7460ad88f53d764b71ac83a8ce6bd3f23c96d8bce5c799d0a3b4515451f8879e1884f94c0e802d26
@@ -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 = Time.now.to_f
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
- delay_pattern = (response.headers['x-ms-delay'] || '1000').split(',').map(&:to_i)
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 ((1000 * (Time.now.to_f - start_time).to_i) + delay) > timeout
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
@@ -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 = Time.now.to_f
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
- delay_pattern = (response.headers['x-ms-delay'] || '1000').split(',').map(&:to_i)
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 ((1000 * (Time.now.to_f - start_time).to_i) + delay) > timeout
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
@@ -1,3 +1,3 @@
1
1
  module Mailosaur
2
- VERSION = '8.1.1'.freeze
2
+ VERSION = '8.2.1'.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'
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.1
4
+ version: 8.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mailosaur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-05-27 00:00:00.000000000 Z
11
+ date: 2026-12-05 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