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.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +22 -7
  4. data/SKILL.md +12 -5
  5. data/lib/amritk-scalar-test/client.rb +59 -13
  6. data/lib/amritk-scalar-test/errors.rb +208 -69
  7. data/lib/amritk-scalar-test/file_part.rb +50 -6
  8. data/lib/amritk-scalar-test/internal/transport/base_client.rb +578 -0
  9. data/lib/amritk-scalar-test/internal/transport/pooled_net_requester.rb +210 -0
  10. data/lib/amritk-scalar-test/internal/type/array_of.rb +168 -0
  11. data/lib/amritk-scalar-test/internal/type/base_model.rb +524 -0
  12. data/lib/amritk-scalar-test/internal/type/base_page.rb +55 -0
  13. data/lib/amritk-scalar-test/internal/type/boolean.rb +77 -0
  14. data/lib/amritk-scalar-test/internal/type/converter.rb +327 -0
  15. data/lib/amritk-scalar-test/internal/type/enum.rb +132 -0
  16. data/lib/amritk-scalar-test/internal/type/file_input.rb +111 -0
  17. data/lib/amritk-scalar-test/internal/type/hash_of.rb +188 -0
  18. data/lib/amritk-scalar-test/internal/type/request_parameters.rb +42 -0
  19. data/lib/amritk-scalar-test/internal/type/union.rb +238 -0
  20. data/lib/amritk-scalar-test/internal/type/unknown.rb +81 -0
  21. data/lib/amritk-scalar-test/internal/util.rb +966 -0
  22. data/lib/amritk-scalar-test/internal.rb +20 -0
  23. data/lib/amritk-scalar-test/models/ping_ping_params.rb +14 -0
  24. data/lib/amritk-scalar-test/models/ping_ping_response.rb +16 -0
  25. data/lib/amritk-scalar-test/models.rb +38 -33
  26. data/lib/amritk-scalar-test/request_options.rb +68 -13
  27. data/lib/amritk-scalar-test/resources/ping.rb +22 -61
  28. data/lib/amritk-scalar-test/version.rb +2 -3
  29. data/lib/amritk-scalar-test.rb +51 -2
  30. data/rbi/amritk-scalar-test/client.rbi +38 -0
  31. data/rbi/amritk-scalar-test/errors.rbi +205 -0
  32. data/rbi/amritk-scalar-test/file_part.rbi +37 -0
  33. data/rbi/amritk-scalar-test/internal/transport/base_client.rbi +297 -0
  34. data/rbi/amritk-scalar-test/internal/transport/pooled_net_requester.rbi +82 -0
  35. data/rbi/amritk-scalar-test/internal/type/array_of.rbi +104 -0
  36. data/rbi/amritk-scalar-test/internal/type/base_model.rbi +299 -0
  37. data/rbi/amritk-scalar-test/internal/type/base_page.rbi +42 -0
  38. data/rbi/amritk-scalar-test/internal/type/boolean.rbi +58 -0
  39. data/rbi/amritk-scalar-test/internal/type/converter.rbi +204 -0
  40. data/rbi/amritk-scalar-test/internal/type/enum.rbi +82 -0
  41. data/rbi/amritk-scalar-test/internal/type/file_input.rbi +59 -0
  42. data/rbi/amritk-scalar-test/internal/type/hash_of.rbi +104 -0
  43. data/rbi/amritk-scalar-test/internal/type/request_parameters.rbi +29 -0
  44. data/rbi/amritk-scalar-test/internal/type/union.rbi +126 -0
  45. data/rbi/amritk-scalar-test/internal/type/unknown.rbi +58 -0
  46. data/rbi/amritk-scalar-test/internal/util.rbi +512 -0
  47. data/rbi/amritk-scalar-test/internal.rbi +16 -0
  48. data/rbi/amritk-scalar-test/models/ping_ping_params.rbi +32 -0
  49. data/rbi/amritk-scalar-test/models/ping_ping_response.rbi +29 -0
  50. data/rbi/amritk-scalar-test/models.rbi +5 -0
  51. data/rbi/amritk-scalar-test/request_options.rbi +55 -0
  52. data/rbi/amritk-scalar-test/resources/ping.rbi +21 -0
  53. data/rbi/amritk-scalar-test/version.rbi +5 -0
  54. data/sig/amritk-scalar-test/client.rbs +21 -0
  55. data/sig/amritk-scalar-test/errors.rbs +117 -0
  56. data/sig/amritk-scalar-test/file_part.rbs +21 -0
  57. data/sig/amritk-scalar-test/internal/transport/base_client.rbs +133 -0
  58. data/sig/amritk-scalar-test/internal/transport/pooled_net_requester.rbs +48 -0
  59. data/sig/amritk-scalar-test/internal/type/array_of.rbs +48 -0
  60. data/sig/amritk-scalar-test/internal/type/base_model.rbs +102 -0
  61. data/sig/amritk-scalar-test/internal/type/base_page.rbs +24 -0
  62. data/sig/amritk-scalar-test/internal/type/boolean.rbs +26 -0
  63. data/sig/amritk-scalar-test/internal/type/converter.rbs +79 -0
  64. data/sig/amritk-scalar-test/internal/type/enum.rbs +32 -0
  65. data/sig/amritk-scalar-test/internal/type/file_input.rbs +25 -0
  66. data/sig/amritk-scalar-test/internal/type/hash_of.rbs +48 -0
  67. data/sig/amritk-scalar-test/internal/type/request_parameters.rbs +17 -0
  68. data/sig/amritk-scalar-test/internal/type/union.rbs +52 -0
  69. data/sig/amritk-scalar-test/internal/type/unknown.rbs +26 -0
  70. data/sig/amritk-scalar-test/internal/util.rbs +199 -0
  71. data/sig/amritk-scalar-test/internal.rbs +9 -0
  72. data/sig/amritk-scalar-test/models/ping_ping_params.rbs +15 -0
  73. data/sig/amritk-scalar-test/models/ping_ping_response.rbs +15 -0
  74. data/sig/amritk-scalar-test/models.rbs +3 -0
  75. data/sig/amritk-scalar-test/request_options.rbs +34 -0
  76. data/sig/amritk-scalar-test/resources/ping.rbs +11 -0
  77. data/sig/amritk-scalar-test/version.rbs +3 -0
  78. data/sig/manifest.yaml +6 -0
  79. metadata +103 -11
  80. data/lib/amritk-scalar-test/internal/cursor_page.rb +0 -9
  81. data/lib/amritk-scalar-test/runtime.rb +0 -893
  82. data/lib/amritk-scalar-test/webhooks.rb +0 -111
  83. data/tests/smoke-test.rb +0 -69
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e330b5f75ddaf318457adb5e09460b061f0670bd47875eccd852f7ffb987124e
4
- data.tar.gz: fb9185d3fb78a4c1c71cab4bfd9b6b0af4089b3fa58e87c96053b28d3fb841ce
3
+ metadata.gz: 57d60baeaab95d5b69bfb7398de111026485f80c908a76dd4939e383784fb200
4
+ data.tar.gz: 2853c8c957db2078b5f02d6ee64b0794f810d88a171aaee55c86f44b7c5edafc
5
5
  SHA512:
