mailosaur 3.0.1 → 5.0.1.pre

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +14 -13
  3. data/README.md +42 -8
  4. data/lib/Mailosaur/analysis.rb +184 -0
  5. data/lib/Mailosaur/files.rb +291 -0
  6. data/lib/Mailosaur/mailosaur_base_client.rb +120 -0
  7. data/lib/Mailosaur/mailosaur_error.rb +23 -0
  8. data/lib/Mailosaur/messages.rb +673 -0
  9. data/lib/Mailosaur/models/attachment.rb +99 -0
  10. data/lib/Mailosaur/models/forwarding_rule.rb +78 -0
  11. data/lib/Mailosaur/models/image.rb +55 -0
  12. data/lib/Mailosaur/models/link.rb +55 -0
  13. data/lib/Mailosaur/models/message.rb +219 -0
  14. data/lib/Mailosaur/models/message_address.rb +66 -0
  15. data/lib/Mailosaur/models/message_content.rb +84 -0
  16. data/lib/Mailosaur/models/message_header.rb +55 -0
  17. data/lib/Mailosaur/models/message_list_result.rb +54 -0
  18. data/lib/Mailosaur/models/message_summary.rb +199 -0
  19. data/lib/Mailosaur/models/metadata.rb +52 -0
  20. data/lib/Mailosaur/models/search_criteria.rb +69 -0
  21. data/lib/Mailosaur/models/server.rb +118 -0
  22. data/lib/Mailosaur/models/server_create_options.rb +44 -0
  23. data/lib/Mailosaur/models/server_list_result.rb +54 -0
  24. data/lib/Mailosaur/models/spam_analysis_result.rb +56 -0
  25. data/lib/Mailosaur/models/spam_assassin_rule.rb +66 -0
  26. data/lib/Mailosaur/models/spam_filter_results.rb +53 -0
  27. data/lib/Mailosaur/module_definition.rb +6 -0
  28. data/lib/Mailosaur/servers.rb +542 -0
  29. data/lib/Mailosaur/version.rb +8 -0
  30. data/lib/mailosaur.rb +52 -108
  31. metadata +78 -46
  32. data/lib/helper.rb +0 -6
  33. data/lib/mailosaur/attachment.rb +0 -10
  34. data/lib/mailosaur/email.rb +0 -23
  35. data/lib/mailosaur/email_address.rb +0 -9
  36. data/lib/mailosaur/email_data.rb +0 -13
  37. data/lib/mailosaur/image.rb +0 -8
  38. data/lib/mailosaur/link.rb +0 -8
  39. data/lib/mailosaur/message_generator.rb +0 -31
