amritk-scalar-test 0.1.1 → 0.3.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/LICENSE +1 -1
- data/README.md +22 -7
- data/SKILL.md +12 -5
- data/lib/amritk-scalar-test/client.rb +59 -13
- data/lib/amritk-scalar-test/errors.rb +208 -69
- data/lib/amritk-scalar-test/file_part.rb +50 -6
- data/lib/amritk-scalar-test/internal/transport/base_client.rb +578 -0
- data/lib/amritk-scalar-test/internal/transport/pooled_net_requester.rb +210 -0
- data/lib/amritk-scalar-test/internal/type/array_of.rb +168 -0
- data/lib/amritk-scalar-test/internal/type/base_model.rb +524 -0
- data/lib/amritk-scalar-test/internal/type/base_page.rb +55 -0
- data/lib/amritk-scalar-test/internal/type/boolean.rb +77 -0
- data/lib/amritk-scalar-test/internal/type/converter.rb +327 -0
- data/lib/amritk-scalar-test/internal/type/enum.rb +132 -0
- data/lib/amritk-scalar-test/internal/type/file_input.rb +111 -0
- data/lib/amritk-scalar-test/internal/type/hash_of.rb +188 -0
- data/lib/amritk-scalar-test/internal/type/request_parameters.rb +42 -0
- data/lib/amritk-scalar-test/internal/type/union.rb +238 -0
- data/lib/amritk-scalar-test/internal/type/unknown.rb +81 -0
- data/lib/amritk-scalar-test/internal/util.rb +966 -0
- data/lib/amritk-scalar-test/internal.rb +20 -0
- data/lib/amritk-scalar-test/models/ping_ping_params.rb +14 -0
- data/lib/amritk-scalar-test/models/ping_ping_response.rb +16 -0
- data/lib/amritk-scalar-test/models.rb +38 -33
- data/lib/amritk-scalar-test/request_options.rb +68 -13
- data/lib/amritk-scalar-test/resources/ping.rb +22 -61
- data/lib/amritk-scalar-test/version.rb +2 -3
- data/lib/amritk-scalar-test.rb +51 -2
- data/rbi/amritk-scalar-test/client.rbi +38 -0
- data/rbi/amritk-scalar-test/errors.rbi +205 -0
- data/rbi/amritk-scalar-test/file_part.rbi +37 -0
- data/rbi/amritk-scalar-test/internal/transport/base_client.rbi +297 -0
- data/rbi/amritk-scalar-test/internal/transport/pooled_net_requester.rbi +82 -0
- data/rbi/amritk-scalar-test/internal/type/array_of.rbi +104 -0
- data/rbi/amritk-scalar-test/internal/type/base_model.rbi +299 -0
- data/rbi/amritk-scalar-test/internal/type/base_page.rbi +42 -0
- data/rbi/amritk-scalar-test/internal/type/boolean.rbi +58 -0
- data/rbi/amritk-scalar-test/internal/type/converter.rbi +204 -0
- data/rbi/amritk-scalar-test/internal/type/enum.rbi +82 -0
- data/rbi/amritk-scalar-test/internal/type/file_input.rbi +59 -0
- data/rbi/amritk-scalar-test/internal/type/hash_of.rbi +104 -0
- data/rbi/amritk-scalar-test/internal/type/request_parameters.rbi +29 -0
- data/rbi/amritk-scalar-test/internal/type/union.rbi +126 -0
- data/rbi/amritk-scalar-test/internal/type/unknown.rbi +58 -0
- data/rbi/amritk-scalar-test/internal/util.rbi +512 -0
- data/rbi/amritk-scalar-test/internal.rbi +16 -0
- data/rbi/amritk-scalar-test/models/ping_ping_params.rbi +32 -0
- data/rbi/amritk-scalar-test/models/ping_ping_response.rbi +29 -0
- data/rbi/amritk-scalar-test/models.rbi +5 -0
- data/rbi/amritk-scalar-test/request_options.rbi +55 -0
- data/rbi/amritk-scalar-test/resources/ping.rbi +21 -0
- data/rbi/amritk-scalar-test/version.rbi +5 -0
- data/sig/amritk-scalar-test/client.rbs +21 -0
- data/sig/amritk-scalar-test/errors.rbs +117 -0
- data/sig/amritk-scalar-test/file_part.rbs +21 -0
- data/sig/amritk-scalar-test/internal/transport/base_client.rbs +133 -0
- data/sig/amritk-scalar-test/internal/transport/pooled_net_requester.rbs +48 -0
- data/sig/amritk-scalar-test/internal/type/array_of.rbs +48 -0
- data/sig/amritk-scalar-test/internal/type/base_model.rbs +102 -0
- data/sig/amritk-scalar-test/internal/type/base_page.rbs +24 -0
- data/sig/amritk-scalar-test/internal/type/boolean.rbs +26 -0
- data/sig/amritk-scalar-test/internal/type/converter.rbs +79 -0
- data/sig/amritk-scalar-test/internal/type/enum.rbs +32 -0
- data/sig/amritk-scalar-test/internal/type/file_input.rbs +25 -0
- data/sig/amritk-scalar-test/internal/type/hash_of.rbs +48 -0
- data/sig/amritk-scalar-test/internal/type/request_parameters.rbs +17 -0
- data/sig/amritk-scalar-test/internal/type/union.rbs +52 -0
- data/sig/amritk-scalar-test/internal/type/unknown.rbs +26 -0
- data/sig/amritk-scalar-test/internal/util.rbs +199 -0
- data/sig/amritk-scalar-test/internal.rbs +9 -0
- data/sig/amritk-scalar-test/models/ping_ping_params.rbs +15 -0
- data/sig/amritk-scalar-test/models/ping_ping_response.rbs +15 -0
- data/sig/amritk-scalar-test/models.rbs +3 -0
- data/sig/amritk-scalar-test/request_options.rbs +34 -0
- data/sig/amritk-scalar-test/resources/ping.rbs +11 -0
- data/sig/amritk-scalar-test/version.rbs +3 -0
- data/sig/manifest.yaml +6 -0
- metadata +103 -11
- data/lib/amritk-scalar-test/internal/cursor_page.rb +0 -9
- data/lib/amritk-scalar-test/runtime.rb +0 -893
- data/lib/amritk-scalar-test/webhooks.rb +0 -111
- data/tests/smoke-test.rb +0 -69
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 57d60baeaab95d5b69bfb7398de111026485f80c908a76dd4939e383784fb200
|
|
4
|
+
data.tar.gz: 2853c8c957db2078b5f02d6ee64b0794f810d88a171aaee55c86f44b7c5edafc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d451bbd651ef8d398070475c97f677ecada1a15b50abee623e048c5dc406a9881155c9ad0f00e5e5330e412974eb8dc3ad6c55f883fac752e2dd4956fa1c8387
|
|
7
|
+
data.tar.gz: c3fa8ff2f6698e9488e37ebd3b15e39baee966dced211edc97d07526295de3b9b11aac1c4cd79c9c810e3aae1cb4f24eab7a4ad9d542a79ab0c9cfaeca87cf10
|
data/LICENSE
CHANGED
|
@@ -186,7 +186,7 @@
|
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
|
187
187
|
identification within third-party archives.
|
|
188
188
|
|
|
189
|
-
Copyright
|
|
189
|
+
Copyright 2026 ScalarRubyTest
|
|
190
190
|
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
192
|
you may not use this file except in compliance with the License.
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ScalarRubyTest
|
|
2
2
|
|
|
3
|
-
This library provides convenient access to the
|
|
3
|
+
This library provides convenient access to the ScalarRubyTest REST API from Ruby.
|
|
4
4
|
|
|
5
5
|
The full API of this library can be found in [api.md](./api.md).
|
|
6
6
|
|
|
@@ -23,6 +23,14 @@ The full API of this library can be found in [api.md](./api.md).
|
|
|
23
23
|
|
|
24
24
|
## Installation
|
|
25
25
|
|
|
26
|
+
Add the gem to your application's `Gemfile`:
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
gem "amritk-scalar-test", "~> 0.3.0" # x-release-please-version
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Or install it directly:
|
|
33
|
+
|
|
26
34
|
```sh
|
|
27
35
|
gem install amritk-scalar-test
|
|
28
36
|
```
|
|
@@ -32,7 +40,12 @@ gem install amritk-scalar-test
|
|
|
32
40
|
## Usage
|
|
33
41
|
|
|
34
42
|
```ruby
|
|
43
|
+
require "amritk-scalar-test"
|
|
44
|
+
|
|
45
|
+
client = AmritkScalarTest::Client.new
|
|
46
|
+
|
|
35
47
|
response = client.ping.ping
|
|
48
|
+
|
|
36
49
|
puts response.inspect
|
|
37
50
|
```
|
|
38
51
|
|
|
@@ -55,10 +68,12 @@ Non-success responses throw generated API errors. Error objects expose status, h
|
|
|
55
68
|
```ruby
|
|
56
69
|
begin
|
|
57
70
|
response = client.ping.ping
|
|
71
|
+
|
|
58
72
|
puts response.inspect
|
|
59
|
-
rescue
|
|
73
|
+
rescue AmritkScalarTest::Errors::APIError => error
|
|
60
74
|
puts "#{error.status}: #{error.message}"
|
|
61
75
|
raise
|
|
76
|
+
end
|
|
62
77
|
```
|
|
63
78
|
|
|
64
79
|
<br />
|
|
@@ -70,7 +85,7 @@ Configure the generated client by setting any of these options when you create i
|
|
|
70
85
|
```ruby
|
|
71
86
|
require "amritk-scalar-test"
|
|
72
87
|
|
|
73
|
-
client =
|
|
88
|
+
client = AmritkScalarTest::Client.new(
|
|
74
89
|
timeout: 60.0,
|
|
75
90
|
max_retries: 2,
|
|
76
91
|
logger: $stderr,
|
|
@@ -112,9 +127,9 @@ Generated clients support request timeouts and retry temporary failures such as
|
|
|
112
127
|
|
|
113
128
|
## Helpers
|
|
114
129
|
|
|
115
|
-
-
|
|
116
|
-
-
|
|
117
|
-
-
|
|
130
|
+
- Every model is a `BaseModel`: pass a plain hash or a model instance, and read decoded values back as attributes.
|
|
131
|
+
- Paginated methods return a page you can iterate directly, or walk with `auto_paging_each`.
|
|
132
|
+
- The gem ships `rbi/` and `sig/` trees, so Sorbet and Steep type-check calls into the SDK.
|
|
118
133
|
|
|
119
134
|
<br />
|
|
120
135
|
|
data/SKILL.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: scalar-ruby-test-ruby-sdk
|
|
3
|
-
description: "Ruby SDK for
|
|
3
|
+
description: "Ruby SDK for ScalarRubyTest API. Use when writing Ruby code that calls ScalarRubyTest API with the amritk-scalar-test package: installing it, constructing and authenticating the client, and calling API operations."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# ScalarRubyTest Ruby SDK
|
|
7
7
|
|
|
8
|
-
Generated Ruby client for
|
|
8
|
+
Generated Ruby client for ScalarRubyTest API, published as `amritk-scalar-test`. Use the generated client instead of hand-writing HTTP requests.
|
|
9
9
|
|
|
10
10
|
## Install
|
|
11
11
|
|
|
@@ -24,7 +24,12 @@ client = AmritkScalarTest::Client.new
|
|
|
24
24
|
## Calling operations
|
|
25
25
|
|
|
26
26
|
```ruby
|
|
27
|
+
require "amritk-scalar-test"
|
|
28
|
+
|
|
29
|
+
client = AmritkScalarTest::Client.new
|
|
30
|
+
|
|
27
31
|
response = client.ping.ping
|
|
32
|
+
|
|
28
33
|
puts response.inspect
|
|
29
34
|
```
|
|
30
35
|
|
|
@@ -37,10 +42,12 @@ Non-success responses throw generated API errors. Error objects expose status, h
|
|
|
37
42
|
```ruby
|
|
38
43
|
begin
|
|
39
44
|
response = client.ping.ping
|
|
45
|
+
|
|
40
46
|
puts response.inspect
|
|
41
|
-
rescue
|
|
47
|
+
rescue AmritkScalarTest::Errors::APIError => error
|
|
42
48
|
puts "#{error.status}: #{error.message}"
|
|
43
49
|
raise
|
|
50
|
+
end
|
|
44
51
|
```
|
|
45
52
|
|
|
46
53
|
## Requirements
|
|
@@ -49,5 +56,5 @@ rescue ScalarRubyTest::APIError => error
|
|
|
49
56
|
|
|
50
57
|
## Reference files
|
|
51
58
|
|
|
52
|
-
- [README.md](./README.md) — full feature tour: client options, request options, retries and timeouts
|
|
59
|
+
- [README.md](./README.md) — full feature tour: client options, request options, retries and timeouts.
|
|
53
60
|
- [api.md](./api.md) — complete catalogue of every operation with request and response types.
|
|
@@ -1,21 +1,67 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
module AmritkScalarTest
|
|
4
|
+
class Client < AmritkScalarTest::Internal::Transport::BaseClient
|
|
5
|
+
# Default max number of retries to attempt after a failed retryable request.
|
|
6
|
+
DEFAULT_MAX_RETRIES = 2
|
|
7
|
+
|
|
8
|
+
# Default per-request timeout.
|
|
9
|
+
DEFAULT_TIMEOUT_IN_SECONDS = 60.0
|
|
10
|
+
|
|
11
|
+
# Default initial retry delay in seconds.
|
|
12
|
+
# Overall delay is calculated using exponential backoff + jitter.
|
|
13
|
+
DEFAULT_INITIAL_RETRY_DELAY = 0.5
|
|
14
|
+
|
|
15
|
+
# Default max retry delay in seconds.
|
|
16
|
+
DEFAULT_MAX_RETRY_DELAY = 8.0
|
|
12
17
|
|
|
13
|
-
|
|
18
|
+
# @return [AmritkScalarTest::Resources::Ping]
|
|
14
19
|
attr_reader :ping
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
# Creates and returns a new client for interacting with the API.
|
|
22
|
+
#
|
|
23
|
+
# @param base_url [String, nil] Override the default base URL for the API, e.g.,
|
|
24
|
+
# `"https://api.example.com/v2/"`. Defaults to `ENV["SCALAR_RUBY_TEST_BASE_URL"]`
|
|
25
|
+
#
|
|
26
|
+
# @param max_retries [Integer] Max number of retries to attempt after a failed retryable request.
|
|
27
|
+
#
|
|
28
|
+
# @param timeout [Float]
|
|
29
|
+
#
|
|
30
|
+
# @param initial_retry_delay [Float]
|
|
31
|
+
#
|
|
32
|
+
# @param max_retry_delay [Float]
|
|
33
|
+
def initialize(
|
|
34
|
+
base_url: ENV["SCALAR_RUBY_TEST_BASE_URL"],
|
|
35
|
+
max_retries: self.class::DEFAULT_MAX_RETRIES,
|
|
36
|
+
timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
|
|
37
|
+
initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
|
|
38
|
+
max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
|
|
39
|
+
)
|
|
40
|
+
base_url ||= "https://api.example.com"
|
|
41
|
+
|
|
42
|
+
headers = {}
|
|
43
|
+
custom_headers_env = ENV["SCALAR_RUBY_TEST_CUSTOM_HEADERS"]
|
|
44
|
+
unless custom_headers_env.nil?
|
|
45
|
+
parsed = {}
|
|
46
|
+
custom_headers_env.split("\n").each do |line|
|
|
47
|
+
colon = line.index(":")
|
|
48
|
+
unless colon.nil?
|
|
49
|
+
parsed[line[0...colon].strip] = line[(colon + 1)..].strip
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
headers = parsed.merge(headers)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
super(
|
|
56
|
+
base_url: base_url,
|
|
57
|
+
timeout: timeout,
|
|
58
|
+
max_retries: max_retries,
|
|
59
|
+
initial_retry_delay: initial_retry_delay,
|
|
60
|
+
max_retry_delay: max_retry_delay,
|
|
61
|
+
headers: headers
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
@ping = AmritkScalarTest::Resources::Ping.new(client: self)
|
|
19
65
|
end
|
|
20
66
|
end
|
|
21
67
|
end
|
|
@@ -1,89 +1,228 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
require_relative "models"
|
|
5
|
-
module ScalarRubyTest
|
|
6
|
-
ProblemDetails = Struct.new(:type, :title, :status, :detail, :instance, :extensions, keyword_init: true)
|
|
7
|
-
|
|
3
|
+
module AmritkScalarTest
|
|
8
4
|
module Errors
|
|
9
|
-
class Error < StandardError
|
|
10
|
-
|
|
5
|
+
class Error < StandardError
|
|
6
|
+
# @!attribute cause
|
|
7
|
+
#
|
|
8
|
+
# @return [StandardError, nil]
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class ConversionError < AmritkScalarTest::Errors::Error
|
|
12
|
+
# @return [StandardError, nil]
|
|
13
|
+
def cause = @cause.nil? ? super : @cause
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
# @api private
|
|
16
|
+
#
|
|
17
|
+
# @param on [Class<StandardError>]
|
|
18
|
+
# @param method [Symbol]
|
|
19
|
+
# @param target [Object]
|
|
20
|
+
# @param value [Object]
|
|
21
|
+
# @param cause [StandardError, nil]
|
|
22
|
+
def initialize(on:, method:, target:, value:, cause: nil)
|
|
23
|
+
cls = on.name.split("::").last
|
|
14
24
|
|
|
15
|
-
|
|
25
|
+
message = [
|
|
26
|
+
"Failed to parse #{cls}.#{method} from #{value.class} to #{target.inspect}.",
|
|
27
|
+
"To get the unparsed API response, use #{cls}[#{method.inspect}].",
|
|
28
|
+
cause && "Cause: #{cause.message}"
|
|
29
|
+
].filter(&:itself).join(" ")
|
|
30
|
+
|
|
31
|
+
@cause = cause
|
|
16
32
|
super(message)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class APIError < AmritkScalarTest::Errors::Error
|
|
37
|
+
# @return [URI::Generic]
|
|
38
|
+
attr_accessor :url
|
|
39
|
+
|
|
40
|
+
# @return [Integer, nil]
|
|
41
|
+
attr_accessor :status
|
|
42
|
+
|
|
43
|
+
# @return [Hash{String=>String}, nil]
|
|
44
|
+
attr_accessor :headers
|
|
45
|
+
|
|
46
|
+
# @return [Object, nil]
|
|
47
|
+
attr_accessor :body
|
|
48
|
+
|
|
49
|
+
# @api private
|
|
50
|
+
#
|
|
51
|
+
# @param url [URI::Generic]
|
|
52
|
+
# @param status [Integer, nil]
|
|
53
|
+
# @param headers [Hash{String=>String}, nil]
|
|
54
|
+
# @param body [Object, nil]
|
|
55
|
+
# @param request [nil]
|
|
56
|
+
# @param response [nil]
|
|
57
|
+
# @param message [String, nil]
|
|
58
|
+
def initialize(url:, status: nil, headers: nil, body: nil, request: nil, response: nil, message: nil)
|
|
59
|
+
@url = url
|
|
17
60
|
@status = status
|
|
18
|
-
@body = body
|
|
19
61
|
@headers = headers
|
|
20
|
-
@
|
|
21
|
-
@
|
|
22
|
-
@
|
|
62
|
+
@body = body
|
|
63
|
+
@request = request
|
|
64
|
+
@response = response
|
|
65
|
+
super(message)
|
|
23
66
|
end
|
|
67
|
+
end
|
|
24
68
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
when 409 then ConflictError
|
|
34
|
-
when 422 then UnprocessableEntityError
|
|
35
|
-
when 429 then RateLimitError
|
|
36
|
-
else response.code.to_i >= 500 ? InternalServerError : APIStatusError
|
|
37
|
-
end
|
|
38
|
-
headers = response.to_hash
|
|
39
|
-
request_id = headers["x-request-id"]&.first || headers["request-id"]&.first
|
|
40
|
-
klass.new(error_message(response.code.to_i, body), status: response.code.to_i, body: body, headers: headers, request_id: request_id, raw_body: response.body)
|
|
41
|
-
end
|
|
69
|
+
class APIConnectionError < AmritkScalarTest::Errors::APIError
|
|
70
|
+
# @!attribute status
|
|
71
|
+
#
|
|
72
|
+
# @return [nil]
|
|
73
|
+
|
|
74
|
+
# @!attribute body
|
|
75
|
+
#
|
|
76
|
+
# @return [nil]
|
|
42
77
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
78
|
+
# @api private
|
|
79
|
+
#
|
|
80
|
+
# @param url [URI::Generic]
|
|
81
|
+
# @param status [nil]
|
|
82
|
+
# @param headers [Hash{String=>String}, nil]
|
|
83
|
+
# @param body [nil]
|
|
84
|
+
# @param request [nil]
|
|
85
|
+
# @param response [nil]
|
|
86
|
+
# @param message [String, nil]
|
|
87
|
+
def initialize(
|
|
88
|
+
url:,
|
|
89
|
+
status: nil,
|
|
90
|
+
headers: nil,
|
|
91
|
+
body: nil,
|
|
92
|
+
request: nil,
|
|
93
|
+
response: nil,
|
|
94
|
+
message: "Connection error."
|
|
95
|
+
)
|
|
96
|
+
super
|
|
46
97
|
end
|
|
98
|
+
end
|
|
47
99
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
100
|
+
class APITimeoutError < AmritkScalarTest::Errors::APIConnectionError
|
|
101
|
+
# @api private
|
|
102
|
+
#
|
|
103
|
+
# @param url [URI::Generic]
|
|
104
|
+
# @param status [nil]
|
|
105
|
+
# @param headers [Hash{String=>String}, nil]
|
|
106
|
+
# @param body [nil]
|
|
107
|
+
# @param request [nil]
|
|
108
|
+
# @param response [nil]
|
|
109
|
+
# @param message [String, nil]
|
|
110
|
+
def initialize(
|
|
111
|
+
url:,
|
|
112
|
+
status: nil,
|
|
113
|
+
headers: nil,
|
|
114
|
+
body: nil,
|
|
115
|
+
request: nil,
|
|
116
|
+
response: nil,
|
|
117
|
+
message: "Request timed out."
|
|
118
|
+
)
|
|
119
|
+
super
|
|
55
120
|
end
|
|
56
121
|
end
|
|
57
122
|
|
|
58
|
-
class APIStatusError < APIError
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
def
|
|
71
|
-
|
|
123
|
+
class APIStatusError < AmritkScalarTest::Errors::APIError
|
|
124
|
+
# @api private
|
|
125
|
+
#
|
|
126
|
+
# @param url [URI::Generic]
|
|
127
|
+
# @param status [Integer]
|
|
128
|
+
# @param headers [Hash{String=>String}, nil]
|
|
129
|
+
# @param body [Object, nil]
|
|
130
|
+
# @param request [nil]
|
|
131
|
+
# @param response [nil]
|
|
132
|
+
# @param message [String, nil]
|
|
133
|
+
#
|
|
134
|
+
# @return [self]
|
|
135
|
+
def self.for(url:, status:, headers:, body:, request:, response:, message: nil)
|
|
136
|
+
kwargs =
|
|
137
|
+
{
|
|
138
|
+
url: url,
|
|
139
|
+
status: status,
|
|
140
|
+
headers: headers,
|
|
141
|
+
body: body,
|
|
142
|
+
request: request,
|
|
143
|
+
response: response,
|
|
144
|
+
message: message
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
case status
|
|
148
|
+
in 400
|
|
149
|
+
AmritkScalarTest::Errors::BadRequestError.new(**kwargs)
|
|
150
|
+
in 401
|
|
151
|
+
AmritkScalarTest::Errors::AuthenticationError.new(**kwargs)
|
|
152
|
+
in 403
|
|
153
|
+
AmritkScalarTest::Errors::PermissionDeniedError.new(**kwargs)
|
|
154
|
+
in 404
|
|
155
|
+
AmritkScalarTest::Errors::NotFoundError.new(**kwargs)
|
|
156
|
+
in 409
|
|
157
|
+
AmritkScalarTest::Errors::ConflictError.new(**kwargs)
|
|
158
|
+
in 422
|
|
159
|
+
AmritkScalarTest::Errors::UnprocessableEntityError.new(**kwargs)
|
|
160
|
+
in 429
|
|
161
|
+
AmritkScalarTest::Errors::RateLimitError.new(**kwargs)
|
|
162
|
+
in (500..)
|
|
163
|
+
AmritkScalarTest::Errors::InternalServerError.new(**kwargs)
|
|
164
|
+
else
|
|
165
|
+
AmritkScalarTest::Errors::APIStatusError.new(**kwargs)
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# @!parse
|
|
170
|
+
# # @return [Integer]
|
|
171
|
+
# attr_accessor :status
|
|
172
|
+
|
|
173
|
+
# @api private
|
|
174
|
+
#
|
|
175
|
+
# @param url [URI::Generic]
|
|
176
|
+
# @param status [Integer]
|
|
177
|
+
# @param headers [Hash{String=>String}, nil]
|
|
178
|
+
# @param body [Object, nil]
|
|
179
|
+
# @param request [nil]
|
|
180
|
+
# @param response [nil]
|
|
181
|
+
# @param message [String, nil]
|
|
182
|
+
def initialize(url:, status:, headers:, body:, request:, response:, message: nil)
|
|
183
|
+
message ||= {url: url.to_s, status: status, body: body}
|
|
184
|
+
super(
|
|
185
|
+
url: url,
|
|
186
|
+
status: status,
|
|
187
|
+
headers: headers,
|
|
188
|
+
body: body,
|
|
189
|
+
request: request,
|
|
190
|
+
response: response,
|
|
191
|
+
message: message&.to_s
|
|
192
|
+
)
|
|
72
193
|
end
|
|
73
194
|
end
|
|
74
|
-
end
|
|
75
195
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
196
|
+
class BadRequestError < AmritkScalarTest::Errors::APIStatusError
|
|
197
|
+
HTTP_STATUS = 400
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
class AuthenticationError < AmritkScalarTest::Errors::APIStatusError
|
|
201
|
+
HTTP_STATUS = 401
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
class PermissionDeniedError < AmritkScalarTest::Errors::APIStatusError
|
|
205
|
+
HTTP_STATUS = 403
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
class NotFoundError < AmritkScalarTest::Errors::APIStatusError
|
|
209
|
+
HTTP_STATUS = 404
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
class ConflictError < AmritkScalarTest::Errors::APIStatusError
|
|
213
|
+
HTTP_STATUS = 409
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
class UnprocessableEntityError < AmritkScalarTest::Errors::APIStatusError
|
|
217
|
+
HTTP_STATUS = 422
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
class RateLimitError < AmritkScalarTest::Errors::APIStatusError
|
|
221
|
+
HTTP_STATUS = 429
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
class InternalServerError < AmritkScalarTest::Errors::APIStatusError
|
|
225
|
+
HTTP_STATUS = (500..)
|
|
226
|
+
end
|
|
227
|
+
end
|
|
89
228
|
end
|
|
@@ -1,14 +1,58 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
module ScalarRubyTest
|
|
3
|
+
module AmritkScalarTest
|
|
5
4
|
class FilePart
|
|
6
|
-
|
|
5
|
+
# @return [Pathname, StringIO, IO, String]
|
|
6
|
+
attr_reader :content
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
# @return [String, nil]
|
|
9
|
+
attr_reader :content_type
|
|
10
|
+
|
|
11
|
+
# @return [String, nil]
|
|
12
|
+
attr_reader :filename
|
|
13
|
+
|
|
14
|
+
# @api private
|
|
15
|
+
#
|
|
16
|
+
# @return [String]
|
|
17
|
+
private def read
|
|
18
|
+
case content
|
|
19
|
+
in Pathname
|
|
20
|
+
content.read(binmode: true)
|
|
21
|
+
in StringIO
|
|
22
|
+
content.string
|
|
23
|
+
in IO
|
|
24
|
+
content.read
|
|
25
|
+
in String
|
|
26
|
+
content
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# @param a [Object]
|
|
31
|
+
#
|
|
32
|
+
# @return [String]
|
|
33
|
+
def to_json(*a) = read.to_json(*a)
|
|
34
|
+
|
|
35
|
+
# @param a [Object]
|
|
36
|
+
#
|
|
37
|
+
# @return [String]
|
|
38
|
+
def to_yaml(*a) = read.to_yaml(*a)
|
|
39
|
+
|
|
40
|
+
# @param content [Pathname, StringIO, IO, String]
|
|
41
|
+
# @param filename [Pathname, String, nil]
|
|
42
|
+
# @param content_type [String, nil]
|
|
43
|
+
def initialize(content, filename: nil, content_type: nil)
|
|
11
44
|
@content_type = content_type
|
|
45
|
+
@filename =
|
|
46
|
+
case [filename, (@content = content)]
|
|
47
|
+
in [String | Pathname, _]
|
|
48
|
+
::File.basename(filename)
|
|
49
|
+
in [nil, Pathname]
|
|
50
|
+
content.basename.to_path
|
|
51
|
+
in [nil, IO]
|
|
52
|
+
content.to_path
|
|
53
|
+
else
|
|
54
|
+
filename
|
|
55
|
+
end
|
|
12
56
|
end
|
|
13
57
|
end
|
|
14
58
|
end
|