mailosaur 5.0.2 → 5.0.20
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 +5 -5
- data/LICENSE +1 -1
- data/README.md +0 -39
- data/lib/Mailosaur/analysis.rb +14 -161
- data/lib/Mailosaur/files.rb +21 -253
- data/lib/Mailosaur/messages.rb +63 -567
- data/lib/Mailosaur/models/attachment.rb +10 -77
- data/lib/Mailosaur/models/base_model.rb +16 -0
- data/lib/Mailosaur/models/forwarding_rule.rb +8 -61
- data/lib/Mailosaur/models/image.rb +6 -45
- data/lib/Mailosaur/models/link.rb +6 -45
- data/lib/Mailosaur/models/message.rb +21 -173
- data/lib/Mailosaur/models/message_address.rb +7 -53
- data/lib/Mailosaur/models/message_content.rb +9 -71
- data/lib/Mailosaur/models/message_header.rb +6 -45
- data/lib/Mailosaur/models/message_list_result.rb +6 -45
- data/lib/Mailosaur/models/message_summary.rb +20 -162
- data/lib/Mailosaur/models/metadata.rb +6 -45
- data/lib/Mailosaur/models/search_criteria.rb +7 -53
- data/lib/Mailosaur/models/server.rb +11 -94
- data/lib/Mailosaur/models/server_create_options.rb +5 -37
- data/lib/Mailosaur/models/server_list_result.rb +6 -45
- data/lib/Mailosaur/models/spam_analysis_result.rb +7 -48
- data/lib/Mailosaur/models/spam_assassin_rule.rb +7 -53
- data/lib/Mailosaur/models/spam_filter_results.rb +6 -46
- data/lib/Mailosaur/module_definition.rb +0 -5
- data/lib/Mailosaur/servers.rb +52 -465
- data/lib/Mailosaur/version.rb +1 -6
- data/lib/mailosaur.rb +32 -16
- metadata +49 -42
- data/lib/Mailosaur/mailosaur_base_client.rb +0 -120
data/lib/Mailosaur/messages.rb
CHANGED
@@ -1,97 +1,16 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# Code generated by Microsoft (R) AutoRest Code Generator.
|
3
|
-
# Changes may cause incorrect behavior and will be lost if the code is
|
4
|
-
# regenerated.
|
5
|
-
|
6
1
|
module Mailosaur
|
7
|
-
#
|
8
|
-
# # Introduction
|
9
|
-
#
|
10
|
-
# This is an overview of the Mailosaur API. This API a RESTful JSON interface
|
11
|
-
# with predictable, resource-oriented URLs. We make use of HTTP response
|
12
|
-
# codes to indicate
|
13
|
-
# API errors.
|
14
|
-
#
|
15
|
-
# We use built-in HTTP features, like HTTP authentication and HTTP verbs,
|
16
|
-
# which are understood
|
17
|
-
# by off-the-shelf HTTP clients.
|
18
|
-
#
|
19
|
-
# [Official client libraries](/docs/client-libraries/) available for most
|
20
|
-
# popular languages.
|
21
|
-
#
|
22
|
-
# # Authentication
|
23
|
-
#
|
24
|
-
# Authenticate your account when using the API by including your API key in
|
25
|
-
# the request.
|
26
|
-
# You can [manage your API keys](/app/account/api-access/) in the Mailosaur
|
27
|
-
# UI. Your API key carrys many privileges,
|
28
|
-
# so be sure to keep it secret! Do not share your API key in
|
29
|
-
# publicly-accessible areas such
|
30
|
-
# GitHub, client-side code, and so on.
|
31
|
-
#
|
32
|
-
# All API requests must be made over HTTPS. Calls made over plain HTTP will
|
33
|
-
# fail.
|
34
|
-
# API requests without authentication will also fail.
|
35
|
-
#
|
36
|
-
# # Errors
|
37
|
-
#
|
38
|
-
# ## HTTP status codes
|
39
|
-
#
|
40
|
-
# Mailosaur uses conventional HTTP response codes to indicate the success or
|
41
|
-
# failure of an
|
42
|
-
# API request. In general, codes in the `2xx` range indicate success, codes
|
43
|
-
# in the `4xx` range
|
44
|
-
# indicate an error that failed given the information provided (e.g., a
|
45
|
-
# required parameter
|
46
|
-
# was omitted), and codes in the `5xx` range indicate an error with
|
47
|
-
# Mailosaur's servers (give us a shout in the unlikely event that you see one
|
48
|
-
# of those).
|
49
|
-
#
|
50
|
-
# | Code | Description |
|
51
|
-
# |---|---|
|
52
|
-
# | 200 - OK | Request was successful. |
|
53
|
-
# | 204 - No Content | Request was successful, no response content. |
|
54
|
-
# | 400 - Bad Request | The request could be handled, often due to missing a
|
55
|
-
# required parameter. |
|
56
|
-
# | 401 - Unauthorized | No valid API key provided. |
|
57
|
-
# | 404 - Not Found | The requested resource doesn't exist. |
|
58
|
-
# | 5XX - Server Errors | Something went wrong at Mailosaur. (Give us a
|
59
|
-
# shout). |
|
60
|
-
#
|
61
|
-
# ## Error handling
|
62
|
-
#
|
63
|
-
# In of an error the server will return as much information as possible. In
|
64
|
-
# the case of a `401` or
|
65
|
-
# `404` error the status code gives as much information as you'd need. But
|
66
|
-
# for `400` errors
|
67
|
-
# Mailosaur will return a JSON object containing the structure below.
|
68
|
-
#
|
69
|
-
# Note that our client libraries convert responses to appropriate
|
70
|
-
# language-specific objects.
|
71
|
-
#
|
72
|
-
# | Property | Description |
|
73
|
-
# |---|---|
|
74
|
-
# | `type` | The type of error returned. Can be: api_connection_error,
|
75
|
-
# api_error, authentication_error, card_error, idempotency_error
|
76
|
-
# invalid_request_error, or rate_limit_error. |
|
77
|
-
# | `message` | A human-readable message providing more details about the
|
78
|
-
# error. |
|
79
|
-
# | `parameters` | A JSON object containing a key for each property name at
|
80
|
-
# fault, with a human-readable message per field |
|
81
|
-
# | `model` | The request model that we sent and failed to be processed |
|
82
|
-
#
|
83
2
|
class Messages
|
84
3
|
|
85
4
|
#
|
86
5
|
# Creates and initializes a new instance of the Messages class.
|
87
|
-
# @param client
|
6
|
+
# @param client connection.
|
88
7
|
#
|
89
|
-
def initialize(
|
90
|
-
@
|
8
|
+
def initialize(conn)
|
9
|
+
@conn = conn
|
91
10
|
end
|
92
11
|
|
93
|
-
# @return [
|
94
|
-
attr_reader :
|
12
|
+
# @return [Connection] the client connection.
|
13
|
+
attr_reader :conn
|
95
14
|
|
96
15
|
#
|
97
16
|
# Retrieve a message
|
@@ -100,119 +19,20 @@ module Mailosaur
|
|
100
19
|
# identifier for the required message.
|
101
20
|
#
|
102
21
|
# @param id The identifier of the email message to be retrieved.
|
103
|
-
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
104
|
-
# will be added to the HTTP request.
|
105
22
|
#
|
106
23
|
# @return [Message] operation results.
|
107
24
|
#
|
108
|
-
def get(id
|
109
|
-
response =
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
#
|
116
|
-
# Retrieves the detail for a single email message. Simply supply the unique
|
117
|
-
# identifier for the required message.
|
118
|
-
#
|
119
|
-
# @param id The identifier of the email message to be retrieved.
|
120
|
-
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
121
|
-
# will be added to the HTTP request.
|
122
|
-
#
|
123
|
-
# @return [MsRest::HttpOperationResponse] HTTP response information.
|
124
|
-
#
|
125
|
-
def get_with_http_info(id, custom_headers:nil)
|
126
|
-
get_async(id, custom_headers:custom_headers).value!
|
127
|
-
end
|
128
|
-
|
129
|
-
#
|
130
|
-
# Retrieve a message
|
131
|
-
#
|
132
|
-
# Retrieves the detail for a single email message. Simply supply the unique
|
133
|
-
# identifier for the required message.
|
134
|
-
#
|
135
|
-
# @param id The identifier of the email message to be retrieved.
|
136
|
-
# @param [Hash{String => String}] A hash of custom headers that will be added
|
137
|
-
# to the HTTP request.
|
138
|
-
#
|
139
|
-
# @return [Concurrent::Promise] Promise object which holds the HTTP response.
|
140
|
-
#
|
141
|
-
def get_async(id, custom_headers:nil)
|
142
|
-
fail ArgumentError, 'id is nil' if id.nil?
|
143
|
-
|
144
|
-
|
145
|
-
request_headers = {}
|
146
|
-
request_headers['Content-Type'] = 'application/json; charset=utf-8'
|
147
|
-
path_template = 'api/messages/{id}'
|
148
|
-
|
149
|
-
request_url = @base_url || @client.base_url
|
150
|
-
|
151
|
-
options = {
|
152
|
-
middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
|
153
|
-
path_params: {'id' => id},
|
154
|
-
headers: request_headers.merge(custom_headers || {}),
|
155
|
-
base_url: request_url
|
156
|
-
}
|
157
|
-
promise = @client.make_request_async(:get, path_template, options)
|
158
|
-
|
159
|
-
promise = promise.then do |result|
|
160
|
-
http_response = result.response
|
161
|
-
status_code = http_response.status
|
162
|
-
response_content = http_response.body
|
163
|
-
unless status_code == 200
|
164
|
-
error_model = JSON.load(response_content)
|
165
|
-
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + status_code.to_s + '\'', error_model)
|
166
|
-
raise mailosaur_error
|
167
|
-
end
|
168
|
-
|
169
|
-
# Deserialize Response
|
170
|
-
if status_code == 200
|
171
|
-
begin
|
172
|
-
parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
|
173
|
-
result_mapper = Mailosaur::Models::Message.mapper()
|
174
|
-
result.body = @client.deserialize(result_mapper, parsed_response)
|
175
|
-
rescue Exception => e
|
176
|
-
fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
result
|
25
|
+
def get(id)
|
26
|
+
response = conn.get 'api/messages/' + id
|
27
|
+
|
28
|
+
unless response.status == 200
|
29
|
+
error_model = JSON.load(response.body)
|
30
|
+
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
|
31
|
+
raise mailosaur_error
|
181
32
|
end
|
182
33
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
#
|
187
|
-
# Delete a message
|
188
|
-
#
|
189
|
-
# Permanently deletes a message. This operation cannot be undone. Also deletes
|
190
|
-
# any attachments related to the message.
|
191
|
-
#
|
192
|
-
# @param id The identifier of the message to be deleted.
|
193
|
-
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
194
|
-
# will be added to the HTTP request.
|
195
|
-
#
|
196
|
-
#
|
197
|
-
def delete(id, custom_headers:nil)
|
198
|
-
response = delete_async(id, custom_headers:custom_headers).value!
|
199
|
-
nil
|
200
|
-
end
|
201
|
-
|
202
|
-
#
|
203
|
-
# Delete a message
|
204
|
-
#
|
205
|
-
# Permanently deletes a message. This operation cannot be undone. Also deletes
|
206
|
-
# any attachments related to the message.
|
207
|
-
#
|
208
|
-
# @param id The identifier of the message to be deleted.
|
209
|
-
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
210
|
-
# will be added to the HTTP request.
|
211
|
-
#
|
212
|
-
# @return [MsRest::HttpOperationResponse] HTTP response information.
|
213
|
-
#
|
214
|
-
def delete_with_http_info(id, custom_headers:nil)
|
215
|
-
delete_async(id, custom_headers:custom_headers).value!
|
34
|
+
model = JSON.load(response.body)
|
35
|
+
Mailosaur::Models::Message.new(model)
|
216
36
|
end
|
217
37
|
|
218
38
|
#
|
@@ -222,44 +42,17 @@ module Mailosaur
|
|
222
42
|
# any attachments related to the message.
|
223
43
|
#
|
224
44
|
# @param id The identifier of the message to be deleted.
|
225
|
-
# @param [Hash{String => String}] A hash of custom headers that will be added
|
226
|
-
# to the HTTP request.
|
227
45
|
#
|
228
|
-
|
229
|
-
|
230
|
-
def delete_async(id, custom_headers:nil)
|
231
|
-
fail ArgumentError, 'id is nil' if id.nil?
|
232
|
-
|
233
|
-
|
234
|
-
request_headers = {}
|
235
|
-
request_headers['Content-Type'] = 'application/json; charset=utf-8'
|
236
|
-
path_template = 'api/messages/{id}'
|
237
|
-
|
238
|
-
request_url = @base_url || @client.base_url
|
239
|
-
|
240
|
-
options = {
|
241
|
-
middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
|
242
|
-
path_params: {'id' => id},
|
243
|
-
headers: request_headers.merge(custom_headers || {}),
|
244
|
-
base_url: request_url
|
245
|
-
}
|
246
|
-
promise = @client.make_request_async(:delete, path_template, options)
|
247
|
-
|
248
|
-
promise = promise.then do |result|
|
249
|
-
http_response = result.response
|
250
|
-
status_code = http_response.status
|
251
|
-
response_content = http_response.body
|
252
|
-
unless status_code == 204
|
253
|
-
error_model = JSON.load(response_content)
|
254
|
-
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + status_code.to_s + '\'', error_model)
|
255
|
-
raise mailosaur_error
|
256
|
-
end
|
257
|
-
|
46
|
+
def delete(id)
|
47
|
+
response = conn.delete 'api/messages/' + id
|
258
48
|
|
259
|
-
|
49
|
+
unless response.status == 204
|
50
|
+
error_model = JSON.load(response.body)
|
51
|
+
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
|
52
|
+
raise mailosaur_error
|
260
53
|
end
|
261
54
|
|
262
|
-
|
55
|
+
nil
|
263
56
|
end
|
264
57
|
|
265
58
|
#
|
@@ -274,129 +67,24 @@ module Mailosaur
|
|
274
67
|
# pagination.
|
275
68
|
# @param items_per_page [Integer] A limit on the number of results to be
|
276
69
|
# returned per page. Can be set between 1 and 1000 items, the default is 50.
|
277
|
-
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
278
|
-
# will be added to the HTTP request.
|
279
70
|
#
|
280
71
|
# @return [MessageListResult] operation results.
|
281
72
|
#
|
282
|
-
def list(server, page:nil, items_per_page:nil
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
#
|
294
|
-
# @param server [String] The identifier of the server hosting the messages.
|
295
|
-
# @param page [Integer] Used in conjunction with `itemsPerPage` to support
|
296
|
-
# pagination.
|
297
|
-
# @param items_per_page [Integer] A limit on the number of results to be
|
298
|
-
# returned per page. Can be set between 1 and 1000 items, the default is 50.
|
299
|
-
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
300
|
-
# will be added to the HTTP request.
|
301
|
-
#
|
302
|
-
# @return [MsRest::HttpOperationResponse] HTTP response information.
|
303
|
-
#
|
304
|
-
def list_with_http_info(server, page:nil, items_per_page:nil, custom_headers:nil)
|
305
|
-
list_async(server, page:page, items_per_page:items_per_page, custom_headers:custom_headers).value!
|
306
|
-
end
|
307
|
-
|
308
|
-
#
|
309
|
-
# List all messages
|
310
|
-
#
|
311
|
-
# Returns a list of your messages in summary form. The summaries are returned
|
312
|
-
# sorted by received date, with the most recently-received messages appearing
|
313
|
-
# first.
|
314
|
-
#
|
315
|
-
# @param server [String] The identifier of the server hosting the messages.
|
316
|
-
# @param page [Integer] Used in conjunction with `itemsPerPage` to support
|
317
|
-
# pagination.
|
318
|
-
# @param items_per_page [Integer] A limit on the number of results to be
|
319
|
-
# returned per page. Can be set between 1 and 1000 items, the default is 50.
|
320
|
-
# @param [Hash{String => String}] A hash of custom headers that will be added
|
321
|
-
# to the HTTP request.
|
322
|
-
#
|
323
|
-
# @return [Concurrent::Promise] Promise object which holds the HTTP response.
|
324
|
-
#
|
325
|
-
def list_async(server, page:nil, items_per_page:nil, custom_headers:nil)
|
326
|
-
fail ArgumentError, 'server is nil' if server.nil?
|
327
|
-
|
328
|
-
|
329
|
-
request_headers = {}
|
330
|
-
request_headers['Content-Type'] = 'application/json; charset=utf-8'
|
331
|
-
path_template = 'api/messages'
|
332
|
-
|
333
|
-
request_url = @base_url || @client.base_url
|
334
|
-
|
335
|
-
options = {
|
336
|
-
middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
|
337
|
-
query_params: {'server' => server,'page' => page,'itemsPerPage' => items_per_page},
|
338
|
-
headers: request_headers.merge(custom_headers || {}),
|
339
|
-
base_url: request_url
|
340
|
-
}
|
341
|
-
promise = @client.make_request_async(:get, path_template, options)
|
342
|
-
|
343
|
-
promise = promise.then do |result|
|
344
|
-
http_response = result.response
|
345
|
-
status_code = http_response.status
|
346
|
-
response_content = http_response.body
|
347
|
-
unless status_code == 200
|
348
|
-
error_model = JSON.load(response_content)
|
349
|
-
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + status_code.to_s + '\'', error_model)
|
350
|
-
raise mailosaur_error
|
351
|
-
end
|
352
|
-
|
353
|
-
# Deserialize Response
|
354
|
-
if status_code == 200
|
355
|
-
begin
|
356
|
-
parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
|
357
|
-
result_mapper = Mailosaur::Models::MessageListResult.mapper()
|
358
|
-
result.body = @client.deserialize(result_mapper, parsed_response)
|
359
|
-
rescue Exception => e
|
360
|
-
fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
|
361
|
-
end
|
362
|
-
end
|
363
|
-
|
364
|
-
result
|
73
|
+
def list(server, page:nil, items_per_page:nil)
|
74
|
+
url = 'api/messages?server=' + server
|
75
|
+
url += page ? '&page=' + page : ''
|
76
|
+
url += items_per_page ? '&itemsPerPage=' + items_per_page : ''
|
77
|
+
|
78
|
+
response = conn.get url
|
79
|
+
|
80
|
+
unless response.status == 200
|
81
|
+
error_model = JSON.load(response.body)
|
82
|
+
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
|
83
|
+
raise mailosaur_error
|
365
84
|
end
|
366
85
|
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
#
|
371
|
-
# Delete all messages
|
372
|
-
#
|
373
|
-
# Permanently deletes all messages held by the specified server. This operation
|
374
|
-
# cannot be undone. Also deletes any attachments related to each message.
|
375
|
-
#
|
376
|
-
# @param server [String] The identifier of the server to be emptied.
|
377
|
-
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
378
|
-
# will be added to the HTTP request.
|
379
|
-
#
|
380
|
-
#
|
381
|
-
def delete_all(server, custom_headers:nil)
|
382
|
-
response = delete_all_async(server, custom_headers:custom_headers).value!
|
383
|
-
nil
|
384
|
-
end
|
385
|
-
|
386
|
-
#
|
387
|
-
# Delete all messages
|
388
|
-
#
|
389
|
-
# Permanently deletes all messages held by the specified server. This operation
|
390
|
-
# cannot be undone. Also deletes any attachments related to each message.
|
391
|
-
#
|
392
|
-
# @param server [String] The identifier of the server to be emptied.
|
393
|
-
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
394
|
-
# will be added to the HTTP request.
|
395
|
-
#
|
396
|
-
# @return [MsRest::HttpOperationResponse] HTTP response information.
|
397
|
-
#
|
398
|
-
def delete_all_with_http_info(server, custom_headers:nil)
|
399
|
-
delete_all_async(server, custom_headers:custom_headers).value!
|
86
|
+
model = JSON.load(response.body)
|
87
|
+
Mailosaur::Models::MessageListResult.new(model)
|
400
88
|
end
|
401
89
|
|
402
90
|
#
|
@@ -406,44 +94,17 @@ module Mailosaur
|
|
406
94
|
# cannot be undone. Also deletes any attachments related to each message.
|
407
95
|
#
|
408
96
|
# @param server [String] The identifier of the server to be emptied.
|
409
|
-
# @param [Hash{String => String}] A hash of custom headers that will be added
|
410
|
-
# to the HTTP request.
|
411
|
-
#
|
412
|
-
# @return [Concurrent::Promise] Promise object which holds the HTTP response.
|
413
97
|
#
|
414
|
-
def
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
request_headers = {}
|
419
|
-
request_headers['Content-Type'] = 'application/json; charset=utf-8'
|
420
|
-
path_template = 'api/messages'
|
421
|
-
|
422
|
-
request_url = @base_url || @client.base_url
|
98
|
+
def delete_all(server)
|
99
|
+
response = conn.delete 'api/messages?server=' + server
|
423
100
|
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
base_url: request_url
|
429
|
-
}
|
430
|
-
promise = @client.make_request_async(:delete, path_template, options)
|
431
|
-
|
432
|
-
promise = promise.then do |result|
|
433
|
-
http_response = result.response
|
434
|
-
status_code = http_response.status
|
435
|
-
response_content = http_response.body
|
436
|
-
unless status_code == 204
|
437
|
-
error_model = JSON.load(response_content)
|
438
|
-
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + status_code.to_s + '\'', error_model)
|
439
|
-
raise mailosaur_error
|
440
|
-
end
|
441
|
-
|
442
|
-
|
443
|
-
result
|
101
|
+
unless response.status == 204
|
102
|
+
error_model = JSON.load(response.body)
|
103
|
+
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
|
104
|
+
raise mailosaur_error
|
444
105
|
end
|
445
106
|
|
446
|
-
|
107
|
+
nil
|
447
108
|
end
|
448
109
|
|
449
110
|
#
|
@@ -460,109 +121,24 @@ module Mailosaur
|
|
460
121
|
# pagination.
|
461
122
|
# @param items_per_page [Integer] A limit on the number of results to be
|
462
123
|
# returned per page. Can be set between 1 and 1000 items, the default is 50.
|
463
|
-
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
464
|
-
# will be added to the HTTP request.
|
465
124
|
#
|
466
125
|
# @return [MessageListResult] operation results.
|
467
126
|
#
|
468
|
-
def search(server, criteria, page:nil, items_per_page:nil
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
#
|
480
|
-
# @param server [String] The identifier of the server hosting the messages.
|
481
|
-
# @param criteria [SearchCriteria] The search criteria to match results
|
482
|
-
# against.
|
483
|
-
# @param page [Integer] Used in conjunction with `itemsPerPage` to support
|
484
|
-
# pagination.
|
485
|
-
# @param items_per_page [Integer] A limit on the number of results to be
|
486
|
-
# returned per page. Can be set between 1 and 1000 items, the default is 50.
|
487
|
-
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
488
|
-
# will be added to the HTTP request.
|
489
|
-
#
|
490
|
-
# @return [MsRest::HttpOperationResponse] HTTP response information.
|
491
|
-
#
|
492
|
-
def search_with_http_info(server, criteria, page:nil, items_per_page:nil, custom_headers:nil)
|
493
|
-
search_async(server, criteria, page:page, items_per_page:items_per_page, custom_headers:custom_headers).value!
|
494
|
-
end
|
495
|
-
|
496
|
-
#
|
497
|
-
# Search for messages
|
498
|
-
#
|
499
|
-
# Returns a list of messages matching the specified search criteria, in summary
|
500
|
-
# form. The messages are returned sorted by received date, with the most
|
501
|
-
# recently-received messages appearing first.
|
502
|
-
#
|
503
|
-
# @param server [String] The identifier of the server hosting the messages.
|
504
|
-
# @param criteria [SearchCriteria] The search criteria to match results
|
505
|
-
# against.
|
506
|
-
# @param page [Integer] Used in conjunction with `itemsPerPage` to support
|
507
|
-
# pagination.
|
508
|
-
# @param items_per_page [Integer] A limit on the number of results to be
|
509
|
-
# returned per page. Can be set between 1 and 1000 items, the default is 50.
|
510
|
-
# @param [Hash{String => String}] A hash of custom headers that will be added
|
511
|
-
# to the HTTP request.
|
512
|
-
#
|
513
|
-
# @return [Concurrent::Promise] Promise object which holds the HTTP response.
|
514
|
-
#
|
515
|
-
def search_async(server, criteria, page:nil, items_per_page:nil, custom_headers:nil)
|
516
|
-
fail ArgumentError, 'server is nil' if server.nil?
|
517
|
-
fail ArgumentError, 'criteria is nil' if criteria.nil?
|
518
|
-
|
519
|
-
|
520
|
-
request_headers = {}
|
521
|
-
request_headers['Content-Type'] = 'application/json; charset=utf-8'
|
522
|
-
|
523
|
-
# Serialize Request
|
524
|
-
request_mapper = Mailosaur::Models::SearchCriteria.mapper()
|
525
|
-
request_content = @client.serialize(request_mapper, criteria)
|
526
|
-
request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
|
527
|
-
|
528
|
-
path_template = 'api/messages/search'
|
529
|
-
|
530
|
-
request_url = @base_url || @client.base_url
|
531
|
-
|
532
|
-
options = {
|
533
|
-
middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
|
534
|
-
query_params: {'server' => server,'page' => page,'itemsPerPage' => items_per_page},
|
535
|
-
body: request_content,
|
536
|
-
headers: request_headers.merge(custom_headers || {}),
|
537
|
-
base_url: request_url
|
538
|
-
}
|
539
|
-
promise = @client.make_request_async(:post, path_template, options)
|
540
|
-
|
541
|
-
promise = promise.then do |result|
|
542
|
-
http_response = result.response
|
543
|
-
status_code = http_response.status
|
544
|
-
response_content = http_response.body
|
545
|
-
unless status_code == 200
|
546
|
-
error_model = JSON.load(response_content)
|
547
|
-
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + status_code.to_s + '\'', error_model)
|
548
|
-
raise mailosaur_error
|
549
|
-
end
|
550
|
-
|
551
|
-
# Deserialize Response
|
552
|
-
if status_code == 200
|
553
|
-
begin
|
554
|
-
parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
|
555
|
-
result_mapper = Mailosaur::Models::MessageListResult.mapper()
|
556
|
-
result.body = @client.deserialize(result_mapper, parsed_response)
|
557
|
-
rescue Exception => e
|
558
|
-
fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
|
559
|
-
end
|
560
|
-
end
|
561
|
-
|
562
|
-
result
|
127
|
+
def search(server, criteria, page:nil, items_per_page:nil)
|
128
|
+
url = 'api/messages/search?server=' + server
|
129
|
+
url += page ? '&page=' + page : ''
|
130
|
+
url += items_per_page ? '&itemsPerPage=' + items_per_page : ''
|
131
|
+
|
132
|
+
response = conn.post url, criteria.to_json
|
133
|
+
|
134
|
+
unless response.status == 200
|
135
|
+
error_model = JSON.load(response.body)
|
136
|
+
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
|
137
|
+
raise mailosaur_error
|
563
138
|
end
|
564
139
|
|
565
|
-
|
140
|
+
model = JSON.load(response.body)
|
141
|
+
Mailosaur::Models::MessageListResult.new(model)
|
566
142
|
end
|
567
143
|
|
568
144
|
#
|
@@ -574,100 +150,20 @@ module Mailosaur
|
|
574
150
|
# @param server [String] The identifier of the server hosting the message.
|
575
151
|
# @param criteria [SearchCriteria] The search criteria to use in order to find
|
576
152
|
# a match.
|
577
|
-
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
578
|
-
# will be added to the HTTP request.
|
579
153
|
#
|
580
154
|
# @return [Message] operation results.
|
581
155
|
#
|
582
|
-
def wait_for(server, criteria
|
583
|
-
response =
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
#
|
590
|
-
# Returns as soon as a message matching the specified search criteria is found.
|
591
|
-
# This is the most efficient method of looking up a message.
|
592
|
-
#
|
593
|
-
# @param server [String] The identifier of the server hosting the message.
|
594
|
-
# @param criteria [SearchCriteria] The search criteria to use in order to find
|
595
|
-
# a match.
|
596
|
-
# @param custom_headers [Hash{String => String}] A hash of custom headers that
|
597
|
-
# will be added to the HTTP request.
|
598
|
-
#
|
599
|
-
# @return [MsRest::HttpOperationResponse] HTTP response information.
|
600
|
-
#
|
601
|
-
def wait_for_with_http_info(server, criteria, custom_headers:nil)
|
602
|
-
wait_for_async(server, criteria, custom_headers:custom_headers).value!
|
603
|
-
end
|
604
|
-
|
605
|
-
#
|
606
|
-
# Wait for a specific message
|
607
|
-
#
|
608
|
-
# Returns as soon as a message matching the specified search criteria is found.
|
609
|
-
# This is the most efficient method of looking up a message.
|
610
|
-
#
|
611
|
-
# @param server [String] The identifier of the server hosting the message.
|
612
|
-
# @param criteria [SearchCriteria] The search criteria to use in order to find
|
613
|
-
# a match.
|
614
|
-
# @param [Hash{String => String}] A hash of custom headers that will be added
|
615
|
-
# to the HTTP request.
|
616
|
-
#
|
617
|
-
# @return [Concurrent::Promise] Promise object which holds the HTTP response.
|
618
|
-
#
|
619
|
-
def wait_for_async(server, criteria, custom_headers:nil)
|
620
|
-
fail ArgumentError, 'server is nil' if server.nil?
|
621
|
-
fail ArgumentError, 'criteria is nil' if criteria.nil?
|
622
|
-
|
623
|
-
|
624
|
-
request_headers = {}
|
625
|
-
request_headers['Content-Type'] = 'application/json; charset=utf-8'
|
626
|
-
|
627
|
-
# Serialize Request
|
628
|
-
request_mapper = Mailosaur::Models::SearchCriteria.mapper()
|
629
|
-
request_content = @client.serialize(request_mapper, criteria)
|
630
|
-
request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
|
631
|
-
|
632
|
-
path_template = 'api/messages/await'
|
633
|
-
|
634
|
-
request_url = @base_url || @client.base_url
|
635
|
-
|
636
|
-
options = {
|
637
|
-
middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
|
638
|
-
query_params: {'server' => server},
|
639
|
-
body: request_content,
|
640
|
-
headers: request_headers.merge(custom_headers || {}),
|
641
|
-
base_url: request_url
|
642
|
-
}
|
643
|
-
promise = @client.make_request_async(:post, path_template, options)
|
644
|
-
|
645
|
-
promise = promise.then do |result|
|
646
|
-
http_response = result.response
|
647
|
-
status_code = http_response.status
|
648
|
-
response_content = http_response.body
|
649
|
-
unless status_code == 200 || status_code == 204
|
650
|
-
error_model = JSON.load(response_content)
|
651
|
-
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + status_code.to_s + '\'', error_model)
|
652
|
-
raise mailosaur_error
|
653
|
-
end
|
654
|
-
|
655
|
-
# Deserialize Response
|
656
|
-
if status_code == 200
|
657
|
-
begin
|
658
|
-
parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
|
659
|
-
result_mapper = Mailosaur::Models::Message.mapper()
|
660
|
-
result.body = @client.deserialize(result_mapper, parsed_response)
|
661
|
-
rescue Exception => e
|
662
|
-
fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
|
663
|
-
end
|
664
|
-
end
|
665
|
-
|
666
|
-
result
|
156
|
+
def wait_for(server, criteria)
|
157
|
+
response = conn.post 'api/messages/await?server=' + server, criteria.to_json
|
158
|
+
|
159
|
+
unless response.status == 200
|
160
|
+
error_model = JSON.load(response.body)
|
161
|
+
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
|
162
|
+
raise mailosaur_error
|
667
163
|
end
|
668
164
|
|
669
|
-
|
165
|
+
model = JSON.load(response.body)
|
166
|
+
Mailosaur::Models::Message.new(model)
|
670
167
|
end
|
671
|
-
|
672
168
|
end
|
673
169
|
end
|