@@ -0,0 +1,673 @@
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
+ 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
+ class Messages
84
+
85
+ #
86
+ # Creates and initializes a new instance of the Messages class.
87
+ # @param client service class for accessing basic functionality.
88
+ #
89
+ def initialize(client)
90
+ @client = client
91
+ end
92
+
93
+ # @return [MailosaurBaseClient] reference to the MailosaurBaseClient
94
+ attr_reader :client
95
+
96
+ #
97
+ # Retrieve a message
98
+ #
99
+ # Retrieves the detail for a single email message. Simply supply the unique
100
+ # identifier for the required message.
101
+ #
102
+ # @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
+ #
106
+ # @return [Message] operation results.
107
+ #
108
+ def get(id, custom_headers:nil)
109
+ response = get_async(id, custom_headers:custom_headers).value!
110
+ response.body unless response.nil?
111
+ end
112
+
113
+ #
114
+ # Retrieve a message
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
181
+ end
182
+
183
+ promise.execute
184
+ end
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!
216
+ end
217
+
218
+ #
219
+ # Delete a message
220
+ #
221
+ # Permanently deletes a message. This operation cannot be undone. Also deletes
222
+ # any attachments related to the message.
223
+ #
224
+ # @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
+ #
228
+ # @return [Concurrent::Promise] Promise object which holds the HTTP response.
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
+
258
+
259
+ result
260
+ end
261
+
262
+ promise.execute
263
+ end
264
+
265
+ #
266
+ # List all messages
267
+ #
268
+ # Returns a list of your messages in summary form. The summaries are returned
269
+ # sorted by received date, with the most recently-received messages appearing
270
+ # first.
271
+ #
272
+ # @param server [String] The identifier of the server hosting the messages.
273
+ # @param page [Integer] Used in conjunction with `itemsPerPage` to support
274
+ # pagination.
275
+ # @param items_per_page [Integer] A limit on the number of results to be
276
+ # 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
+ #
280
+ # @return [MessageListResult] operation results.
281
+ #
282
+ def list(server, page:nil, items_per_page:nil, custom_headers:nil)
283
+ response = list_async(server, page:page, items_per_page:items_per_page, custom_headers:custom_headers).value!
284
+ response.body unless response.nil?
285
+ end
286
+
287
+ #
288
+ # List all messages
289
+ #
290
+ # Returns a list of your messages in summary form. The summaries are returned
291
+ # sorted by received date, with the most recently-received messages appearing
292
+ # first.
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
365
+ end
366
+
367
+ promise.execute
368
+ end
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!
400
+ end
401
+
402
+ #
403
+ # Delete all messages
404
+ #
405
+ # Permanently deletes all messages held by the specified server. This operation
406
+ # cannot be undone. Also deletes any attachments related to each message.
407
+ #
408
+ # @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
+ #
414
+ def delete_all_async(server, custom_headers:nil)
415
+ fail ArgumentError, 'server is nil' if server.nil?
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
423
+
424
+ options = {
425
+ middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
426
+ query_params: {'server' => server},
427
+ headers: request_headers.merge(custom_headers || {}),
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
444
+ end
445
+
446
+ promise.execute
447
+ end
448
+
449
+ #
450
+ # Search for messages
451
+ #
452
+ # Returns a list of messages matching the specified search criteria, in summary
453
+ # form. The messages are returned sorted by received date, with the most
454
+ # recently-received messages appearing first.
455
+ #
456
+ # @param server [String] The identifier of the server hosting the messages.
457
+ # @param criteria [SearchCriteria] The search criteria to match results
458
+ # against.
459
+ # @param page [Integer] Used in conjunction with `itemsPerPage` to support
460
+ # pagination.
461
+ # @param items_per_page [Integer] A limit on the number of results to be
462
+ # 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
+ #
466
+ # @return [MessageListResult] operation results.
467
+ #
468
+ def search(server, criteria, page:nil, items_per_page:nil, custom_headers:nil)
469
+ response = search_async(server, criteria, page:page, items_per_page:items_per_page, custom_headers:custom_headers).value!
470
+ response.body unless response.nil?
471
+ end
472
+
473
+ #
474
+ # Search for messages
475
+ #
476
+ # Returns a list of messages matching the specified search criteria, in summary
477
+ # form. The messages are returned sorted by received date, with the most
478
+ # recently-received messages appearing first.
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
563
+ end
564
+
565
+ promise.execute
566
+ end
567
+
568
+ #
569
+ # Wait for a specific message
570
+ #
571
+ # Returns as soon as a message matching the specified search criteria is found.
572
+ # This is the most efficient method of looking up a message.
573
+ #
574
+ # @param server [String] The identifier of the server hosting the message.
575
+ # @param criteria [SearchCriteria] The search criteria to use in order to find
576
+ # a match.
577
+ # @param custom_headers [Hash{String => String}] A hash of custom headers that
578
+ # will be added to the HTTP request.
579
+ #
580
+ # @return [Message] operation results.
581
+ #
582
+ def wait_for(server, criteria, custom_headers:nil)
583
+ response = wait_for_async(server, criteria, custom_headers:custom_headers).value!
584
+ response.body unless response.nil?
585
+ end
586
+
587
+ #
588
+ # Wait for a specific message
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
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
667
+ end
668
+
669
+ promise.execute
670
+ end
671
+
672
+ end
673
+ end