mailosaur 5.0.2 → 5.0.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,53 +1,13 @@
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
2
  module Models
8
- #
9
- # Model object.
10
- #
11
- #
12
- class SpamFilterResults
3
+ class SpamFilterResults < BaseModel
4
+ def initialize(data = {})
5
+ @spam_assassin = []
6
+ (data['spamAssassin'] || []).each do | i | @spam_assassin << Mailosaur::Models::SpamAssassinRule.new(i) end
7
+ end
8
+
13
9
  # @return [Array<SpamAssassinRule>]
14
10
  attr_accessor :spam_assassin
15
-
16
-
17
- #
18
- # Mapper for SpamFilterResults class as Ruby Hash.
19
- # This will be used for serialization/deserialization.
20
- #
21
- def self.mapper()
22
- {
23
- client_side_validation: true,
24
- required: false,
25
- serialized_name: 'SpamFilterResults',
26
- type: {
27
- name: 'Composite',
28
- class_name: 'SpamFilterResults',
29
- model_properties: {
30
- spam_assassin: {
31
- client_side_validation: true,
32
- required: false,
33
- serialized_name: 'spamAssassin',
34
- type: {
35
- name: 'Sequence',
36
- element: {
37
- client_side_validation: true,
38
- required: false,
39
- serialized_name: 'SpamAssassinRuleElementType',
40
- type: {
41
- name: 'Composite',
42
- class_name: 'SpamAssassinRule'
43
- }
44
- }
45
- }
46
- }
47
- }
48
- }
49
- }
50
- end
51
11
  end
52
12
  end
53
13
  end
@@ -1,6 +1 @@
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 end
@@ -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 Servers
84
3
 
85
4
  #
86
5
  # Creates and initializes a new instance of the Servers class.
87
- # @param client service class for accessing basic functionality.
6
+ # @param client connection.
88
7
  #
89
- def initialize(client)
90
- @client = client
8
+ def initialize(conn)
9
+ @conn = conn
91
10
  end
92
11
 
93
- # @return [MailosaurBaseClient] reference to the MailosaurBaseClient
94
- attr_reader :client
12
+ # @return [Connection] the client connection.
13
+ attr_reader :conn
95
14
 
96
15
  #
97
16
  # List all servers
@@ -99,83 +18,19 @@ module Mailosaur
99
18
  # Returns a list of your virtual SMTP servers. Servers are returned sorted in
100
19
  # alphabetical order.
101
20
  #
102
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
103
- # will be added to the HTTP request.
104
- #
105
21
  # @return [ServerListResult] operation results.
106
22
  #
107
- def list(custom_headers:nil)
108
- response = list_async(custom_headers:custom_headers).value!
109
- response.body unless response.nil?
110
- end
111
-
112
- #
113
- # List all servers
114
- #
115
- # Returns a list of your virtual SMTP servers. Servers are returned sorted in
116
- # alphabetical order.
117
- #
118
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
119
- # will be added to the HTTP request.
120
- #
121
- # @return [MsRest::HttpOperationResponse] HTTP response information.
122
- #
123
- def list_with_http_info(custom_headers:nil)
124
- list_async(custom_headers:custom_headers).value!
125
- end
126
-
127
- #
128
- # List all servers
129
- #
130
- # Returns a list of your virtual SMTP servers. Servers are returned sorted in
131
- # alphabetical order.
132
- #
133
- # @param [Hash{String => String}] A hash of custom headers that will be added
134
- # to the HTTP request.
135
- #
136
- # @return [Concurrent::Promise] Promise object which holds the HTTP response.
137
- #
138
- def list_async(custom_headers:nil)
139
-
140
-
141
- request_headers = {}
142
- request_headers['Content-Type'] = 'application/json; charset=utf-8'
143
- path_template = 'api/servers'
144
-
145
- request_url = @base_url || @client.base_url
146
-
147
- options = {
148
- middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
149
- headers: request_headers.merge(custom_headers || {}),
150
- base_url: request_url
151
- }
152
- promise = @client.make_request_async(:get, path_template, options)
153
-
154
- promise = promise.then do |result|
155
- http_response = result.response
156
- status_code = http_response.status
157
- response_content = http_response.body
158
- unless status_code == 200
159
- error_model = JSON.load(response_content)
160
- mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + status_code.to_s + '\'', error_model)
161
- raise mailosaur_error
162
- end
163
-
164
- # Deserialize Response
165
- if status_code == 200
166
- begin
167
- parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
168
- result_mapper = Mailosaur::Models::ServerListResult.mapper()
169
- result.body = @client.deserialize(result_mapper, parsed_response)
170
- rescue Exception => e
171
- fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
172
- end
173
- end
174
-
175
- result
23
+ def list()
24
+ response = conn.get 'api/servers'
25
+
26
+ unless response.status == 200
27
+ error_model = JSON.load(response.body)
28
+ mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
29
+ raise mailosaur_error
176
30
  end
