openlayer 0.3.0 → 0.4.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/.ignore +2 -0
- data/CHANGELOG.md +23 -0
- data/README.md +280 -39
- data/SECURITY.md +27 -0
- data/lib/openlayer/client.rb +64 -59
- data/lib/openlayer/errors.rb +228 -0
- data/lib/openlayer/file_part.rb +58 -0
- data/lib/openlayer/internal/transport/base_client.rb +567 -0
- data/lib/openlayer/internal/transport/pooled_net_requester.rb +198 -0
- data/lib/openlayer/internal/type/array_of.rb +168 -0
- data/lib/openlayer/internal/type/base_model.rb +531 -0
- data/lib/openlayer/internal/type/base_page.rb +55 -0
- data/lib/openlayer/internal/type/boolean.rb +77 -0
- data/lib/openlayer/internal/type/converter.rb +327 -0
- data/lib/openlayer/internal/type/enum.rb +131 -0
- data/lib/openlayer/internal/type/file_input.rb +111 -0
- data/lib/openlayer/internal/type/hash_of.rb +188 -0
- data/lib/openlayer/internal/type/request_parameters.rb +42 -0
- data/lib/openlayer/internal/type/union.rb +237 -0
- data/lib/openlayer/internal/type/unknown.rb +81 -0
- data/lib/openlayer/internal/util.rb +915 -0
- data/lib/openlayer/internal.rb +20 -0
- data/lib/openlayer/models/commit_retrieve_params.rb +14 -0
- data/lib/openlayer/models/commit_retrieve_response.rb +275 -0
- data/lib/openlayer/models/commits/test_result_list_params.rb +91 -0
- data/lib/openlayer/models/commits/test_result_list_response.rb +566 -0
- data/lib/openlayer/models/inference_pipeline_delete_params.rb +14 -0
- data/lib/openlayer/models/inference_pipeline_retrieve_params.rb +33 -0
- data/lib/openlayer/models/inference_pipeline_retrieve_response.rb +605 -0
- data/lib/openlayer/models/inference_pipeline_update_params.rb +42 -0
- data/lib/openlayer/models/inference_pipeline_update_response.rb +605 -0
- data/lib/openlayer/models/inference_pipelines/data_stream_params.rb +463 -0
- data/lib/openlayer/models/inference_pipelines/data_stream_response.rb +28 -0
- data/lib/openlayer/models/inference_pipelines/row_update_params.rb +90 -0
- data/lib/openlayer/models/inference_pipelines/row_update_response.rb +28 -0
- data/lib/openlayer/models/inference_pipelines/test_result_list_params.rb +83 -0
- data/lib/openlayer/models/inference_pipelines/test_result_list_response.rb +568 -0
- data/lib/openlayer/models/project_create_params.rb +51 -0
- data/lib/openlayer/models/project_create_response.rb +262 -0
- data/lib/openlayer/models/project_list_params.rb +59 -0
- data/lib/openlayer/models/project_list_response.rb +274 -0
- data/lib/openlayer/models/projects/commit_create_params.rb +61 -0
- data/lib/openlayer/models/projects/commit_create_response.rb +277 -0
- data/lib/openlayer/models/projects/commit_list_params.rb +32 -0
- data/lib/openlayer/models/projects/commit_list_response.rb +288 -0
- data/lib/openlayer/models/projects/inference_pipeline_create_params.rb +229 -0
- data/lib/openlayer/models/projects/inference_pipeline_create_response.rb +612 -0
- data/lib/openlayer/models/projects/inference_pipeline_list_params.rb +40 -0
- data/lib/openlayer/models/projects/inference_pipeline_list_response.rb +623 -0
- data/lib/openlayer/models/projects/test_create_params.rb +367 -0
- data/lib/openlayer/models/projects/test_create_response.rb +438 -0
- data/lib/openlayer/models/projects/test_list_params.rb +91 -0
- data/lib/openlayer/models/projects/test_list_response.rb +452 -0
- data/lib/openlayer/models/projects/test_update_params.rb +262 -0
- data/lib/openlayer/models/projects/test_update_response.rb +24 -0
- data/lib/openlayer/models/storage/presigned_url_create_params.rb +24 -0
- data/lib/openlayer/models/storage/presigned_url_create_response.rb +35 -0
- data/lib/openlayer/models.rb +61 -0
- data/lib/openlayer/request_options.rb +77 -0
- data/lib/openlayer/resources/commits/test_results.rb +51 -0
- data/lib/openlayer/resources/commits.rb +38 -0
- data/lib/openlayer/resources/inference_pipelines/data.rb +46 -0
- data/lib/openlayer/resources/inference_pipelines/rows.rb +46 -0
- data/lib/openlayer/resources/inference_pipelines/test_results.rb +49 -0
- data/lib/openlayer/resources/inference_pipelines.rb +101 -0
- data/lib/openlayer/resources/projects/commits.rb +72 -0
- data/lib/openlayer/resources/projects/inference_pipelines.rb +74 -0
- data/lib/openlayer/resources/projects/tests.rb +135 -0
- data/lib/openlayer/resources/projects.rb +80 -0
- data/lib/openlayer/resources/storage/presigned_url.rb +38 -0
- data/lib/openlayer/resources/storage.rb +18 -0
- data/lib/openlayer/version.rb +1 -1
- data/lib/openlayer.rb +96 -12
- data/manifest.yaml +15 -0
- data/rbi/openlayer/client.rbi +58 -0
- data/rbi/openlayer/errors.rbi +205 -0
- data/rbi/openlayer/file_part.rbi +37 -0
- data/rbi/openlayer/internal/transport/base_client.rbi +293 -0
- data/rbi/openlayer/internal/transport/pooled_net_requester.rbi +79 -0
- data/rbi/openlayer/internal/type/array_of.rbi +104 -0
- data/rbi/openlayer/internal/type/base_model.rbi +304 -0
- data/rbi/openlayer/internal/type/base_page.rbi +42 -0
- data/rbi/openlayer/internal/type/boolean.rbi +58 -0
- data/rbi/openlayer/internal/type/converter.rbi +216 -0
- data/rbi/openlayer/internal/type/enum.rbi +82 -0
- data/rbi/openlayer/internal/type/file_input.rbi +59 -0
- data/rbi/openlayer/internal/type/hash_of.rbi +104 -0
- data/rbi/openlayer/internal/type/request_parameters.rbi +29 -0
- data/rbi/openlayer/internal/type/union.rbi +128 -0
- data/rbi/openlayer/internal/type/unknown.rbi +58 -0
- data/rbi/openlayer/internal/util.rbi +487 -0
- data/rbi/openlayer/internal.rbi +18 -0
- data/rbi/openlayer/models/commit_retrieve_params.rbi +27 -0
- data/rbi/openlayer/models/commit_retrieve_response.rbi +393 -0
- data/rbi/openlayer/models/commits/test_result_list_params.rbi +214 -0
- data/rbi/openlayer/models/commits/test_result_list_response.rbi +1256 -0
- data/rbi/openlayer/models/inference_pipeline_delete_params.rbi +30 -0
- data/rbi/openlayer/models/inference_pipeline_retrieve_params.rbi +101 -0
- data/rbi/openlayer/models/inference_pipeline_retrieve_response.rbi +1022 -0
- data/rbi/openlayer/models/inference_pipeline_update_params.rbi +67 -0
- data/rbi/openlayer/models/inference_pipeline_update_response.rbi +1018 -0
- data/rbi/openlayer/models/inference_pipelines/data_stream_params.rbi +750 -0
- data/rbi/openlayer/models/inference_pipelines/data_stream_response.rbi +73 -0
- data/rbi/openlayer/models/inference_pipelines/row_update_params.rbi +153 -0
- data/rbi/openlayer/models/inference_pipelines/row_update_response.rbi +73 -0
- data/rbi/openlayer/models/inference_pipelines/test_result_list_params.rbi +216 -0
- data/rbi/openlayer/models/inference_pipelines/test_result_list_response.rbi +1258 -0
- data/rbi/openlayer/models/project_create_params.rbi +99 -0
- data/rbi/openlayer/models/project_create_response.rbi +401 -0
- data/rbi/openlayer/models/project_list_params.rbi +121 -0
- data/rbi/openlayer/models/project_list_response.rbi +442 -0
- data/rbi/openlayer/models/projects/commit_create_params.rbi +125 -0
- data/rbi/openlayer/models/projects/commit_create_response.rbi +409 -0
- data/rbi/openlayer/models/projects/commit_list_params.rbi +62 -0
- data/rbi/openlayer/models/projects/commit_list_response.rbi +454 -0
- data/rbi/openlayer/models/projects/inference_pipeline_create_params.rbi +560 -0
- data/rbi/openlayer/models/projects/inference_pipeline_create_response.rbi +1027 -0
- data/rbi/openlayer/models/projects/inference_pipeline_list_params.rbi +73 -0
- data/rbi/openlayer/models/projects/inference_pipeline_list_response.rbi +1070 -0
- data/rbi/openlayer/models/projects/test_create_params.rbi +940 -0
- data/rbi/openlayer/models/projects/test_create_response.rbi +1026 -0
- data/rbi/openlayer/models/projects/test_list_params.rbi +165 -0
- data/rbi/openlayer/models/projects/test_list_response.rbi +1067 -0
- data/rbi/openlayer/models/projects/test_update_params.rbi +699 -0
- data/rbi/openlayer/models/projects/test_update_response.rbi +43 -0
- data/rbi/openlayer/models/storage/presigned_url_create_params.rbi +45 -0
- data/rbi/openlayer/models/storage/presigned_url_create_response.rbi +55 -0
- data/rbi/openlayer/models.rbi +26 -0
- data/rbi/openlayer/request_options.rbi +59 -0
- data/rbi/openlayer/resources/commits/test_results.rbi +45 -0
- data/rbi/openlayer/resources/commits.rbi +29 -0
- data/rbi/openlayer/resources/inference_pipelines/data.rbi +41 -0
- data/rbi/openlayer/resources/inference_pipelines/rows.rbi +40 -0
- data/rbi/openlayer/resources/inference_pipelines/test_results.rbi +46 -0
- data/rbi/openlayer/resources/inference_pipelines.rbi +79 -0
- data/rbi/openlayer/resources/projects/commits.rbi +60 -0
- data/rbi/openlayer/resources/projects/inference_pipelines.rbi +69 -0
- data/rbi/openlayer/resources/projects/tests.rbi +123 -0
- data/rbi/openlayer/resources/projects.rbi +64 -0
- data/rbi/openlayer/resources/storage/presigned_url.rbi +28 -0
- data/rbi/openlayer/resources/storage.rbi +15 -0
- data/rbi/openlayer/version.rbi +5 -0
- data/sig/openlayer/client.rbs +32 -0
- data/sig/openlayer/errors.rbs +117 -0
- data/sig/openlayer/file_part.rbs +21 -0
- data/sig/openlayer/internal/transport/base_client.rbs +131 -0
- data/sig/openlayer/internal/transport/pooled_net_requester.rbs +45 -0
- data/sig/openlayer/internal/type/array_of.rbs +48 -0
- data/sig/openlayer/internal/type/base_model.rbs +102 -0
- data/sig/openlayer/internal/type/base_page.rbs +24 -0
- data/sig/openlayer/internal/type/boolean.rbs +26 -0
- data/sig/openlayer/internal/type/converter.rbs +79 -0
- data/sig/openlayer/internal/type/enum.rbs +32 -0
- data/sig/openlayer/internal/type/file_input.rbs +25 -0
- data/sig/openlayer/internal/type/hash_of.rbs +48 -0
- data/sig/openlayer/internal/type/request_parameters.rbs +19 -0
- data/sig/openlayer/internal/type/union.rbs +52 -0
- data/sig/openlayer/internal/type/unknown.rbs +26 -0
- data/sig/openlayer/internal/util.rbs +185 -0
- data/sig/openlayer/internal.rbs +9 -0
- data/sig/openlayer/models/commit_retrieve_params.rbs +15 -0
- data/sig/openlayer/models/commit_retrieve_response.rbs +209 -0
- data/sig/openlayer/models/commits/test_result_list_params.rbs +91 -0
- data/sig/openlayer/models/commits/test_result_list_response.rbs +529 -0
- data/sig/openlayer/models/inference_pipeline_delete_params.rbs +15 -0
- data/sig/openlayer/models/inference_pipeline_retrieve_params.rbs +41 -0
- data/sig/openlayer/models/inference_pipeline_retrieve_response.rbs +493 -0
- data/sig/openlayer/models/inference_pipeline_update_params.rbs +34 -0
- data/sig/openlayer/models/inference_pipeline_update_response.rbs +493 -0
- data/sig/openlayer/models/inference_pipelines/data_stream_params.rbs +386 -0
- data/sig/openlayer/models/inference_pipelines/data_stream_response.rbs +32 -0
- data/sig/openlayer/models/inference_pipelines/row_update_params.rbs +75 -0
- data/sig/openlayer/models/inference_pipelines/row_update_response.rbs +32 -0
- data/sig/openlayer/models/inference_pipelines/test_result_list_params.rbs +84 -0
- data/sig/openlayer/models/inference_pipelines/test_result_list_response.rbs +529 -0
- data/sig/openlayer/models/project_create_params.rbs +53 -0
- data/sig/openlayer/models/project_create_response.rbs +210 -0
- data/sig/openlayer/models/project_list_params.rbs +68 -0
- data/sig/openlayer/models/project_list_response.rbs +225 -0
- data/sig/openlayer/models/projects/commit_create_params.rbs +82 -0
- data/sig/openlayer/models/projects/commit_create_response.rbs +211 -0
- data/sig/openlayer/models/projects/commit_list_params.rbs +34 -0
- data/sig/openlayer/models/projects/commit_list_response.rbs +228 -0
- data/sig/openlayer/models/projects/inference_pipeline_create_params.rbs +308 -0
- data/sig/openlayer/models/projects/inference_pipeline_create_response.rbs +495 -0
- data/sig/openlayer/models/projects/inference_pipeline_list_params.rbs +40 -0
- data/sig/openlayer/models/projects/inference_pipeline_list_response.rbs +512 -0
- data/sig/openlayer/models/projects/test_create_params.rbs +388 -0
- data/sig/openlayer/models/projects/test_create_response.rbs +427 -0
- data/sig/openlayer/models/projects/test_list_params.rbs +85 -0
- data/sig/openlayer/models/projects/test_list_response.rbs +442 -0
- data/sig/openlayer/models/projects/test_update_params.rbs +275 -0
- data/sig/openlayer/models/projects/test_update_response.rbs +25 -0
- data/sig/openlayer/models/storage/presigned_url_create_params.rbs +25 -0
- data/sig/openlayer/models/storage/presigned_url_create_response.rbs +22 -0
- data/sig/openlayer/models.rbs +21 -0
- data/sig/openlayer/request_options.rbs +34 -0
- data/sig/openlayer/resources/commits/test_results.rbs +19 -0
- data/sig/openlayer/resources/commits.rbs +14 -0
- data/sig/openlayer/resources/inference_pipelines/data.rbs +16 -0
- data/sig/openlayer/resources/inference_pipelines/rows.rbs +17 -0
- data/sig/openlayer/resources/inference_pipelines/test_results.rbs +18 -0
- data/sig/openlayer/resources/inference_pipelines.rbs +32 -0
- data/sig/openlayer/resources/projects/commits.rbs +25 -0
- data/sig/openlayer/resources/projects/inference_pipelines.rbs +26 -0
- data/sig/openlayer/resources/projects/tests.rbs +45 -0
- data/sig/openlayer/resources/projects.rbs +28 -0
- data/sig/openlayer/resources/storage/presigned_url.rbs +14 -0
- data/sig/openlayer/resources/storage.rbs +9 -0
- data/sig/openlayer/version.rbs +3 -0
- metadata +223 -91
- data/.env +0 -0
- data/.rspec +0 -3
- data/.rubocop.yml +0 -13
- data/LICENSE +0 -21
- data/Rakefile +0 -12
- data/examples/staging/.DS_Store +0 -0
- data/examples/staging/commit.yaml +0 -2
- data/examples/staging/model/model_config.yaml +0 -12
- data/examples/staging/validation/dataset_config.yaml +0 -12
- data/lib/openlayer/error.rb +0 -5
- data/lib/openlayer/inference_pipeline.rb +0 -36
- data/lib/openlayer/object.rb +0 -28
- data/lib/openlayer/objects/project.rb +0 -185
- data/lib/openlayer/objects/project_version.rb +0 -89
- data/lib/openlayer/services/s3_presigned_client.rb +0 -47
- data/lib/openlayer/services/tar_file_helper.rb +0 -55
- data/openlayer.gemspec +0 -45
- data/sig/openlayer.rbs +0 -4
@@ -0,0 +1,228 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Openlayer
|
4
|
+
module Errors
|
5
|
+
class Error < StandardError
|
6
|
+
# @!attribute cause
|
7
|
+
#
|
8
|
+
# @return [StandardError, nil]
|
9
|
+
end
|
10
|
+
|
11
|
+
class ConversionError < Openlayer::Errors::Error
|
12
|
+
# @return [StandardError, nil]
|
13
|
+
def cause = @cause.nil? ? super : @cause
|
14
|
+
|
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
|
24
|
+
|
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
|
32
|
+
super(message)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class APIError < Openlayer::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
|
60
|
+
@status = status
|
61
|
+
@headers = headers
|
62
|
+
@body = body
|
63
|
+
@request = request
|
64
|
+
@response = response
|
65
|
+
super(message)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class APIConnectionError < Openlayer::Errors::APIError
|
70
|
+
# @!attribute status
|
71
|
+
#
|
72
|
+
# @return [nil]
|
73
|
+
|
74
|
+
# @!attribute body
|
75
|
+
#
|
76
|
+
# @return [nil]
|
77
|
+
|
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
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
class APITimeoutError < Openlayer::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
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
class APIStatusError < Openlayer::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
|
+
Openlayer::Errors::BadRequestError.new(**kwargs)
|
150
|
+
in 401
|
151
|
+
Openlayer::Errors::AuthenticationError.new(**kwargs)
|
152
|
+
in 403
|
153
|
+
Openlayer::Errors::PermissionDeniedError.new(**kwargs)
|
154
|
+
in 404
|
155
|
+
Openlayer::Errors::NotFoundError.new(**kwargs)
|
156
|
+
in 409
|
157
|
+
Openlayer::Errors::ConflictError.new(**kwargs)
|
158
|
+
in 422
|
159
|
+
Openlayer::Errors::UnprocessableEntityError.new(**kwargs)
|
160
|
+
in 429
|
161
|
+
Openlayer::Errors::RateLimitError.new(**kwargs)
|
162
|
+
in (500..)
|
163
|
+
Openlayer::Errors::InternalServerError.new(**kwargs)
|
164
|
+
else
|
165
|
+
Openlayer::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
|
+
)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
class BadRequestError < Openlayer::Errors::APIStatusError
|
197
|
+
HTTP_STATUS = 400
|
198
|
+
end
|
199
|
+
|
200
|
+
class AuthenticationError < Openlayer::Errors::APIStatusError
|
201
|
+
HTTP_STATUS = 401
|
202
|
+
end
|
203
|
+
|
204
|
+
class PermissionDeniedError < Openlayer::Errors::APIStatusError
|
205
|
+
HTTP_STATUS = 403
|
206
|
+
end
|
207
|
+
|
208
|
+
class NotFoundError < Openlayer::Errors::APIStatusError
|
209
|
+
HTTP_STATUS = 404
|
210
|
+
end
|
211
|
+
|
212
|
+
class ConflictError < Openlayer::Errors::APIStatusError
|
213
|
+
HTTP_STATUS = 409
|
214
|
+
end
|
215
|
+
|
216
|
+
class UnprocessableEntityError < Openlayer::Errors::APIStatusError
|
217
|
+
HTTP_STATUS = 422
|
218
|
+
end
|
219
|
+
|
220
|
+
class RateLimitError < Openlayer::Errors::APIStatusError
|
221
|
+
HTTP_STATUS = 429
|
222
|
+
end
|
223
|
+
|
224
|
+
class InternalServerError < Openlayer::Errors::APIStatusError
|
225
|
+
HTTP_STATUS = (500..)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Openlayer
|
4
|
+
class FilePart
|
5
|
+
# @return [Pathname, StringIO, IO, String]
|
6
|
+
attr_reader :content
|
7
|
+
|
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)
|
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
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|