mailosaur 6.0.6 → 7.2.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/README.md +33 -10
- data/lib/Mailosaur/analysis.rb +3 -8
- data/lib/Mailosaur/files.rb +4 -15
- data/lib/Mailosaur/mailosaur_error.rb +7 -15
- data/lib/Mailosaur/messages.rb +17 -38
- data/lib/Mailosaur/models/search_criteria.rb +11 -0
- data/lib/Mailosaur/models/server.rb +0 -10
- data/lib/Mailosaur/servers.rb +9 -38
- data/lib/Mailosaur/version.rb +1 -1
- data/lib/mailosaur.rb +19 -5
- metadata +32 -27
- data/lib/Mailosaur/models/forwarding_rule.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 011e2ac28ac0877666e8773c40e40dc6d0a1a5af9f32aeb73da66d57bdb2b003
|
4
|
+
data.tar.gz: c6dc865d59c1cd2f93a59352a4652deef949673676241cca325d6d23904b72c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d226ef24c5af4e341d93ccb17f64f0f83788273958ce48aff5c815aaafd3fdc84bef7942355c1507f4d8014d6d42559180cb3d4ae873511610256929f8466dd7
|
7
|
+
data.tar.gz: afb69cdb68ef7f270dee406c34a6c7f576e58cb3bafbc4689edbd4fdcc725786e06a0f177ec0398ef425a76bb99ce9cdb0e6c3fa2aa83785ca36277bd782ea83
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Mailosaur Ruby Client Library
|
2
2
|
|
3
|
-
[Mailosaur](https://mailosaur.com)
|
3
|
+
[Mailosaur](https://mailosaur.com) lets you automate email and SMS tests, like account verification and password resets, and integrate these into your CI/CD pipeline.
|
4
4
|
|
5
5
|
[](https://github.com/mailosaur/mailosaur-ruby/actions)
|
6
6
|
|
@@ -10,29 +10,52 @@
|
|
10
10
|
gem install mailosaur
|
11
11
|
```
|
12
12
|
|
13
|
-
## Documentation
|
13
|
+
## Documentation
|
14
14
|
|
15
|
-
[
|
15
|
+
Please see the [Ruby client reference](https://mailosaur.com/docs/email-testing/ruby/client-reference/) for the most up-to-date documentation.
|
16
16
|
|
17
|
-
##
|
17
|
+
## Usage
|
18
18
|
|
19
|
-
|
19
|
+
example.rb
|
20
20
|
|
21
|
+
```ruby
|
22
|
+
require "mailosaur"
|
23
|
+
mailosaur = Mailosaur::MailosaurClient.new("YOUR_API_KEY")
|
24
|
+
|
25
|
+
result = mailosaur.servers.list()
|
26
|
+
|
27
|
+
print("You have a server called: " + result.items[0].name)
|
21
28
|
```
|
29
|
+
|
30
|
+
## Development
|
31
|
+
|
32
|
+
You must have the following prerequisites installed:
|
33
|
+
|
34
|
+
* [Bundler](https://bundler.io/)
|
35
|
+
|
36
|
+
Install all development dependencies:
|
37
|
+
|
38
|
+
```sh
|
22
39
|
bundle install
|
40
|
+
```
|
41
|
+
|
42
|
+
The test suite requires the following environment variables to be set:
|
23
43
|
|
44
|
+
```sh
|
45
|
+
export MAILOSAUR_BASE_URL=https://mailosaur.com/
|
24
46
|
export MAILOSAUR_API_KEY=your_api_key
|
25
47
|
export MAILOSAUR_SERVER=server_id
|
48
|
+
```
|
49
|
+
|
50
|
+
Run all tests:
|
26
51
|
|
52
|
+
```sh
|
27
53
|
bundle exec rake test
|
28
54
|
```
|
29
55
|
|
30
|
-
|
56
|
+
Lint code (via Rubocop):
|
31
57
|
|
32
|
-
|
33
|
-
|
34
|
-
```
|
35
|
-
bundle install
|
58
|
+
```sh
|
36
59
|
bundle exec rubocop
|
37
60
|
```
|
38
61
|
|
data/lib/Mailosaur/analysis.rb
CHANGED
@@ -4,8 +4,9 @@ module Mailosaur
|
|
4
4
|
# Creates and initializes a new instance of the Analysis class.
|
5
5
|
# @param conn client connection.
|
6
6
|
#
|
7
|
-
def initialize(conn)
|
7
|
+
def initialize(conn, handle_http_error)
|
8
8
|
@conn = conn
|
9
|
+
@handle_http_error = handle_http_error
|
9
10
|
end
|
10
11
|
|
11
12
|
# @return [Connection] the client connection.
|
@@ -22,13 +23,7 @@ module Mailosaur
|
|
22
23
|
#
|
23
24
|
def spam(email)
|
24
25
|
response = conn.get 'api/analysis/spam/' + email
|
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
|
30
|
-
end
|
31
|
-
|
26
|
+
@handle_http_error.call(response) unless response.status == 200
|
32
27
|
model = JSON.load(response.body)
|
33
28
|
Mailosaur::Models::SpamAnalysisResult.new(model)
|
34
29
|
end
|
data/lib/Mailosaur/files.rb
CHANGED
@@ -4,8 +4,9 @@ module Mailosaur
|
|
4
4
|
# Creates and initializes a new instance of the Files class.
|
5
5
|
# @param client connection.
|
6
6
|
#
|
7
|
-
def initialize(conn)
|
7
|
+
def initialize(conn, handle_http_error)
|
8
8
|
@conn = conn
|
9
|
+
@handle_http_error = handle_http_error
|
9
10
|
end
|
10
11
|
|
11
12
|
# @return [Connection] the client connection.
|
@@ -23,13 +24,7 @@ module Mailosaur
|
|
23
24
|
#
|
24
25
|
def get_attachment(id)
|
25
26
|
response = conn.get 'api/files/attachments/' + id
|
26
|
-
|
27
|
-
unless response.status == 200
|
28
|
-
error_model = JSON.load(response.body)
|
29
|
-
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
|
30
|
-
raise mailosaur_error
|
31
|
-
end
|
32
|
-
|
27
|
+
@handle_http_error.call(response) unless response.status == 200
|
33
28
|
response.body
|
34
29
|
end
|
35
30
|
|
@@ -45,13 +40,7 @@ module Mailosaur
|
|
45
40
|
#
|
46
41
|
def get_email(id)
|
47
42
|
response = conn.get 'api/files/email/' + id
|
48
|
-
|
49
|
-
unless response.status == 200
|
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
|
53
|
-
end
|
54
|
-
|
43
|
+
@handle_http_error.call(response) unless response.status == 200
|
55
44
|
response.body
|
56
45
|
end
|
57
46
|
end
|
@@ -1,23 +1,15 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
1
|
module Mailosaur
|
4
2
|
class MailosaurError < StandardError
|
5
|
-
attr_reader :
|
6
|
-
attr_reader :
|
7
|
-
attr_reader :
|
3
|
+
attr_reader :error_type
|
4
|
+
attr_reader :http_status_code
|
5
|
+
attr_reader :http_response_body
|
8
6
|
|
9
|
-
def initialize(message,
|
7
|
+
def initialize(message = '', error_type = '', http_status_code = nil, http_response_body = nil)
|
10
8
|
super(message)
|
11
9
|
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
|
16
|
-
unless error_model.nil?
|
17
|
-
@type = error_model['type']
|
18
|
-
@messages = error_model['messages']
|
19
|
-
@model = error_model['model']
|
20
|
-
end
|
10
|
+
@error_type = error_type
|
11
|
+
@http_status_code = http_status_code
|
12
|
+
@http_response_body = http_response_body
|
21
13
|
end
|
22
14
|
end
|
23
15
|
end
|
data/lib/Mailosaur/messages.rb
CHANGED
@@ -6,8 +6,9 @@ module Mailosaur
|
|
6
6
|
# Creates and initializes a new instance of the Messages class.
|
7
7
|
# @param client connection.
|
8
8
|
#
|
9
|
-
def initialize(conn)
|
9
|
+
def initialize(conn, handle_http_error)
|
10
10
|
@conn = conn
|
11
|
+
@handle_http_error = handle_http_error
|
11
12
|
end
|
12
13
|
|
13
14
|
# @return [Connection] the client connection.
|
@@ -31,9 +32,9 @@ module Mailosaur
|
|
31
32
|
#
|
32
33
|
def get(server, criteria, timeout: 10_000, received_after: DateTime.now - (1.0 / 24))
|
33
34
|
# Defaults timeout to 10s, receivedAfter to 1h
|
34
|
-
raise Mailosaur::MailosaurError.new('
|
35
|
+
raise Mailosaur::MailosaurError.new('Must provide a valid Server ID.', 'invalid_request') if server.length != 8
|
35
36
|
|
36
|
-
result = search(server, criteria, timeout: timeout, received_after: received_after)
|
37
|
+
result = search(server, criteria, page: 0, items_per_page: 1, timeout: timeout, received_after: received_after)
|
37
38
|
get_by_id(result.items[0].id)
|
38
39
|
end
|
39
40
|
|
@@ -49,13 +50,7 @@ module Mailosaur
|
|
49
50
|
#
|
50
51
|
def get_by_id(id)
|
51
52
|
response = conn.get 'api/messages/' + id
|
52
|
-
|
53
|
-
unless response.status == 200
|
54
|
-
error_model = JSON.load(response.body)
|
55
|
-
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
|
56
|
-
raise mailosaur_error
|
57
|
-
end
|
58
|
-
|
53
|
+
@handle_http_error.call(response) unless response.status == 200
|
59
54
|
model = JSON.load(response.body)
|
60
55
|
Mailosaur::Models::Message.new(model)
|
61
56
|
end
|
@@ -70,13 +65,7 @@ module Mailosaur
|
|
70
65
|
#
|
71
66
|
def delete(id)
|
72
67
|
response = conn.delete 'api/messages/' + id
|
73
|
-
|
74
|
-
unless response.status == 204
|
75
|
-
error_model = JSON.load(response.body)
|
76
|
-
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
|
77
|
-
raise mailosaur_error
|
78
|
-
end
|
79
|
-
|
68
|
+
@handle_http_error.call(response) unless response.status == 204
|
80
69
|
nil
|
81
70
|
end
|
82
71
|
|
@@ -99,17 +88,13 @@ module Mailosaur
|
|
99
88
|
#
|
100
89
|
def list(server, page: nil, items_per_page: nil, received_after: nil)
|
101
90
|
url = 'api/messages?server=' + server
|
102
|
-
url += page ? '&page=' + page : ''
|
103
|
-
url += items_per_page ? '&itemsPerPage=' + items_per_page : ''
|
91
|
+
url += page ? '&page=' + page.to_s : ''
|
92
|
+
url += items_per_page ? '&itemsPerPage=' + items_per_page.to_s : ''
|
104
93
|
url += received_after ? '&receivedAfter=' + CGI.escape(received_after.iso8601) : ''
|
105
94
|
|
106
95
|
response = conn.get url
|
107
96
|
|
108
|
-
unless response.status == 200
|
109
|
-
error_model = JSON.load(response.body)
|
110
|
-
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
|
111
|
-
raise mailosaur_error
|
112
|
-
end
|
97
|
+
@handle_http_error.call(response) unless response.status == 200
|
113
98
|
|
114
99
|
model = JSON.load(response.body)
|
115
100
|
Mailosaur::Models::MessageListResult.new(model)
|
@@ -125,13 +110,7 @@ module Mailosaur
|
|
125
110
|
#
|
126
111
|
def delete_all(server)
|
127
112
|
response = conn.delete 'api/messages?server=' + server
|
128
|
-
|
129
|
-
unless response.status == 204
|
130
|
-
error_model = JSON.load(response.body)
|
131
|
-
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
|
132
|
-
raise mailosaur_error
|
133
|
-
end
|
134
|
-
|
113
|
+
@handle_http_error.call(response) unless response.status == 204
|
135
114
|
nil
|
136
115
|
end
|
137
116
|
|
@@ -153,10 +132,12 @@ module Mailosaur
|
|
153
132
|
# (in milliseconds).
|
154
133
|
# @param received_after [DateTime] Limits results to only messages received
|
155
134
|
# after this date/time.
|
135
|
+
# @param error_on_timeout [Boolean] When set to false, an error will not be
|
136
|
+
# throw if timeout is reached (default: true).
|
156
137
|
#
|
157
138
|
# @return [MessageListResult] operation results.
|
158
139
|
#
|
159
|
-
def search(server, criteria, page: nil, items_per_page: nil, timeout: nil, received_after: nil) # rubocop:disable all
|
140
|
+
def search(server, criteria, page: nil, items_per_page: nil, timeout: nil, received_after: nil, error_on_timeout: true) # rubocop:disable all
|
160
141
|
url = 'api/messages/search?server=' + server
|
161
142
|
url += page ? '&page=' + page.to_s : ''
|
162
143
|
url += items_per_page ? '&itemsPerPage=' + items_per_page.to_s : ''
|
@@ -168,11 +149,7 @@ module Mailosaur
|
|
168
149
|
loop do
|
169
150
|
response = conn.post url, criteria.to_json
|
170
151
|
|
171
|
-
unless response.status == 200
|
172
|
-
error_model = JSON.load(response.body)
|
173
|
-
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model) # rubocop:disable Metrics/LineLength
|
174
|
-
raise mailosaur_error
|
175
|
-
end
|
152
|
+
@handle_http_error.call(response) unless response.status == 200
|
176
153
|
|
177
154
|
model = JSON.load(response.body)
|
178
155
|
return Mailosaur::Models::MessageListResult.new(model) if timeout.to_i.zero? || !model['items'].empty?
|
@@ -185,7 +162,9 @@ module Mailosaur
|
|
185
162
|
|
186
163
|
## Stop if timeout will be exceeded
|
187
164
|
if ((1000 * (Time.now.to_f - start_time).to_i) + delay) > timeout
|
188
|
-
|
165
|
+
return Mailosaur::Models::MessageListResult.new(model) unless error_on_timeout
|
166
|
+
|
167
|
+
raise Mailosaur::MailosaurError.new('No matching messages found in time. By default, only messages received in the last hour are checked (use receivedAfter to override this).', 'search_timeout')
|
189
168
|
end
|
190
169
|
|
191
170
|
sleep(delay / 1000)
|
@@ -2,11 +2,17 @@ module Mailosaur
|
|
2
2
|
module Models
|
3
3
|
class SearchCriteria < BaseModel
|
4
4
|
def initialize(data = {})
|
5
|
+
@sent_from = data['sentFrom']
|
5
6
|
@sent_to = data['sentTo']
|
6
7
|
@subject = data['subject']
|
7
8
|
@body = data['body']
|
9
|
+
@match = data['match'] || 'ALL'
|
8
10
|
end
|
9
11
|
|
12
|
+
# @return [String] The full email address from which the target email was
|
13
|
+
# sent.
|
14
|
+
attr_accessor :sent_from
|
15
|
+
|
10
16
|
# @return [String] The full email address to which the target email was
|
11
17
|
# sent.
|
12
18
|
attr_accessor :sent_to
|
@@ -18,6 +24,11 @@ module Mailosaur
|
|
18
24
|
# @return [String] The value to seek within the target email's HTML or
|
19
25
|
# text body.
|
20
26
|
attr_accessor :body
|
27
|
+
|
28
|
+
# @return [String] If set to ALL (default), then only results that match all
|
29
|
+
# specified criteria will be returned. If set to ANY, results that match any of the
|
30
|
+
# specified criteria will be returned.
|
31
|
+
attr_accessor :match
|
21
32
|
end
|
22
33
|
end
|
23
34
|
end
|
@@ -3,21 +3,15 @@ module Mailosaur
|
|
3
3
|
class Server < BaseModel
|
4
4
|
def initialize(data = {})
|
5
5
|
@id = data['id']
|
6
|
-
@password = data['password']
|
7
6
|
@name = data['name']
|
8
7
|
@users = data['users']
|
9
8
|
@messages = data['messages']
|
10
|
-
@forwarding_rules = []
|
11
|
-
(data['forwardingRules'] || []).each do |i| @forwarding_rules << Mailosaur::Models::ForwardingRule.new(i) end
|
12
9
|
end
|
13
10
|
|
14
11
|
# @return [String] Unique identifier for the server. Used as username for
|
15
12
|
# SMTP/POP3 authentication.
|
16
13
|
attr_accessor :id
|
17
14
|
|
18
|
-
# @return [String] SMTP/POP3 password.
|
19
|
-
attr_accessor :password
|
20
|
-
|
21
15
|
# @return [String] A name used to identify the server.
|
22
16
|
attr_accessor :name
|
23
17
|
|
@@ -26,10 +20,6 @@ module Mailosaur
|
|
26
20
|
|
27
21
|
# @return [Integer] The number of messages currently in the server.
|
28
22
|
attr_accessor :messages
|
29
|
-
|
30
|
-
# @return [Array<ForwardingRule>] The rules used to manage email
|
31
|
-
# forwarding for this server.
|
32
|
-
attr_accessor :forwarding_rules
|
33
23
|
end
|
34
24
|
end
|
35
25
|
end
|
data/lib/Mailosaur/servers.rb
CHANGED
@@ -4,8 +4,9 @@ module Mailosaur
|
|
4
4
|
# Creates and initializes a new instance of the Servers class.
|
5
5
|
# @param client connection.
|
6
6
|
#
|
7
|
-
def initialize(conn)
|
7
|
+
def initialize(conn, handle_http_error)
|
8
8
|
@conn = conn
|
9
|
+
@handle_http_error = handle_http_error
|
9
10
|
end
|
10
11
|
|
11
12
|
# @return [Connection] the client connection.
|
@@ -21,13 +22,7 @@ module Mailosaur
|
|
21
22
|
#
|
22
23
|
def list
|
23
24
|
response = conn.get 'api/servers'
|
24
|
-
|
25
|
-
unless response.status == 200
|
26
|
-
error_model = JSON.load(response.body)
|
27
|
-
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
|
28
|
-
raise mailosaur_error
|
29
|
-
end
|
30
|
-
|
25
|
+
@handle_http_error.call(response) unless response.status == 200
|
31
26
|
model = JSON.load(response.body)
|
32
27
|
Mailosaur::Models::ServerListResult.new(model)
|
33
28
|
end
|
@@ -43,13 +38,7 @@ module Mailosaur
|
|
43
38
|
#
|
44
39
|
def create(server_create_options)
|
45
40
|
response = conn.post 'api/servers', server_create_options.to_json
|
46
|
-
|
47
|
-
unless response.status == 200
|
48
|
-
error_model = JSON.load(response.body)
|
49
|
-
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
|
50
|
-
raise mailosaur_error
|
51
|
-
end
|
52
|
-
|
41
|
+
@handle_http_error.call(response) unless response.status == 200
|
53
42
|
model = JSON.load(response.body)
|
54
43
|
Mailosaur::Models::Server.new(model)
|
55
44
|
end
|
@@ -66,13 +55,7 @@ module Mailosaur
|
|
66
55
|
#
|
67
56
|
def get(id)
|
68
57
|
response = conn.get 'api/servers/' + id
|
69
|
-
|
70
|
-
unless response.status == 200
|
71
|
-
error_model = JSON.load(response.body)
|
72
|
-
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
|
73
|
-
raise mailosaur_error
|
74
|
-
end
|
75
|
-
|
58
|
+
@handle_http_error.call(response) unless response.status == 200
|
76
59
|
model = JSON.load(response.body)
|
77
60
|
Mailosaur::Models::Server.new(model)
|
78
61
|
end
|
@@ -89,13 +72,7 @@ module Mailosaur
|
|
89
72
|
#
|
90
73
|
def update(id, server)
|
91
74
|
response = conn.put 'api/servers/' + id, server.to_json
|
92
|
-
|
93
|
-
unless response.status == 200
|
94
|
-
error_model = JSON.load(response.body)
|
95
|
-
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
|
96
|
-
raise mailosaur_error
|
97
|
-
end
|
98
|
-
|
75
|
+
@handle_http_error.call(response) unless response.status == 200
|
99
76
|
model = JSON.load(response.body)
|
100
77
|
Mailosaur::Models::Server.new(model)
|
101
78
|
end
|
@@ -110,19 +87,13 @@ module Mailosaur
|
|
110
87
|
#
|
111
88
|
def delete(id)
|
112
89
|
response = conn.delete 'api/servers/' + id
|
113
|
-
|
114
|
-
unless response.status == 204
|
115
|
-
error_model = JSON.load(response.body)
|
116
|
-
mailosaur_error = Mailosaur::MailosaurError.new('Operation returned an invalid status code \'' + response.status.to_s + '\'', error_model)
|
117
|
-
raise mailosaur_error
|
118
|
-
end
|
119
|
-
|
90
|
+
@handle_http_error.call(response) unless response.status == 204
|
120
91
|
nil
|
121
92
|
end
|
122
93
|
|
123
94
|
def generate_email_address(server)
|
124
|
-
host = ENV['MAILOSAUR_SMTP_HOST'] || 'mailosaur.
|
125
|
-
'%s.%s
|
95
|
+
host = ENV['MAILOSAUR_SMTP_HOST'] || 'mailosaur.net'
|
96
|
+
'%s@%s.%s' % [SecureRandom.hex(3), server, host]
|
126
97
|
end
|
127
98
|
end
|
128
99
|
end
|
data/lib/Mailosaur/version.rb
CHANGED
data/lib/mailosaur.rb
CHANGED
@@ -27,7 +27,6 @@ module Mailosaur
|
|
27
27
|
autoload :MessageListResult, 'Mailosaur/models/message_list_result.rb'
|
28
28
|
autoload :Attachment, 'Mailosaur/models/attachment.rb'
|
29
29
|
autoload :SearchCriteria, 'Mailosaur/models/search_criteria.rb'
|
30
|
-
autoload :ForwardingRule, 'Mailosaur/models/forwarding_rule.rb'
|
31
30
|
autoload :MessageContent, 'Mailosaur/models/message_content.rb'
|
32
31
|
autoload :Server, 'Mailosaur/models/server.rb'
|
33
32
|
autoload :Link, 'Mailosaur/models/link.rb'
|
@@ -50,22 +49,22 @@ module Mailosaur
|
|
50
49
|
|
51
50
|
# @return [Analysis] analysis
|
52
51
|
def analysis
|
53
|
-
@analysis ||= Analysis.new(connection)
|
52
|
+
@analysis ||= Analysis.new(connection, method(:handle_http_error))
|
54
53
|
end
|
55
54
|
|
56
55
|
# @return [Files] files
|
57
56
|
def files
|
58
|
-
@files ||= Files.new(connection)
|
57
|
+
@files ||= Files.new(connection, method(:handle_http_error))
|
59
58
|
end
|
60
59
|
|
61
60
|
# @return [Messages] messages
|
62
61
|
def messages
|
63
|
-
@messages ||= Messages.new(connection)
|
62
|
+
@messages ||= Messages.new(connection, method(:handle_http_error))
|
64
63
|
end
|
65
64
|
|
66
65
|
# @return [Servers] servers
|
67
66
|
def servers
|
68
|
-
@servers ||= Servers.new(connection)
|
67
|
+
@servers ||= Servers.new(connection, method(:handle_http_error))
|
69
68
|
end
|
70
69
|
|
71
70
|
private
|
@@ -78,5 +77,20 @@ module Mailosaur
|
|
78
77
|
}
|
79
78
|
}).tap { |conn| conn.basic_auth(@api_key, '') }
|
80
79
|
end
|
80
|
+
|
81
|
+
def handle_http_error(response)
|
82
|
+
case response.status
|
83
|
+
when 400
|
84
|
+
raise Mailosaur::MailosaurError.new('Request had one or more invalid parameters.', 'invalid_request', response.status, response.body)
|
85
|
+
when 401
|
86
|
+
raise Mailosaur::MailosaurError.new('Authentication failed, check your API key.', 'authentication_error', response.status, response.body)
|
87
|
+
when 403
|
88
|
+
raise Mailosaur::MailosaurError.new('Insufficient permission to perform that task.', 'permission_error', response.status, response.body)
|
89
|
+
when 404
|
90
|
+
raise Mailosaur::MailosaurError.new('Request did not find any matching resources.', 'invalid_request', response.status, response.body)
|
91
|
+
else
|
92
|
+
raise Mailosaur::MailosaurError.new('An API error occurred, see httpResponse for further information.', 'api_error', response.status, response.body)
|
93
|
+
end
|
94
|
+
end
|
81
95
|
end
|
82
96
|
end
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailosaur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 7.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Mailosaur
|
7
|
+
- Mailosaur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.9.0
|
20
17
|
- - "<="
|
21
18
|
- !ruby/object:Gem::Version
|
22
19
|
version: '1.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.9.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 0.9.0
|
30
27
|
- - "<="
|
31
28
|
- !ruby/object:Gem::Version
|
32
29
|
version: '1.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.9.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: json
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - ">="
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: 1.7.5
|
40
37
|
- - "<="
|
41
38
|
- !ruby/object:Gem::Version
|
42
39
|
version: '3.0'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.7.5
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- - ">="
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: 1.7.5
|
50
47
|
- - "<="
|
51
48
|
- !ruby/object:Gem::Version
|
52
49
|
version: '3.0'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.7.5
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: mail
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,22 +74,22 @@ dependencies:
|
|
74
74
|
name: rake
|
75
75
|
requirement: !ruby/object:Gem::Requirement
|
76
76
|
requirements:
|
77
|
-
- - ">="
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
version: 12.3.0
|
80
77
|
- - "~>"
|
81
78
|
- !ruby/object:Gem::Version
|
82
79
|
version: '12.3'
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 12.3.0
|
83
83
|
type: :development
|
84
84
|
prerelease: false
|
85
85
|
version_requirements: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 12.3.0
|
90
87
|
- - "~>"
|
91
88
|
- !ruby/object:Gem::Version
|
92
89
|
version: '12.3'
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 12.3.0
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
name: rubocop
|
95
95
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,7 +144,8 @@ dependencies:
|
|
144
144
|
- - ">="
|
145
145
|
- !ruby/object:Gem::Version
|
146
146
|
version: 3.2.7
|
147
|
-
description: Ruby
|
147
|
+
description: The Mailosaur Ruby library lets you integrate email and SMS testing into
|
148
|
+
your continuous integration process.
|
148
149
|
email: code@mailosaur.com
|
149
150
|
executables: []
|
150
151
|
extensions: []
|
@@ -158,7 +159,6 @@ files:
|
|
158
159
|
- lib/Mailosaur/messages.rb
|
159
160
|
- lib/Mailosaur/models/attachment.rb
|
160
161
|
- lib/Mailosaur/models/base_model.rb
|
161
|
-
- lib/Mailosaur/models/forwarding_rule.rb
|
162
162
|
- lib/Mailosaur/models/image.rb
|
163
163
|
- lib/Mailosaur/models/link.rb
|
164
164
|
- lib/Mailosaur/models/message.rb
|
@@ -179,10 +179,15 @@ files:
|
|
179
179
|
- lib/Mailosaur/servers.rb
|
180
180
|
- lib/Mailosaur/version.rb
|
181
181
|
- lib/mailosaur.rb
|
182
|
-
homepage: https://mailosaur.com
|
182
|
+
homepage: https://mailosaur.com/
|
183
183
|
licenses:
|
184
184
|
- MIT
|
185
|
-
metadata:
|
185
|
+
metadata:
|
186
|
+
bug_tracker_uri: https://github.com/mailosaur/mailosaur-ruby/issues
|
187
|
+
documentation_uri: https://mailosaur.com/docs/email-testing/ruby/
|
188
|
+
github_repo: ssh://github.com/mailosaur/mailosaur-ruby
|
189
|
+
homepage_uri: https://mailosaur.com/
|
190
|
+
source_code_uri: https://github.com/mailosaur/mailosaur-ruby
|
186
191
|
post_install_message:
|
187
192
|
rdoc_options: []
|
188
193
|
require_paths:
|
@@ -198,8 +203,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
203
|
- !ruby/object:Gem::Version
|
199
204
|
version: '0'
|
200
205
|
requirements: []
|
201
|
-
rubygems_version: 3.
|
206
|
+
rubygems_version: 3.2.3
|
202
207
|
signing_key:
|
203
208
|
specification_version: 4
|
204
|
-
summary: Ruby
|
209
|
+
summary: The Mailosaur Ruby library
|
205
210
|
test_files: []
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Mailosaur
|
2
|
-
module Models
|
3
|
-
class ForwardingRule < BaseModel
|
4
|
-
def initialize(data = {})
|
5
|
-
@field = data['field']
|
6
|
-
@operator = data['operator']
|
7
|
-
@value = data['value']
|
8
|
-
@forward_to = data['forwardTo']
|
9
|
-
end
|
10
|
-
|
11
|
-
# @return [Enum] Possible values include: 'from', 'to', 'subject'
|
12
|
-
attr_accessor :field
|
13
|
-
|
14
|
-
# @return [Enum] Possible values include: 'endsWith', 'startsWith',
|
15
|
-
# 'contains'
|
16
|
-
attr_accessor :operator
|
17
|
-
|
18
|
-
# @return [String]
|
19
|
-
attr_accessor :value
|
20
|
-
|
21
|
-
# @return [String]
|
22
|
-
attr_accessor :forward_to
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|