177
31
 
178
- promise.execute
32
+ model = JSON.load(response.body)
33
+ Mailosaur::Models::ServerListResult.new(model)
179
34
  end
180
35
 
181
36
  #
@@ -184,91 +39,20 @@ module Mailosaur
184
39
  # Creates a new virtual SMTP server and returns it.
185
40
  #
186
41
  # @param server_create_options [ServerCreateOptions]
187
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
188
- # will be added to the HTTP request.
189
42
  #
190
43
  # @return [Server] operation results.
191
44
  #
192
- def create(server_create_options, custom_headers:nil)
193
- response = create_async(server_create_options, custom_headers:custom_headers).value!
194
- response.body unless response.nil?
195
- end
196
-
197
- #
198
- # Create a server
199
- #
200
- # Creates a new virtual SMTP server and returns it.
201
- #
202
- # @param server_create_options [ServerCreateOptions]
203
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
204
- # will be added to the HTTP request.
205
- #
206
- # @return [MsRest::HttpOperationResponse] HTTP response information.
207
- #
208
- def create_with_http_info(server_create_options, custom_headers:nil)
209
- create_async(server_create_options, custom_headers:custom_headers).value!
210
- end
211
-
212
- #
213
- # Create a server
214
- #
215
- # Creates a new virtual SMTP server and returns it.
216
- #
217
- # @param server_create_options [ServerCreateOptions]
218
- # @param [Hash{String => String}] A hash of custom headers that will be added
219
- # to the HTTP request.
220
- #
221
- # @return [Concurrent::Promise] Promise object which holds the HTTP response.
222
- #
223
- def create_async(server_create_options, custom_headers:nil)
224
- fail ArgumentError, 'server_create_options is nil' if server_create_options.nil?
225
-
226
-
227
- request_headers = {}
228
- request_headers['Content-Type'] = 'application/json; charset=utf-8'
229
-
230
- # Serialize Request
231
- request_mapper = Mailosaur::Models::ServerCreateOptions.mapper()
232
- request_content = @client.serialize(request_mapper, server_create_options)
233
- request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
234
-
235
- path_template = 'api/servers'
236
-
237
- request_url = @base_url || @client.base_url
238
-
239
- options = {
240
- middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
241
- body: request_content,
242
- headers: request_headers.merge(custom_headers || {}),
243
- base_url: request_url
244
- }
245
- promise = @client.make_request_async(:post, path_template, options)
246
-
247
- promise = promise.then do |result|
248
- http_response = result.response
249
- status_code = http_response.status
250
- response_content = http_response.body
251
- unless status_code == 200
252
- error_model = JSON.load(response_content)
253
- mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + status_code.to_s + '\'', error_model)
254
- raise mailosaur_error
255
- end
256
-
257
- # Deserialize Response
258
- if status_code == 200
259
- begin
260
- parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
261
- result_mapper = Mailosaur::Models::Server.mapper()
262
- result.body = @client.deserialize(result_mapper, parsed_response)
263
- rescue Exception => e
264
- fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
265
- end
266
- end
267
-
268
- result
45
+ def create(server_create_options)
46
+ response = conn.post 'api/servers', server_create_options.to_json
47
+
48
+ unless response.status == 200
49
+ error_model = JSON.load(response.body)
50
+ mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
51
+ raise mailosaur_error
269
52
  end
270
53
 
271
- promise.execute
54
+ model = JSON.load(response.body)
55
+ Mailosaur::Models::Server.new(model)
272
56
  end
273
57
 
274
58
  #
@@ -278,87 +62,20 @@ module Mailosaur
278
62
  # for the required server.
279
63
  #
280
64
  # @param id [String] The identifier of the server to be retrieved.
281
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
282
- # will be added to the HTTP request.
283
65
  #
284
66
  # @return [Server] operation results.
285
67
  #
