mailosaur 7.17.0 → 8.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4e9715da4f69e6078392f4846fe8f85228b1cb0c8efd32f75ab5262ad0b7510
4
- data.tar.gz: 42afb8a6023e449b90e4cb5c185ba02564b307460cdac6082edac492250ebc07
3
+ metadata.gz: 3f9e68987fc63770ca61c94a5091b02ea932bb765ea6dfa1d2d3ca8603e58867
4
+ data.tar.gz: 8683c7bb7ffe561fc491867bb2000437cd3b0541cec1c738d9733c649c6c2d1d
5
5
  SHA512:
6
- metadata.gz: 4d439710cbb8ee21bc8956f6f9b14222e76ab9132e0826bfd4fb612934f3e45059ef3bdadead642c7689af76e3af8849f5f3ed2d4ba4c562e21967d7951f2c0b
7
- data.tar.gz: 9300b227579346522080db84cfa5483f8662af6f288bed790025e0f50e5e4d547a58984132c0d9742f6e3ecbe8a9d75723a1a115e13e1e72fa4b18480a05588b
6
+ metadata.gz: abb3db223ad672d31099e11284a928679c3a3c9db15b9e727c2fbd68119a23fe424bd75116b54b35c6a1b25ce9edb47f7a956baf444835b626a9acf904824bf0
7
+ data.tar.gz: 7a556665627605e074ce413a02be0d839032454445e5592de4367ee1d05707c193205726940a20545edd752926b277da7801e6b1dac9db14b0f738402110a065
data/README.md CHANGED
@@ -11,6 +11,10 @@ Mailosaur lets you automate email and SMS tests as part of software development
11
11
  This guide provides several key sections:
12
12
 
