preflight_qa 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 58029b8709fbd90777e57cca90107d05606e0ffbf76e6b34fbc21acfa82af9c5
4
+ data.tar.gz: 82891a7d96801e681fb9a48a8807ca4811bc273a8b7f7a47f8b9755bac1f5a39
5
+ SHA512:
6
+ metadata.gz: d832c308ac3ff42ffc1d6b7b8e6ad7c622c83cccff3872466976888fb17104e8117c3986d4273f39aa8e40cee22eeb743cf6afa0d511b20946962af0709d4328
7
+ data.tar.gz: c703e98ad92ddef5cb5273135af13a79c8d6e90a1c98ffd738d80900bb9959600f4ef97d24f997323ed8d40646c6c98734619117e709a6168ae35587127bb67a
@@ -0,0 +1,10 @@
1
+ # Code of Conduct
2
+
3
+ "preflight_qa" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
4
+
5
+ * Participants will be tolerant of opposing views.
6
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
+ * When interpreting the words and actions of others, participants should always assume good intentions.
8
+ * Behaviour which can be reasonably considered harassment will not be tolerated.
9
+
10
+ If you have any concerns about behaviour within this project, please contact us at ["hello@preflight.qa"](mailto:"hello@preflight.qa").
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Preflight Software Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # PreflightQA
2
+
3
+ Official Ruby library for interacting with the https://preflight.qa API.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ ```bash
10
+ bundle add preflight_qa
11
+ ```
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ ```bash
16
+ gem install preflight_qa
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ Configure the gem with your PreflightQA API key:
22
+
23
+ ```ruby
24
+ PreflightQA.configure do |config|
25
+ config.api_key = "xxxxxxx"
26
+ end
27
+ ```
28
+
29
+ You can override the default API host if needed:
30
+
31
+ ```ruby
32
+ PreflightQA.configure do |config|
33
+ config.api_key = "xxxxxxx"
34
+ config.base_url = "https://api.preflight.qa"
35
+ end
36
+ ```
37
+
38
+ List available apps:
39
+
40
+ ```ruby
41
+ apps = PreflightQA::Apps.list
42
+ apps["apple_mail_mac"]["name"]
43
+ apps["apple_mail_mac"]["modes"]
44
+ ```
45
+
46
+ Create a screenshot submission for all default apps:
47
+
48
+ ```ruby
49
+ submission = PreflightQA::Screenshots.create(
50
+ subject: "My Test Email",
51
+ html: "<html><body>Hello world</body></html>"
52
+ )
53
+
54
+ submission.uuid
55
+ submission.status
56
+ submission.code
57
+ ```
58
+
59
+ `webhook_url` is optional. If you want PreflightQA to notify your app when rendering is finished, pass it explicitly:
60
+
61
+ ```ruby
62
+ submission = PreflightQA::Screenshots.create(
63
+ subject: "My Test Email",
64
+ html: "<html><body>Hello world</body></html>",
65
+ webhook_url: "https://example.com/preflight/webhook"
66
+ )
67
+ ```
68
+
69
+ You can also limit the request to specific apps and modes:
70
+
71
+ ```ruby
72
+ submission = PreflightQA::Screenshots.create(
73
+ subject: "My Test Email",
74
+ html: "<html><body>Hello world</body></html>",
75
+ apps: {
76
+ apple_mail_mac: { modes: [:light, :dark] },
77
+ outlook_mac: { modes: [:light] }
78
+ }
79
+ )
80
+ ```
81
+
82
+ Find screenshots for a submission:
83
+
84
+ ```ruby
85
+ screenshots = PreflightQA::Screenshots.find(submission.uuid)
86
+
87
+ screenshots.each do |screenshot|
88
+ puts "#{screenshot.app}: #{screenshot.status} -> #{screenshot.url}"
89
+ end
90
+ ```
91
+
92
+ `PreflightQA::Apps.list` returns the raw `data["apps"]` hash from the API.
93
+
94
+ `PreflightQA::Screenshots.create` returns `PreflightQA::Submission` with `uuid`, `status`, `code`, and `raw`.
95
+
96
+ `PreflightQA::Screenshots.find` returns `Array<PreflightQA::Screenshot>`.
97
+
98
+ ## Development
99
+
100
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
101
+
102
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
103
+
104
+ ## Contributing
105
+
106
+ Bug reports and pull requests are welcome on GitHub at https://github.com/PreflightQA/ruby_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/PreflightQA/ruby_api/blob/main/CODE_OF_CONDUCT.md).
107
+
108
+ ## License
109
+
110
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
111
+
112
+ ## Code of Conduct
113
+
114
+ Everyone interacting in the PreflightQA project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/PreflightQA/ruby_api/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: [:spec, :rubocop]
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PreflightQA
4
+ # Resource helpers for listing configured PreflightQA apps.
5
+ module Apps
6
+ module_function
7
+
8
+ def list
9
+ payload = PreflightQA.client.get("/apps")
10
+ apps_from(payload)
11
+ end
12
+
13
+ def apps_from(payload)
14
+ payload.dig("data", "apps") || payload["apps"] || {}
15
+ end
16
+ private_class_method :apps_from
17
+ end
18
+ end
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "net/http"
5
+ require "uri"
6
+
7
+ module PreflightQA
8
+ # Low-level HTTP client responsible for authenticated JSON requests.
9
+ class Client
10
+ NETWORK_ERRORS = [
11
+ EOFError,
12
+ Errno::ECONNREFUSED,
13
+ Errno::ECONNRESET,
14
+ Errno::ETIMEDOUT,
15
+ Net::OpenTimeout,
16
+ Net::ReadTimeout,
17
+ SocketError
18
+ ].freeze
19
+
20
+ def initialize(config)
21
+ @config = config
22
+ end
23
+
24
+ def get(path)
25
+ request(Net::HTTP::Get, path)
26
+ end
27
+
28
+ def post(path, body:)
29
+ request(Net::HTTP::Post, path, body: body)
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :config
35
+
36
+ def request(http_class, path, body: nil)
37
+ validate_configuration!
38
+ uri = build_uri(path)
39
+ response = perform_request(uri, build_request(http_class, uri, body))
40
+ handle_response(response)
41
+ rescue *NETWORK_ERRORS => e
42
+ raise RequestError, "Network error: #{e.message}"
43
+ end
44
+
45
+ def validate_configuration!
46
+ return if config.api_key && !config.api_key.strip.empty?
47
+
48
+ raise ConfigurationError, "PreflightQA api_key is required"
49
+ end
50
+
51
+ def build_request(http_class, uri, body)
52
+ request = http_class.new(uri)
53
+ request["Authorization"] = "Bearer #{config.api_key}"
54
+ request["Content-Type"] = "application/json"
55
+ request["Accept"] = "application/json"
56
+ request.body = JSON.generate(normalize_payload(body)) unless body.nil?
57
+ request
58
+ end
59
+
60
+ def build_uri(path)
61
+ URI.join("#{config.base_url}/", path.sub(%r{\A/}, ""))
62
+ end
63
+
64
+ def perform_request(uri, request)
65
+ Net::HTTP.start(
66
+ uri.hostname,
67
+ uri.port,
68
+ use_ssl: uri.scheme == "https",
69
+ open_timeout: config.open_timeout,
70
+ read_timeout: config.read_timeout
71
+ ) do |http|
72
+ http.request(request)
73
+ end
74
+ end
75
+
76
+ def handle_response(response)
77
+ status = response.code.to_i
78
+ body = response.body
79
+
80
+ return parse_body(body) if status.between?(200, 299)
81
+
82
+ error_class = error_class_for(status)
83
+ message = response.message || "Request failed"
84
+ raise error_class.new(message, status: status, body: body)
85
+ end
86
+
87
+ def parse_body(body)
88
+ return nil if body.nil? || body.strip.empty?
89
+
90
+ JSON.parse(body)
91
+ rescue JSON::ParserError => e
92
+ raise RequestError.new("Invalid JSON response: #{e.message}", body: body)
93
+ end
94
+
95
+ def error_class_for(status)
96
+ case status
97
+ when 401 then AuthenticationError
98
+ when 429 then RateLimitError
99
+ when 500..599 then ServerError
100
+ else RequestError
101
+ end
102
+ end
103
+
104
+ def normalize_payload(value)
105
+ case value
106
+ when Array
107
+ value.map { |item| normalize_payload(item) }
108
+ when Hash
109
+ normalize_payload_hash(value)
110
+ when Symbol
111
+ value.to_s
112
+ else
113
+ value
114
+ end
115
+ end
116
+
117
+ def normalize_payload_hash(value)
118
+ value.each_with_object({}) do |(key, nested_value), normalized|
119
+ normalized[key.to_s] = normalize_payload(nested_value)
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PreflightQA
4
+ # Stores runtime settings used to build authenticated API requests.
5
+ class Configuration
6
+ DEFAULT_BASE_URL = "https://api.preflight.qa"
7
+ DEFAULT_OPEN_TIMEOUT = 5
8
+ DEFAULT_READ_TIMEOUT = 30
9
+
10
+ attr_accessor :api_key, :base_url, :open_timeout, :read_timeout
11
+
12
+ def initialize
13
+ @base_url = DEFAULT_BASE_URL
14
+ @open_timeout = DEFAULT_OPEN_TIMEOUT
15
+ @read_timeout = DEFAULT_READ_TIMEOUT
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PreflightQA
4
+ class Error < StandardError; end
5
+
6
+ class ConfigurationError < Error; end
7
+
8
+ # Raised when the API returns an error response or the response cannot be parsed.
9
+ class RequestError < Error
10
+ attr_reader :status, :body
11
+
12
+ def initialize(message = nil, status: nil, body: nil)
13
+ super(message)
14
+ @status = status
15
+ @body = body
16
+ end
17
+ end
18
+
19
+ class AuthenticationError < RequestError; end
20
+ class RateLimitError < RequestError; end
21
+ class ServerError < RequestError; end
22
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/inflector"
4
+ require "rails/railtie"
5
+
6
+ module PreflightQA
7
+ # Rails integration for preserving the QA acronym in inflections.
8
+ class Railtie < Rails::Railtie
9
+ initializer "preflight_qa.inflections" do
10
+ ActiveSupport::Inflector.inflections(:en) do |inflect|
11
+ inflect.acronym "QA"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PreflightQA
4
+ Screenshot = Data.define(:uuid, :app, :mode, :status, :url, :raw) do
5
+ def self.from_payload(payload, uuid: nil)
6
+ new(
7
+ uuid: payload["uuid"] || uuid,
8
+ app: payload["app"],
9
+ mode: payload["mode"],
10
+ status: payload["status"],
11
+ url: payload["url"],
12
+ raw: payload
13
+ )
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PreflightQA
4
+ # Resource helpers for creating screenshot submissions and fetching screenshot results.
5
+ module Screenshots
6
+ module_function
7
+
8
+ def create(subject:, html:, **options)
9
+ Submission.from_payload(
10
+ PreflightQA.client.post("/screenshots", body: build_create_payload(subject:, html:, options:))
11
+ )
12
+ end
13
+
14
+ def find(uuid)
15
+ payload = PreflightQA.client.get("/screenshots/#{uuid}")
16
+ screenshots = extract_screenshots(payload)
17
+ screenshots.map { |screenshot| Screenshot.from_payload(screenshot, uuid: extract_uuid(payload, uuid)) }
18
+ end
19
+
20
+ def extract_screenshots(payload)
21
+ return payload if payload.is_a?(Array)
22
+
23
+ payload.dig("data", "screenshots") ||
24
+ payload["screenshots"] ||
25
+ Array(payload.dig("data", "screenshot")).compact
26
+ end
27
+ private_class_method :extract_screenshots
28
+
29
+ def extract_uuid(payload, fallback)
30
+ payload.dig("meta", "uuid") ||
31
+ payload.dig("data", "uuid") ||
32
+ payload.dig("data", "submission", "uuid") ||
33
+ fallback
34
+ end
35
+ private_class_method :extract_uuid
36
+
37
+ def build_create_payload(subject:, html:, options:)
38
+ payload = { subject: subject, html: html }
39
+ append_optional_field(payload, :apps, options)
40
+ append_optional_field(payload, :webhook_url, options)
41
+ payload.merge(options.except(:apps, :webhook_url))
42
+ end
43
+ private_class_method :build_create_payload
44
+
45
+ def append_optional_field(payload, key, options)
46
+ return unless options.key?(key)
47
+ return if options[key].nil?
48
+
49
+ payload[key] = key == :apps ? normalize_apps(options[key]) : options[key]
50
+ end
51
+ private_class_method :append_optional_field
52
+
53
+ def normalize_apps(apps)
54
+ raise ArgumentError, "apps must be a hash of app keys to mode hashes" unless apps.is_a?(Hash)
55
+
56
+ apps.each_with_object({}) do |(app, config), normalized|
57
+ normalized[app.to_s] = normalize_app_config(config)
58
+ end
59
+ end
60
+ private_class_method :normalize_apps
61
+
62
+ def normalize_app_config(config)
63
+ raise ArgumentError, "each app config must be a hash with :modes" unless config.is_a?(Hash)
64
+
65
+ modes = config[:modes] || config["modes"]
66
+ raise ArgumentError, "each app config must include :modes" if modes.nil?
67
+
68
+ { modes: normalize_modes(modes) }
69
+ end
70
+ private_class_method :normalize_app_config
71
+
72
+ def normalize_modes(modes)
73
+ Array(modes).map(&:to_s)
74
+ end
75
+ private_class_method :normalize_modes
76
+ end
77
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PreflightQA
4
+ Submission = Data.define(:uuid, :status, :code, :raw) do
5
+ def self.from_payload(payload)
6
+ new(
7
+ uuid: pick_value(payload, "uuid"),
8
+ status: pick_value(payload, "status"),
9
+ code: pick_value(payload, "code"),
10
+ raw: payload
11
+ )
12
+ end
13
+
14
+ def self.pick_value(payload, key)
15
+ payload.dig("meta", key) || submission_source(payload)[key]
16
+ end
17
+
18
+ def self.submission_source(payload)
19
+ data = payload["data"] || payload
20
+ data["submission"] || data["request"] || data["screenshot_request"] || data
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PreflightQA
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "preflight_qa/version"
4
+ require_relative "preflight_qa/configuration"
5
+ require_relative "preflight_qa/errors"
6
+ require_relative "preflight_qa/client"
7
+ require_relative "preflight_qa/submission"
8
+ require_relative "preflight_qa/screenshot"
9
+ require_relative "preflight_qa/apps"
10
+ require_relative "preflight_qa/screenshots"
11
+
12
+ begin
13
+ require_relative "preflight_qa/railtie"
14
+ rescue LoadError
15
+ # Not running in Rails
16
+ end
17
+
18
+ module PreflightQA
19
+ # Public entrypoint for configuring and accessing the PreflightQA API client.
20
+ class << self
21
+ def configure
22
+ yield(current_configuration) if block_given?
23
+ current_configuration
24
+ end
25
+
26
+ def reset_config!
27
+ @current_configuration = Configuration.new
28
+ end
29
+
30
+ def client
31
+ Client.new(current_configuration)
32
+ end
33
+
34
+ private
35
+
36
+ def current_configuration
37
+ @current_configuration ||= Configuration.new
38
+ end
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: preflight_qa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mark Connell
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ email:
13
+ - hello@preflight.qa
14
+ executables: []
15
+ extensions: []
16
+ extra_rdoc_files: []
17
+ files:
18
+ - CODE_OF_CONDUCT.md
19
+ - LICENSE.txt
20
+ - README.md
21
+ - Rakefile
22
+ - lib/preflight_qa.rb
23
+ - lib/preflight_qa/apps.rb
24
+ - lib/preflight_qa/client.rb
25
+ - lib/preflight_qa/configuration.rb
26
+ - lib/preflight_qa/errors.rb
27
+ - lib/preflight_qa/railtie.rb
28
+ - lib/preflight_qa/screenshot.rb
29
+ - lib/preflight_qa/screenshots.rb
30
+ - lib/preflight_qa/submission.rb
31
+ - lib/preflight_qa/version.rb
32
+ homepage: https://github.com/PreflightQA/ruby_api
33
+ licenses:
34
+ - MIT
35
+ metadata:
36
+ homepage_uri: https://github.com/PreflightQA/ruby_api
37
+ source_code_uri: https://github.com/PreflightQA/ruby_api
38
+ changelog_uri: https://github.com/PreflightQA/ruby_api/releases
39
+ rubygems_mfa_required: 'true'
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 4.0.3
55
+ specification_version: 4
56
+ summary: Official Ruby library for interacting with the PreflightQA API
57
+ test_files: []