286
- def get(id, custom_headers:nil)
287
- response = get_async(id, custom_headers:custom_headers).value!
288
- response.body unless response.nil?
289
- end
290
-
291
- #
292
- # Retrieve a server
293
- #
294
- # Retrieves the detail for a single server. Simply supply the unique identifier
295
- # for the required server.
296
- #
297
- # @param id [String] The identifier of the server to be retrieved.
298
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
299
- # will be added to the HTTP request.
300
- #
301
- # @return [MsRest::HttpOperationResponse] HTTP response information.
302
- #
303
- def get_with_http_info(id, custom_headers:nil)
304
- get_async(id, custom_headers:custom_headers).value!
305
- end
306
-
307
- #
308
- # Retrieve a server
309
- #
310
- # Retrieves the detail for a single server. Simply supply the unique identifier
311
- # for the required server.
312
- #
313
- # @param id [String] The identifier of the server to be retrieved.
314
- # @param [Hash{String => String}] A hash of custom headers that will be added
315
- # to the HTTP request.
316
- #
317
- # @return [Concurrent::Promise] Promise object which holds the HTTP response.
318
- #
319
- def get_async(id, custom_headers:nil)
320
- fail ArgumentError, 'id is nil' if id.nil?
321
-
322
-
323
- request_headers = {}
324
- request_headers['Content-Type'] = 'application/json; charset=utf-8'
325
- path_template = 'api/servers/{id}'
326
-
327
- request_url = @base_url || @client.base_url
328
-
329
- options = {
330
- middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
331
- path_params: {'id' => id},
332
- headers: request_headers.merge(custom_headers || {}),
333
- base_url: request_url
334
- }
335
- promise = @client.make_request_async(:get, path_template, options)
336
-
337
- promise = promise.then do |result|
338
- http_response = result.response
339
- status_code = http_response.status
340
- response_content = http_response.body
341
- unless status_code == 200
342
- error_model = JSON.load(response_content)
343
- mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + status_code.to_s + '\'', error_model)
344
- raise mailosaur_error
345
- end
346
-
347
- # Deserialize Response
348
- if status_code == 200
349
- begin
350
- parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
351
- result_mapper = Mailosaur::Models::Server.mapper()
352
- result.body = @client.deserialize(result_mapper, parsed_response)
353
- rescue Exception => e
354
- fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
355
- end
356
- end
357
-
358
- result
68
+ def get(id)
69
+ response = conn.get 'api/servers/' + id
70
+
71
+ unless response.status == 200
72
+ error_model = JSON.load(response.body)
73
+ mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
74
+ raise mailosaur_error
359
75
  end
360
76
 
361
- promise.execute
77
+ model = JSON.load(response.body)
78
+ Mailosaur::Models::Server.new(model)
362
79
  end
363
80
 
364
81
  #
@@ -368,95 +85,20 @@ module Mailosaur
368
85
  #
369
86
  # @param id [String] The identifier of the server to be updated.
370
87
  # @param server [Server]
371
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
372
- # will be added to the HTTP request.
373
88
  #
374
89
  # @return [Server] operation results.
375
90
  #
376
- def update(id, server, custom_headers:nil)
377
- response = update_async(id, server, custom_headers:custom_headers).value!
378
- response.body unless response.nil?
379
- end
380
-
381
- #
382
- # Update a server
383
- #
384
- # Updats a single server and returns it.
385
- #
386
- # @param id [String] The identifier of the server to be updated.
387
- # @param server [Server]
388
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
389
- # will be added to the HTTP request.
390
- #
391
- # @return [MsRest::HttpOperationResponse] HTTP response information.
392
- #
393
- def update_with_http_info(id, server, custom_headers:nil)
394
- update_async(id, server, custom_headers:custom_headers).value!
395
- end
396
-
397
- #
398
- # Update a server
399
- #
400
- # Updats a single server and returns it.
401
- #
402
- # @param id [String] The identifier of the server to be updated.
403
- # @param server [Server]
404
- # @param [Hash{String => String}] A hash of custom headers that will be added
405
- # to the HTTP request.
406
- #
407
- # @return [Concurrent::Promise] Promise object which holds the HTTP response.
408
- #
409
- def update_async(id, server, custom_headers:nil)
410
- fail ArgumentError, 'id is nil' if id.nil?
411
- fail ArgumentError, 'server is nil' if server.nil?
412
-
413
-
414
- request_headers = {}
415
- request_headers['Content-Type'] = 'application/json; charset=utf-8'
416
-
417
- # Serialize Request
418
- request_mapper = Mailosaur::Models::Server.mapper()
419
- request_content = @client.serialize(request_mapper, server)
420
- request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil
421
-
422
- path_template = 'api/servers/{id}'
423
-
424
- request_url = @base_url || @client.base_url
425
-
426
- options = {
427
- middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
428
- path_params: {'id' => id},
429
- body: request_content,
430
- headers: request_headers.merge(custom_headers || {}),
431
- base_url: request_url
432
- }
433
- promise = @client.make_request_async(:put, path_template, options)
434
-
435
- promise = promise.then do |result|
436
- http_response = result.response
437
- status_code = http_response.status
438
- response_content = http_response.body
439
- unless status_code == 200
440
- error_model = JSON.load(response_content)
441
- mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + status_code.to_s + '\'', error_model)
442
- raise mailosaur_error
443
- end
444
-
445
- # Deserialize Response
446
- if status_code == 200
447
- begin
448
- parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
449
- result_mapper = Mailosaur::Models::Server.mapper()
450
- result.body = @client.deserialize(result_mapper, parsed_response)
451
- rescue Exception => e
452
- fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
453
- end
454
- end
455
-
456
- result
91
+ def update(id, server)
92
+ response = conn.put 'api/servers/' + id, server.to_json
93
+
94
+ unless response.status == 200
95
+ error_model = JSON.load(response.body)
96
+ mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
97
+ raise mailosaur_error
457
98
  end