13
13
  - [Get Started](#get-started)
14
+ - [Installation](#installation)
15
+ - [Set your API key](#set-your-api-key)
16
+ - [Create your code](#create-your-code)
17
+ - [API Reference](#api-reference)
14
18
  - [Creating an account](#creating-an-account)
15
19
  - [Test email addresses with Mailosaur](#test-email-addresses-with-mailosaur)
16
20
  - [Find an email](#find-an-email)
@@ -32,11 +36,21 @@ If you get stuck, just contact us at support@mailosaur.com.
32
36
  gem install mailosaur
33
37
  ```
34
38
 
35
- Then import the library into your code. The value for `YOUR_API_KEY` is covered in the next step ([creating an account](#creating-an-account)):
39
+ ### Set your API key
40
+
41
+ Get your API key from the Mailosaur Dashboard and set it as an environment variable:
42
+
43
+ ```sh
44
+ export MAILOSAUR_API_KEY='your-api-key-here'
45
+ ```
46
+
47
+ ### Create your code
48
+
49
+ Then import the library into your code:
36
50
 
37
51
  ```ruby
38
52
  require 'mailosaur'
39
- mailosaur = Mailosaur::MailosaurClient.new("YOUR_API_KEY")
53
+ mailosaur = Mailosaur::MailosaurClient.new()
40
54
  ```
41
55
 
42
56
  ### API Reference
@@ -79,7 +93,7 @@ In automated tests you will want to wait for a new email to arrive. This library
79
93
  ```ruby
80
94
  require 'mailosaur'
81
95
 
82
- mailosaur = Mailosaur::MailosaurClient.new("API_KEY")
96
+ mailosaur = Mailosaur::MailosaurClient.new()
83
97
 
84
98
  # See https://mailosaur.com/app/project/api
85
99
  server_id = "abc123"
@@ -95,7 +109,7 @@ puts(email.subject) # "Hello world!"
95
109
 
96
110
  ### What is this code doing?
97
111
 
98
- 1. Sets up an instance of `MailosaurClient` with your API key.
112
+ 1. Sets up an instance of `MailosaurClient` using the `MAILOSAUR_API_KEY` environment variable.
99
113
  2. Waits for an email to arrive at the server with ID `abc123`.
100
114
  3. Outputs the subject line of the email.
101
115
 
@@ -108,7 +122,7 @@ If your account has [SMS testing](https://mailosaur.com/sms-testing/) enabled, y
108
122
  ```ruby
109
123
  require 'mailosaur'
110
124
 
111
- mailosaur = Mailosaur::MailosaurClient.new("API_KEY")
125
+ mailosaur = Mailosaur::MailosaurClient.new()
112
126
 
113
127
  server_id = "abc123"
114
128
 
@@ -55,9 +55,31 @@ module Mailosaur
55
55
  # @return [NOT_IMPLEMENTED] operation results.
56
56
  #
57
57
  def get_preview(id)
58
- response = conn.get "api/files/previews/#{id}"
59
- @handle_http_error.call(response) unless response.status == 200
60
- response.body
58
+ timeout = 120_000
59
+ poll_count = 0
60
+ start_time = Time.now.to_f
61
+
62
+ loop do
63
+ response = conn.get "api/files/screenshots/#{id}"
64
+
65
+ return response.body if response.status == 200
66
+
67
+ @handle_http_error.call(response) unless response.status == 202
68
+
69
+ delay_pattern = (response.headers['x-ms-delay'] || '1000').split(',').map(&:to_i)
70
+
71
+ delay = poll_count >= delay_pattern.length ? delay_pattern[delay_pattern.length - 1] : delay_pattern[poll_count]
72
+
73
+ poll_count += 1
74
+
75
+ ## Stop if timeout will be exceeded
76
+ if ((1000 * (Time.now.to_f - start_time).to_i) + delay) > timeout
77
+ msg = format('An email preview was not generated in time. The email client may not be available, or the preview ID [%s] may be incorrect.', id)
78
+ raise Mailosaur::MailosaurError.new(msg, 'preview_timeout')
79
+ end
80
+
81
+ sleep(delay / 1000.0)
82
+ end
61
83
  end
62
84
  end
63
85
  end
@@ -248,7 +248,7 @@ module Mailosaur
248
248
  # @return [PreviewListResult] operation result.
249
249
  #
250
250
  def generate_previews(id, options)
251
- response = conn.post "api/messages/#{id}/previews", options.to_json
251
+ response = conn.post "api/messages/#{id}/screenshots", options.to_json
252
252
  @handle_http_error.call(response) unless response.status == 200
253
253
  model = JSON.parse(response.body)
254
254
  Mailosaur::Models::PreviewListResult.new(model)
@@ -0,0 +1,16 @@
1
+ module Mailosaur
2
+ module Models
3
+ class EmailClient < BaseModel
4
+ def initialize(data = {})
5
+ @label = data['label']
6
+ @name = data['name']
7
+ end
8
+
9
+ # @return [String] The unique email client label. Used when generating email preview requests.
10
+ attr_accessor :label
11
+
12
+ # @return [String] The display name of the email client.
13
+ attr_accessor :name
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Mailosaur
2
+ module Models
3
+ class EmailClientListResult < BaseModel
4
+ def initialize(data = {})
5
+ @items = []
6
+ (data['items'] || []).each { |i| @items << Mailosaur::Models::EmailClient.new(i) }
7
+ end
8
+
9
+ # @return [Array<EmailClient>] A list of available email clients with which to generate email previews.
10
+ attr_accessor :items
11
+ end
12
+ end
13
+ end
@@ -1,12 +1,12 @@
1
1
  module Mailosaur
2
2
  module Models
3
3
  class PreviewRequestOptions < BaseModel
4
- def initialize(previews)
5
- @previews = previews
4
+ def initialize(email_clients)
5
+ @email_clients = email_clients
6
6
  end
7
7
 
8
- # @return [PreviewRequest] The list of email preview requests.
9
- attr_accessor :previews
8
+ # @return [Array<String>] The list email clients to generate previews with.
9
+ attr_accessor :email_clients
10
10
  end
11
11
  end
12
12
  end
@@ -17,13 +17,13 @@ module Mailosaur
17
17
  #
18
18
  # Returns a list of available email clients.
19
19
  #
20
- # @return [PreviewEmailClientListResult] operation results.
20
+ # @return [EmailClientListResult] operation results.
21
21
  #
22
22
  def list_email_clients
23
- response = conn.get 'api/previews/clients'
23
+ response = conn.get 'api/screenshots/clients'
24
24
  @handle_http_error.call(response) unless response.status == 200
25
25
  model = JSON.parse(response.body)
26
- Mailosaur::Models::PreviewEmailClientListResult.new(model)
26
+ Mailosaur::Models::EmailClientListResult.new(model)
27
27
  end
28
28
  end
29
29
  end
@@ -1,3 +1,3 @@
1
1
  module Mailosaur
2
- VERSION = '7.17.0'.freeze
2
+ VERSION = '8.1.0'.freeze
3
3
  end
data/lib/mailosaur.rb CHANGED
@@ -55,10 +55,9 @@ module Mailosaur
55
55
  autoload :DeviceCreateOptions, 'Mailosaur/models/device_create_options.rb'
56
56
  autoload :OtpResult, 'Mailosaur/models/otp_result.rb'
57
57
  autoload :Preview, 'Mailosaur/models/preview.rb'
58
- autoload :PreviewEmailClient, 'Mailosaur/models/preview_email_client.rb'
59
- autoload :PreviewEmailClientListResult, 'Mailosaur/models/preview_email_client_list_result.rb'
58
+ autoload :EmailClient, 'Mailosaur/models/email_client.rb'
59
+ autoload :EmailClientListResult, 'Mailosaur/models/email_client_list_result.rb'
60
60
  autoload :PreviewListResult, 'Mailosaur/models/preview_list_result.rb'
61
- autoload :PreviewRequest, 'Mailosaur/models/preview_request.rb'
62
61
  autoload :PreviewRequestOptions, 'Mailosaur/models/preview_request_options.rb'
63
62
  autoload :BaseModel, 'Mailosaur/models/base_model.rb'
64
63
  end
@@ -66,11 +65,15 @@ module Mailosaur
66
65
  class MailosaurClient
67
66
  #
68
67
  # Creates initializes a new instance of the MailosaurClient class.
69
- # @param api_key [String] your Mailosaur API key.
68
+ # @param api_key [String] Optional API key. Overrides the MAILOSAUR_API_KEY environment variable if set.
70
69
  # @param base_url [String] the base URI of the service.
71
70
  #
72
- def initialize(api_key, base_url = 'https://mailosaur.com/')
73
- @api_key = api_key
71
+ def initialize(api_key = nil, base_url: 'https://mailosaur.com/')
72
+ resolved_api_key = api_key || ENV['MAILOSAUR_API_KEY']
73
+
74
+ raise ArgumentError, "'api_key' must be set. Set the MAILOSAUR_API_KEY environment variable or pass it to the MailosaurClient constructor." unless resolved_api_key
75
+
76
+ @api_key = resolved_api_key
74
77
  @base_url = base_url
75
78
  end
76
79
 
@@ -148,6 +151,8 @@ module Mailosaur
148
151
  raise Mailosaur::MailosaurError.new('Insufficient permission to perform that task.', 'permission_error', response.status, response.body)
149
152
  when 404
150
153
  raise Mailosaur::MailosaurError.new('Not found, check input parameters.', 'invalid_request', response.status, response.body)
154
+ when 410
155
+ raise Mailosaur::MailosaurError.new('Permanently expired or deleted.', 'gone', response.status, response.body)
151
156
  else
152
157
  raise Mailosaur::MailosaurError.new('An API error occurred, see httpResponse for further information.', 'api_error', response.status, response.body)
153
158
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailosaur
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.17.0
4
+ version: 8.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mailosaur
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-02 00:00:00.000000000 Z
11
+ date: 2026-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -157,6 +157,8 @@ files:
157
157
  - lib/Mailosaur/models/device_list_result.rb
158
158
  - lib/Mailosaur/models/dns_records.rb
159
159
  - lib/Mailosaur/models/email_authentication_result.rb
160
+ - lib/Mailosaur/models/email_client.rb
161
+ - lib/Mailosaur/models/email_client_list_result.rb
160
162
  - lib/Mailosaur/models/image.rb
161
163
  - lib/Mailosaur/models/link.rb
162
164
  - lib/Mailosaur/models/message.rb
@@ -171,10 +173,7 @@ files:
171
173
  - lib/Mailosaur/models/metadata.rb
172
174
  - lib/Mailosaur/models/otp_result.rb
173
175
  - lib/Mailosaur/models/preview.rb
174
- - lib/Mailosaur/models/preview_email_client.rb
175
- - lib/Mailosaur/models/preview_email_client_list_result.rb
176
176
  - lib/Mailosaur/models/preview_list_result.rb
177
- - lib/Mailosaur/models/preview_request.rb
178
177
  - lib/Mailosaur/models/preview_request_options.rb
179
178
  - lib/Mailosaur/models/search_criteria.rb
180
179
  - lib/Mailosaur/models/server.rb
@@ -203,7 +202,7 @@ metadata:
203
202
  github_repo: ssh://github.com/mailosaur/mailosaur-ruby
204
203
  homepage_uri: https://mailosaur.com/
205
204
  source_code_uri: https://github.com/mailosaur/mailosaur-ruby
206
- post_install_message:
205
+ post_install_message:
207
206
  rdoc_options: []
208
207
  require_paths:
209
208
  - lib
@@ -218,8 +217,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
217
  - !ruby/object:Gem::Version
219
218
  version: '0'
220
219
  requirements: []
221
- rubygems_version: 3.4.19
222
- signing_key:
220
+ rubygems_version: 3.1.6
221
+ signing_key:
223
222
  specification_version: 4
224
223
  summary: The Mailosaur Ruby library
225
224
  test_files: []
@@ -1,36 +0,0 @@
1
- module Mailosaur
2
- module Models
3
- class PreviewEmailClient < BaseModel
4
- def initialize(data = {})
5
- @id = data['id']
6
- @name = data['name']
7
- @platform_group = data['platformGroup']
8
- @platform_type = data['platformType']
9
- @platform_version = data['platformVersion']
10
- @can_disable_images = data['canDisableImages']
11
- @status = data['status']
12
- end
13
-
14
- # @return [String] Unique identifier for the email preview.
15
- attr_accessor :id
16
-
17
- # @return [String] The display name of the email client.
18
- attr_accessor :name
19
-
20
- # @return [String] Whether the platform is desktop, mobile, or web-based.
21
- attr_accessor :platform_group
22
-
23
- # @return [String] The type of platform on which the email client is running.
24
- attr_accessor :platform_type
25
-
26
- # @return [String] The platform version number.
27
- attr_accessor :platform_version
28
-
29
- # @return [Boolean] If true, images can be disabled when generating previews.
30
- attr_accessor :can_disable_images
31
-
32
- # @return [String] The current status of the email client.
33
- attr_accessor :status
34
- end
35
- end
36
- end
@@ -1,14 +0,0 @@
1
- module Mailosaur
2
- module Models
3
- class PreviewEmailClientListResult < BaseModel
4
- def initialize(data = {})
5
- @items = []
6
- (data['items'] || []).each { |i| @items << Mailosaur::Models::PreviewEmailClient.new(i) }
7
- end
8
-
9
- # @return [Array<PreviewEmailClient>] A list of available email clients with which to generate email previews.
10
- # A list of available email clients.
11
- attr_accessor :items
12
- end
13
- end
14
- end
@@ -1,16 +0,0 @@
1
- module Mailosaur
2
- module Models
3
- class PreviewRequest < BaseModel
4
- def initialize(email_client, disable_images: false)
5
- @email_client = email_client
6
- @disable_images = disable_images
7
- end
8
-
9
- # @return [String] The email client the preview was generated with.
10
- attr_accessor :email_client
11
-
12
- # @return [Boolean] True if images were disabled in the preview.
13
- attr_accessor :disable_images
14
- end
15
- end
16
- end