6
- metadata.gz: a40597758f49453df975c6bfaa3f97873bf186898613d2ac1a3069a11da4aa0c6d5c30d8819605381cb7761b3c99d66e5f0e63d2737887357e1a2dfbcacba059
7
- data.tar.gz: f787d4c7f6f2cd87c4595a89fa691f652bc883fa01223acde90548c4df591dcd1c20df5aa95da7d8d2445dd31f783f710e7f2b5ccc082cb10faf639faec4fcf6
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 [yyyy] [name of copyright owner]
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
- # Scalar Ruby Test
1
+ # ScalarRubyTest
2
2
 
3
- This library provides convenient access to the Scalar Ruby Test REST API from Ruby.
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 ScalarRubyTest::APIError => error
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 = ScalarRubyTest::Client.new(
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
- - Use `with_raw_response` companions when you need status, headers, or unparsed response bodies.
116
- - Use `with_result` companions when you want success data or HTTP error bodies without raising status errors.
117
- - WebSocket helpers use Ruby stdlib sockets (`ws://` and `wss://`) and expose typed `serialize_send` / `deserialize_receive` helpers.
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 Scalar Ruby Test API. Use when writing Ruby code that calls Scalar Ruby Test API with the amritk-scalar-test package: installing it, constructing and authenticating the client, and calling API operations."
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
- # Scalar Ruby Test Ruby SDK
6
+ # ScalarRubyTest Ruby SDK
7
7
 
8
- Generated Ruby client for Scalar Ruby Test API, published as `amritk-scalar-test`. Use the generated client instead of hand-writing HTTP requests.
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 ScalarRubyTest::APIError => error
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, logging.
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
- # Code generated by Scalar SDK Generator. DO NOT EDIT.
4
- require_relative "errors"
5
- require_relative "runtime"
6
- require_relative "models"
7
-
8
- module ScalarRubyTest
9
- module Resources
10
- autoload :Ping, File.expand_path("resources/ping", __dir__)
11
- end
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
- class Client < APIClient
18
+ # @return [AmritkScalarTest::Resources::Ping]
14
19
  attr_reader :ping
15
20
 
16
- def initialize(base_url: ENV["SCALAR_RUBY_TEST_BASE_URL"] || "https://api.example.com", max_retries: 2, timeout: 60.0, initial_retry_delay: 0.5, max_retry_delay: 8.0, idempotency_header: "Idempotency-Key", logger: nil, default_headers: nil, default_query: nil)
17
- super(base_url: base_url, max_retries: max_retries, timeout: timeout, initial_retry_delay: initial_retry_delay, max_retry_delay: max_retry_delay, idempotency_header: idempotency_header, logger: logger, default_headers: ({ }).merge(default_headers || {}), default_query: default_query || {})
18
- @ping = Resources::Ping.new(self)
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
- # Code generated by Scalar SDK Generator. DO NOT EDIT.
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; end
10
- class ConversionError < Error; end
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
- class APIError < Error
13
- attr_reader :status, :body, :headers, :request_id, :raw_body, :problem_details
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
- def initialize(message, status: nil, body: nil, headers: nil, request_id: nil, raw_body: nil)
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
- @request_id = request_id
21
- @raw_body = raw_body
22
- @problem_details = self.class.parse_problem_details(body)
62
+ @body = body
63
+ @request = request
64
+ @response = response
65
+ super(message)
23
66
  end
67
+ end
24
68
 
25
- alias problem problem_details
26
-
27
- def self.from_response(response, body)
28
- klass = case response.code.to_i
29
- when 400 then BadRequestError
30
- when 401 then AuthenticationError
31
- when 403 then PermissionDeniedError
32
- when 404 then NotFoundError
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
- def self.error_message(status, body)
44
- detail = Runtime.extract_error_message(body)
45
- detail.nil? || detail.empty? ? "HTTP #{status}" : "#{status} #{detail}"
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
- def self.parse_problem_details(body)
49
- return nil unless body.is_a?(Hash)
50
- known = %w[type title status detail instance]
51
- return nil unless known.any? { |key| body.key?(key) }
52
- return nil if %w[type title detail instance].any? { |key| body.key?(key) && !body[key].is_a?(String) }
53
- return nil if body.key?("status") && !body["status"].is_a?(Integer)
54
- ProblemDetails.new(type: body["type"], title: body["title"], status: body["status"], detail: body["detail"], instance: body["instance"], extensions: body.reject { |key, _| known.include?(key) })
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; end
59
- class BadRequestError < APIStatusError; end
60
- class AuthenticationError < APIStatusError; end
61
- class PermissionDeniedError < APIStatusError; end
62
- class NotFoundError < APIStatusError; end
63
- class ConflictError < APIStatusError; end
64
- class UnprocessableEntityError < APIStatusError; end
65
- class RateLimitError < APIStatusError; end
66
- class InternalServerError < APIStatusError; end
67
- class APIConnectionError < APIError; end
68
- class APITimeoutError < APIConnectionError; end
69
- class MissingDependencyError < Error
70
- def initialize(gem_name:, feature:)
71
- super("The #{gem_name} gem is required to use #{feature}. Install it with: gem install #{gem_name}")
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
- APIError = Errors::APIError
77
- APIStatusError = Errors::APIStatusError
78
- BadRequestError = Errors::BadRequestError
79
- AuthenticationError = Errors::AuthenticationError
80
- PermissionDeniedError = Errors::PermissionDeniedError
81
- NotFoundError = Errors::NotFoundError
82
- ConflictError = Errors::ConflictError
83
- UnprocessableEntityError = Errors::UnprocessableEntityError
84
- RateLimitError = Errors::RateLimitError
85
- InternalServerError = Errors::InternalServerError
86
- APIConnectionError = Errors::APIConnectionError
87
- APIConnectionTimeoutError = Errors::APITimeoutError
88
- MissingDependencyError = Errors::MissingDependencyError
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
- # Code generated by Scalar SDK Generator. DO NOT EDIT.
4
- module ScalarRubyTest
3
+ module AmritkScalarTest
5
4
  class FilePart
6
- attr_reader :io, :filename, :content_type
5
+ # @return [Pathname, StringIO, IO, String]
6
+ attr_reader :content
7
7
 
8
- def initialize(io:, filename: nil, content_type: nil)
9
- @io = io
10
- @filename = filename
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