458
99
 
459
- promise.execute
100
+ model = JSON.load(response.body)
101
+ Mailosaur::Models::Server.new(model)
460
102
  end
461
103
 
462
104
  #
@@ -466,77 +108,22 @@ module Mailosaur
466
108
  # all messages and associated attachments within the server.
467
109
  #
468
110
  # @param id [String] The identifier of the server to be deleted.
469
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
470
- # will be added to the HTTP request.
471
- #
472
- #
473
- def delete(id, custom_headers:nil)
474
- response = delete_async(id, custom_headers:custom_headers).value!
475
- nil
476
- end
477
-
478
111
  #
479
- # Delete a server
480
- #
481
- # Permanently deletes a server. This operation cannot be undone. Also deletes
482
- # all messages and associated attachments within the server.
483
- #
484
- # @param id [String] The identifier of the server to be deleted.
485
- # @param custom_headers [Hash{String => String}] A hash of custom headers that
486
- # will be added to the HTTP request.
487
- #
488
- # @return [MsRest::HttpOperationResponse] HTTP response information.
489
- #
490
- def delete_with_http_info(id, custom_headers:nil)
491
- delete_async(id, custom_headers:custom_headers).value!
492
- end
112
+ def delete(id)
113
+ response = conn.delete 'api/servers/' + id
493
114
 
494
- #
495
- # Delete a server
496
- #
497
- # Permanently deletes a server. This operation cannot be undone. Also deletes
498
- # all messages and associated attachments within the server.
499
- #
500
- # @param id [String] The identifier of the server to be deleted.
501
- # @param [Hash{String => String}] A hash of custom headers that will be added
502
- # to the HTTP request.
503
- #
504
- # @return [Concurrent::Promise] Promise object which holds the HTTP response.
505
- #
506
- def delete_async(id, custom_headers:nil)
507
- fail ArgumentError, 'id is nil' if id.nil?
508
-
509
-
510
- request_headers = {}
511
- request_headers['Content-Type'] = 'application/json; charset=utf-8'
512
- path_template = 'api/servers/{id}'
513
-
514
- request_url = @base_url || @client.base_url
515
-
516
- options = {
517
- middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
518
- path_params: {'id' => id},
519
- headers: request_headers.merge(custom_headers || {}),
520
- base_url: request_url
521
- }
522
- promise = @client.make_request_async(:delete, path_template, options)
523
-
524
- promise = promise.then do |result|
525
- http_response = result.response
526
- status_code = http_response.status
527
- response_content = http_response.body
528
- unless status_code == 204
529
- error_model = JSON.load(response_content)
530
- mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + status_code.to_s + '\'', error_model)
531
- raise mailosaur_error
532
- end
533
-
534
-
535
- result
115
+ unless response.status == 204
116
+ error_model = JSON.load(response.body)
117
+ mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
118
+ raise mailosaur_error
536
119
  end
537
120
 
538
- promise.execute
121
+ nil
539
122
  end
540
123
 
124
+ def generate_email_address(server)
125
+ host = ENV['MAILOSAUR_SMTP_HOST'] || 'mailosaur.io'
126
+ '%s.%s@%s' % [SecureRandom.hex(3), server, host]
127
+ end
541
128
  end
542
129
  end