mailosaur 5.0.20 → 6.0.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/messages.rb +68 -39
- data/lib/Mailosaur/version.rb +1 -1
- data/lib/mailosaur.rb +3 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec06119b13b80148c1afc565e3aa3645d3784c2aec0772da7d2d43443b37cc18
|
4
|
+
data.tar.gz: d2fc23557ffab91c12b3bad70942212395f0d16beaf00feecf5f8914a8d77635
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c1212d6c8b230bb1944cd8066fd3498278206ddaae60c44844fc531ec11ddf9a6b800a34ce55403190f0fe873b51ffe30925904e4d7dd580ed7854ea18c2cf7
|
7
|
+
data.tar.gz: 6497b4bb404036491fe89bb5a3fb1e2c6ea81ae8e339e0ed986c69c0286a3852ffd535e97446c95a7ee765481782693c7d5a7ab69a78fb1f4b7a89400f516bca
|
data/lib/Mailosaur/messages.rb
CHANGED
@@ -12,6 +12,33 @@ module Mailosaur
|
|
12
12
|
# @return [Connection] the client connection.
|
13
13
|
attr_reader :conn
|
14
14
|
|
15
|
+
#
|
16
|
+
# Retrieve a message using search criteria
|
17
|
+
#
|
18
|
+
# Returns as soon as a message matching the specified search criteria is
|
19
|
+
# found. This is the most efficient method of looking up a message.
|
20
|
+
#
|
21
|
+
# @param server [String] The identifier of the server hosting the message.
|
22
|
+
# @param criteria [SearchCriteria] The search criteria to use in order to find
|
23
|
+
# a match.
|
24
|
+
# @param timeout [Integer] Specify how long to wait for a matching result
|
25
|
+
# (in milliseconds).
|
26
|
+
# @param received_after [DateTime] Limits results to only messages received
|
27
|
+
# after this date/time.
|
28
|
+
#
|
29
|
+
# @return [Message] operation results.
|
30
|
+
#
|
31
|
+
def get(server, criteria, timeout:10000, received_after:DateTime.now - (1.0/24))
|
32
|
+
# Defaults timeout to 10s, receivedAfter to 1h
|
33
|
+
if server.length > 8
|
34
|
+
raise Mailosaur::MailosaurError.new('Use get_by_id to retrieve a message using its identifier', nil)
|
35
|
+
end
|
36
|
+
|
37
|
+
result = search(server, criteria, timeout:timeout, received_after:received_after)
|
38
|
+
return get_by_id(result.items[0].id)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
15
42
|
#
|
16
43
|
# Retrieve a message
|
17
44
|
#
|
@@ -22,7 +49,7 @@ module Mailosaur
|
|
22
49
|
#
|
23
50
|
# @return [Message] operation results.
|
24
51
|
#
|
25
|
-
def
|
52
|
+
def get_by_id(id)
|
26
53
|
response = conn.get 'api/messages/' + id
|
27
54
|
|
28
55
|
unless response.status == 200
|
@@ -121,49 +148,51 @@ module Mailosaur
|
|
121
148
|
# pagination.
|
122
149
|
# @param items_per_page [Integer] A limit on the number of results to be
|
123
150
|
# returned per page. Can be set between 1 and 1000 items, the default is 50.
|
151
|
+
# @param timeout [Integer] Specify how long to wait for a matching result
|
152
|
+
# (in milliseconds).
|
153
|
+
# @param received_after [DateTime] Limits results to only messages received
|
154
|
+
# after this date/time.
|
124
155
|
#
|
125
156
|
# @return [MessageListResult] operation results.
|
126
157
|
#
|
127
|
-
def search(server, criteria, page:nil, items_per_page:nil)
|
158
|
+
def search(server, criteria, page:nil, items_per_page:nil, timeout:nil, received_after:nil)
|
128
159
|
url = 'api/messages/search?server=' + server
|
129
|
-
url += page ? '&page=' + page : ''
|
130
|
-
url += items_per_page ? '&itemsPerPage=' + items_per_page : ''
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
160
|
+
url += page ? '&page=' + page.to_s : ''
|
161
|
+
url += items_per_page ? '&itemsPerPage=' + items_per_page.to_s : ''
|
162
|
+
url += received_after ? '&receivedAfter=' + received_after.iso8601 : ''
|
163
|
+
|
164
|
+
poll_count = 0
|
165
|
+
start_time = Time.now.to_f
|
166
|
+
|
167
|
+
loop do
|
168
|
+
response = conn.post url, criteria.to_json
|
169
|
+
|
170
|
+
unless response.status == 200
|
171
|
+
error_model = JSON.load(response.body)
|
172
|
+
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
|
173
|
+
raise mailosaur_error
|
174
|
+
end
|
175
|
+
|
176
|
+
model = JSON.load(response.body)
|
177
|
+
if timeout.to_i == 0 || model['items'].length != 0
|
178
|
+
return Mailosaur::Models::MessageListResult.new(model)
|
179
|
+
end
|
180
|
+
|
181
|
+
delay_pattern = (response.headers['x-ms-delay'] || '1000').split(',').map{ |x| x.to_i }
|
182
|
+
|
183
|
+
delay = poll_count >= delay_pattern.length ?
|
184
|
+
delay_pattern[delay_pattern.length - 1] :
|
185
|
+
delay_pattern[poll_count]
|
186
|
+
|
187
|
+
poll_count += 1
|
188
|
+
|
189
|
+
## Stop if timeout will be exceeded
|
190
|
+
if ((1000 * (Time.now.to_f - start_time).to_i) + delay) > timeout
|
191
|
+
raise Mailosaur::MailosaurError.new('No matching messages were found in time', nil)
|
192
|
+
end
|
193
|
+
|
194
|
+
sleep (delay / 1000)
|
163
195
|
end
|
164
|
-
|
165
|
-
model = JSON.load(response.body)
|
166
|
-
Mailosaur::Models::Message.new(model)
|
167
196
|
end
|
168
197
|
end
|
169
198
|
end
|
data/lib/Mailosaur/version.rb
CHANGED
data/lib/mailosaur.rb
CHANGED
@@ -6,6 +6,7 @@ require 'securerandom'
|
|
6
6
|
require 'time'
|
7
7
|
require 'faraday'
|
8
8
|
require 'Mailosaur/module_definition'
|
9
|
+
require 'Mailosaur/version'
|
9
10
|
|
10
11
|
module Mailosaur
|
11
12
|
autoload :Analysis, 'Mailosaur/analysis.rb'
|
@@ -33,7 +34,7 @@ module Mailosaur
|
|
33
34
|
autoload :ServerListResult, 'Mailosaur/models/server_list_result.rb'
|
34
35
|
autoload :SpamFilterResults, 'Mailosaur/models/spam_filter_results.rb'
|
35
36
|
autoload :ServerCreateOptions, 'Mailosaur/models/server_create_options.rb'
|
36
|
-
autoload :BaseModel,
|
37
|
+
autoload :BaseModel, 'Mailosaur/models/base_model.rb'
|
37
38
|
end
|
38
39
|
|
39
40
|
class MailosaurClient
|
@@ -58,7 +59,7 @@ autoload :BaseModel, 'Mailosaur/mod
|
|
58
59
|
conn = Faraday.new(base_url || 'https://mailosaur.com/', {
|
59
60
|
:headers => {
|
60
61
|
:content_type => 'application/json; charset=utf-8',
|
61
|
-
:user_agent => 'mailosaur-ruby/
|
62
|
+
:user_agent => 'mailosaur-ruby/' + Mailosaur::VERSION
|
62
63
|
}
|
63
64
|
})
|
64
65
|
|
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:
|
4
|
+
version: 6.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mailosaur Ltd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -184,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
184
|
- !ruby/object:Gem::Version
|
185
185
|
version: '0'
|
186
186
|
requirements: []
|
187
|
-
rubygems_version: 3.0.
|
187
|
+
rubygems_version: 3.0.4
|
188
188
|
signing_key:
|
189
189
|
specification_version: 4
|
190
190
|
summary: Ruby client library for Mailosaur
|