openlayer 0.0.2

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 (212) hide show
  1. checksums.yaml +7 -0
  2. data/.ignore +2 -0
  3. data/CHANGELOG.md +15 -0
  4. data/README.md +314 -0
  5. data/SECURITY.md +27 -0
  6. data/lib/openlayer/client.rb +82 -0
  7. data/lib/openlayer/errors.rb +228 -0
  8. data/lib/openlayer/file_part.rb +58 -0
  9. data/lib/openlayer/internal/transport/base_client.rb +567 -0
  10. data/lib/openlayer/internal/transport/pooled_net_requester.rb +198 -0
  11. data/lib/openlayer/internal/type/array_of.rb +168 -0
  12. data/lib/openlayer/internal/type/base_model.rb +531 -0
  13. data/lib/openlayer/internal/type/base_page.rb +55 -0
  14. data/lib/openlayer/internal/type/boolean.rb +77 -0
  15. data/lib/openlayer/internal/type/converter.rb +327 -0
  16. data/lib/openlayer/internal/type/enum.rb +131 -0
  17. data/lib/openlayer/internal/type/file_input.rb +111 -0
  18. data/lib/openlayer/internal/type/hash_of.rb +188 -0
  19. data/lib/openlayer/internal/type/request_parameters.rb +42 -0
  20. data/lib/openlayer/internal/type/union.rb +237 -0
  21. data/lib/openlayer/internal/type/unknown.rb +81 -0
  22. data/lib/openlayer/internal/util.rb +915 -0
  23. data/lib/openlayer/internal.rb +20 -0
  24. data/lib/openlayer/models/commit_retrieve_params.rb +14 -0
  25. data/lib/openlayer/models/commit_retrieve_response.rb +275 -0
  26. data/lib/openlayer/models/commits/test_result_list_params.rb +91 -0
  27. data/lib/openlayer/models/commits/test_result_list_response.rb +566 -0
  28. data/lib/openlayer/models/inference_pipeline_delete_params.rb +14 -0
  29. data/lib/openlayer/models/inference_pipeline_retrieve_params.rb +33 -0
  30. data/lib/openlayer/models/inference_pipeline_retrieve_response.rb +605 -0
  31. data/lib/openlayer/models/inference_pipeline_update_params.rb +42 -0
  32. data/lib/openlayer/models/inference_pipeline_update_response.rb +605 -0
  33. data/lib/openlayer/models/inference_pipelines/data_stream_params.rb +463 -0
  34. data/lib/openlayer/models/inference_pipelines/data_stream_response.rb +28 -0
  35. data/lib/openlayer/models/inference_pipelines/row_update_params.rb +90 -0
  36. data/lib/openlayer/models/inference_pipelines/row_update_response.rb +28 -0
  37. data/lib/openlayer/models/inference_pipelines/test_result_list_params.rb +83 -0
  38. data/lib/openlayer/models/inference_pipelines/test_result_list_response.rb +568 -0
  39. data/lib/openlayer/models/project_create_params.rb +51 -0
  40. data/lib/openlayer/models/project_create_response.rb +262 -0
  41. data/lib/openlayer/models/project_list_params.rb +59 -0
  42. data/lib/openlayer/models/project_list_response.rb +274 -0
  43. data/lib/openlayer/models/projects/commit_create_params.rb +61 -0
  44. data/lib/openlayer/models/projects/commit_create_response.rb +277 -0
  45. data/lib/openlayer/models/projects/commit_list_params.rb +32 -0
  46. data/lib/openlayer/models/projects/commit_list_response.rb +288 -0
  47. data/lib/openlayer/models/projects/inference_pipeline_create_params.rb +229 -0
  48. data/lib/openlayer/models/projects/inference_pipeline_create_response.rb +612 -0
  49. data/lib/openlayer/models/projects/inference_pipeline_list_params.rb +40 -0
  50. data/lib/openlayer/models/projects/inference_pipeline_list_response.rb +623 -0
  51. data/lib/openlayer/models/projects/test_create_params.rb +367 -0
  52. data/lib/openlayer/models/projects/test_create_response.rb +438 -0
  53. data/lib/openlayer/models/projects/test_list_params.rb +91 -0
  54. data/lib/openlayer/models/projects/test_list_response.rb +452 -0
  55. data/lib/openlayer/models/projects/test_update_params.rb +262 -0
  56. data/lib/openlayer/models/projects/test_update_response.rb +24 -0
  57. data/lib/openlayer/models/storage/presigned_url_create_params.rb +24 -0
  58. data/lib/openlayer/models/storage/presigned_url_create_response.rb +35 -0
  59. data/lib/openlayer/models.rb +61 -0
  60. data/lib/openlayer/request_options.rb +77 -0
  61. data/lib/openlayer/resources/commits/test_results.rb +51 -0
  62. data/lib/openlayer/resources/commits.rb +38 -0
  63. data/lib/openlayer/resources/inference_pipelines/data.rb +46 -0
  64. data/lib/openlayer/resources/inference_pipelines/rows.rb +46 -0
  65. data/lib/openlayer/resources/inference_pipelines/test_results.rb +49 -0
  66. data/lib/openlayer/resources/inference_pipelines.rb +101 -0
  67. data/lib/openlayer/resources/projects/commits.rb +72 -0
  68. data/lib/openlayer/resources/projects/inference_pipelines.rb +74 -0
  69. data/lib/openlayer/resources/projects/tests.rb +135 -0
  70. data/lib/openlayer/resources/projects.rb +80 -0
  71. data/lib/openlayer/resources/storage/presigned_url.rb +38 -0
  72. data/lib/openlayer/resources/storage.rb +18 -0
  73. data/lib/openlayer/version.rb +5 -0
  74. data/lib/openlayer.rb +100 -0
  75. data/manifest.yaml +15 -0
  76. data/rbi/openlayer/client.rbi +58 -0
  77. data/rbi/openlayer/errors.rbi +205 -0
  78. data/rbi/openlayer/file_part.rbi +37 -0
  79. data/rbi/openlayer/internal/transport/base_client.rbi +293 -0
  80. data/rbi/openlayer/internal/transport/pooled_net_requester.rbi +79 -0
  81. data/rbi/openlayer/internal/type/array_of.rbi +104 -0
  82. data/rbi/openlayer/internal/type/base_model.rbi +304 -0
  83. data/rbi/openlayer/internal/type/base_page.rbi +42 -0
  84. data/rbi/openlayer/internal/type/boolean.rbi +58 -0
  85. data/rbi/openlayer/internal/type/converter.rbi +216 -0
  86. data/rbi/openlayer/internal/type/enum.rbi +82 -0
  87. data/rbi/openlayer/internal/type/file_input.rbi +59 -0
  88. data/rbi/openlayer/internal/type/hash_of.rbi +104 -0
  89. data/rbi/openlayer/internal/type/request_parameters.rbi +29 -0
  90. data/rbi/openlayer/internal/type/union.rbi +128 -0
  91. data/rbi/openlayer/internal/type/unknown.rbi +58 -0
  92. data/rbi/openlayer/internal/util.rbi +487 -0
  93. data/rbi/openlayer/internal.rbi +18 -0
  94. data/rbi/openlayer/models/commit_retrieve_params.rbi +27 -0
  95. data/rbi/openlayer/models/commit_retrieve_response.rbi +393 -0
  96. data/rbi/openlayer/models/commits/test_result_list_params.rbi +214 -0
  97. data/rbi/openlayer/models/commits/test_result_list_response.rbi +1256 -0
  98. data/rbi/openlayer/models/inference_pipeline_delete_params.rbi +30 -0
  99. data/rbi/openlayer/models/inference_pipeline_retrieve_params.rbi +101 -0
  100. data/rbi/openlayer/models/inference_pipeline_retrieve_response.rbi +1022 -0
  101. data/rbi/openlayer/models/inference_pipeline_update_params.rbi +67 -0
  102. data/rbi/openlayer/models/inference_pipeline_update_response.rbi +1018 -0
  103. data/rbi/openlayer/models/inference_pipelines/data_stream_params.rbi +750 -0
  104. data/rbi/openlayer/models/inference_pipelines/data_stream_response.rbi +73 -0
  105. data/rbi/openlayer/models/inference_pipelines/row_update_params.rbi +153 -0
  106. data/rbi/openlayer/models/inference_pipelines/row_update_response.rbi +73 -0
  107. data/rbi/openlayer/models/inference_pipelines/test_result_list_params.rbi +216 -0
  108. data/rbi/openlayer/models/inference_pipelines/test_result_list_response.rbi +1258 -0
  109. data/rbi/openlayer/models/project_create_params.rbi +99 -0
  110. data/rbi/openlayer/models/project_create_response.rbi +401 -0
  111. data/rbi/openlayer/models/project_list_params.rbi +121 -0
  112. data/rbi/openlayer/models/project_list_response.rbi +442 -0
  113. data/rbi/openlayer/models/projects/commit_create_params.rbi +125 -0
  114. data/rbi/openlayer/models/projects/commit_create_response.rbi +409 -0
  115. data/rbi/openlayer/models/projects/commit_list_params.rbi +62 -0
  116. data/rbi/openlayer/models/projects/commit_list_response.rbi +454 -0
  117. data/rbi/openlayer/models/projects/inference_pipeline_create_params.rbi +560 -0
  118. data/rbi/openlayer/models/projects/inference_pipeline_create_response.rbi +1027 -0
  119. data/rbi/openlayer/models/projects/inference_pipeline_list_params.rbi +73 -0
  120. data/rbi/openlayer/models/projects/inference_pipeline_list_response.rbi +1070 -0
  121. data/rbi/openlayer/models/projects/test_create_params.rbi +940 -0
  122. data/rbi/openlayer/models/projects/test_create_response.rbi +1026 -0
  123. data/rbi/openlayer/models/projects/test_list_params.rbi +165 -0
  124. data/rbi/openlayer/models/projects/test_list_response.rbi +1067 -0
  125. data/rbi/openlayer/models/projects/test_update_params.rbi +699 -0
  126. data/rbi/openlayer/models/projects/test_update_response.rbi +43 -0
  127. data/rbi/openlayer/models/storage/presigned_url_create_params.rbi +45 -0
  128. data/rbi/openlayer/models/storage/presigned_url_create_response.rbi +55 -0
  129. data/rbi/openlayer/models.rbi +26 -0
  130. data/rbi/openlayer/request_options.rbi +59 -0
  131. data/rbi/openlayer/resources/commits/test_results.rbi +45 -0
  132. data/rbi/openlayer/resources/commits.rbi +29 -0
  133. data/rbi/openlayer/resources/inference_pipelines/data.rbi +41 -0
  134. data/rbi/openlayer/resources/inference_pipelines/rows.rbi +40 -0
  135. data/rbi/openlayer/resources/inference_pipelines/test_results.rbi +46 -0
  136. data/rbi/openlayer/resources/inference_pipelines.rbi +79 -0
  137. data/rbi/openlayer/resources/projects/commits.rbi +60 -0
  138. data/rbi/openlayer/resources/projects/inference_pipelines.rbi +69 -0
  139. data/rbi/openlayer/resources/projects/tests.rbi +123 -0
  140. data/rbi/openlayer/resources/projects.rbi +64 -0
  141. data/rbi/openlayer/resources/storage/presigned_url.rbi +28 -0
  142. data/rbi/openlayer/resources/storage.rbi +15 -0
  143. data/rbi/openlayer/version.rbi +5 -0
  144. data/sig/openlayer/client.rbs +32 -0
  145. data/sig/openlayer/errors.rbs +117 -0
  146. data/sig/openlayer/file_part.rbs +21 -0
  147. data/sig/openlayer/internal/transport/base_client.rbs +131 -0
  148. data/sig/openlayer/internal/transport/pooled_net_requester.rbs +45 -0
  149. data/sig/openlayer/internal/type/array_of.rbs +48 -0
  150. data/sig/openlayer/internal/type/base_model.rbs +102 -0
  151. data/sig/openlayer/internal/type/base_page.rbs +24 -0
  152. data/sig/openlayer/internal/type/boolean.rbs +26 -0
  153. data/sig/openlayer/internal/type/converter.rbs +79 -0
  154. data/sig/openlayer/internal/type/enum.rbs +32 -0
  155. data/sig/openlayer/internal/type/file_input.rbs +25 -0
  156. data/sig/openlayer/internal/type/hash_of.rbs +48 -0
  157. data/sig/openlayer/internal/type/request_parameters.rbs +19 -0
  158. data/sig/openlayer/internal/type/union.rbs +52 -0
  159. data/sig/openlayer/internal/type/unknown.rbs +26 -0
  160. data/sig/openlayer/internal/util.rbs +185 -0
  161. data/sig/openlayer/internal.rbs +9 -0
  162. data/sig/openlayer/models/commit_retrieve_params.rbs +15 -0
  163. data/sig/openlayer/models/commit_retrieve_response.rbs +209 -0
  164. data/sig/openlayer/models/commits/test_result_list_params.rbs +91 -0
  165. data/sig/openlayer/models/commits/test_result_list_response.rbs +529 -0
  166. data/sig/openlayer/models/inference_pipeline_delete_params.rbs +15 -0
  167. data/sig/openlayer/models/inference_pipeline_retrieve_params.rbs +41 -0
  168. data/sig/openlayer/models/inference_pipeline_retrieve_response.rbs +493 -0
  169. data/sig/openlayer/models/inference_pipeline_update_params.rbs +34 -0
  170. data/sig/openlayer/models/inference_pipeline_update_response.rbs +493 -0
  171. data/sig/openlayer/models/inference_pipelines/data_stream_params.rbs +386 -0
  172. data/sig/openlayer/models/inference_pipelines/data_stream_response.rbs +32 -0
  173. data/sig/openlayer/models/inference_pipelines/row_update_params.rbs +75 -0
  174. data/sig/openlayer/models/inference_pipelines/row_update_response.rbs +32 -0
  175. data/sig/openlayer/models/inference_pipelines/test_result_list_params.rbs +84 -0
  176. data/sig/openlayer/models/inference_pipelines/test_result_list_response.rbs +529 -0
  177. data/sig/openlayer/models/project_create_params.rbs +53 -0
  178. data/sig/openlayer/models/project_create_response.rbs +210 -0
  179. data/sig/openlayer/models/project_list_params.rbs +68 -0
  180. data/sig/openlayer/models/project_list_response.rbs +225 -0
  181. data/sig/openlayer/models/projects/commit_create_params.rbs +82 -0
  182. data/sig/openlayer/models/projects/commit_create_response.rbs +211 -0
  183. data/sig/openlayer/models/projects/commit_list_params.rbs +34 -0
  184. data/sig/openlayer/models/projects/commit_list_response.rbs +228 -0
  185. data/sig/openlayer/models/projects/inference_pipeline_create_params.rbs +308 -0
  186. data/sig/openlayer/models/projects/inference_pipeline_create_response.rbs +495 -0
  187. data/sig/openlayer/models/projects/inference_pipeline_list_params.rbs +40 -0
  188. data/sig/openlayer/models/projects/inference_pipeline_list_response.rbs +512 -0
  189. data/sig/openlayer/models/projects/test_create_params.rbs +388 -0
  190. data/sig/openlayer/models/projects/test_create_response.rbs +427 -0
  191. data/sig/openlayer/models/projects/test_list_params.rbs +85 -0
  192. data/sig/openlayer/models/projects/test_list_response.rbs +442 -0
  193. data/sig/openlayer/models/projects/test_update_params.rbs +275 -0
  194. data/sig/openlayer/models/projects/test_update_response.rbs +25 -0
  195. data/sig/openlayer/models/storage/presigned_url_create_params.rbs +25 -0
  196. data/sig/openlayer/models/storage/presigned_url_create_response.rbs +22 -0
  197. data/sig/openlayer/models.rbs +21 -0
  198. data/sig/openlayer/request_options.rbs +34 -0
  199. data/sig/openlayer/resources/commits/test_results.rbs +19 -0
  200. data/sig/openlayer/resources/commits.rbs +14 -0
  201. data/sig/openlayer/resources/inference_pipelines/data.rbs +16 -0
  202. data/sig/openlayer/resources/inference_pipelines/rows.rbs +17 -0
  203. data/sig/openlayer/resources/inference_pipelines/test_results.rbs +18 -0
  204. data/sig/openlayer/resources/inference_pipelines.rbs +32 -0
  205. data/sig/openlayer/resources/projects/commits.rbs +25 -0
  206. data/sig/openlayer/resources/projects/inference_pipelines.rbs +26 -0
  207. data/sig/openlayer/resources/projects/tests.rbs +45 -0
  208. data/sig/openlayer/resources/projects.rbs +28 -0
  209. data/sig/openlayer/resources/storage/presigned_url.rbs +14 -0
  210. data/sig/openlayer/resources/storage.rbs +9 -0
  211. data/sig/openlayer/version.rbs +3 -0
  212. metadata +269 -0
data/manifest.yaml ADDED
@@ -0,0 +1,15 @@
1
+ dependencies:
2
+ - English
3
+ - cgi
4
+ - date
5
+ - erb
6
+ - etc
7
+ - json
8
+ - net/http
9
+ - pathname
10
+ - rbconfig
11
+ - securerandom
12
+ - set
13
+ - stringio
14
+ - time
15
+ - uri
@@ -0,0 +1,58 @@
1
+ # typed: strong
2
+
3
+ module Openlayer
4
+ class Client < Openlayer::Internal::Transport::BaseClient
5
+ DEFAULT_MAX_RETRIES = 2
6
+
7
+ DEFAULT_TIMEOUT_IN_SECONDS = T.let(60.0, Float)
8
+
9
+ DEFAULT_INITIAL_RETRY_DELAY = T.let(0.5, Float)
10
+
11
+ DEFAULT_MAX_RETRY_DELAY = T.let(8.0, Float)
12
+
13
+ sig { returns(T.nilable(String)) }
14
+ attr_reader :api_key
15
+
16
+ sig { returns(Openlayer::Resources::Projects) }
17
+ attr_reader :projects
18
+
19
+ sig { returns(Openlayer::Resources::Commits) }
20
+ attr_reader :commits
21
+
22
+ sig { returns(Openlayer::Resources::InferencePipelines) }
23
+ attr_reader :inference_pipelines
24
+
25
+ sig { returns(Openlayer::Resources::Storage) }
26
+ attr_reader :storage
27
+
28
+ # @api private
29
+ sig { override.returns(T::Hash[String, String]) }
30
+ private def auth_headers
31
+ end
32
+
33
+ # Creates and returns a new client for interacting with the API.
34
+ sig do
35
+ params(
36
+ api_key: T.nilable(String),
37
+ base_url: T.nilable(String),
38
+ max_retries: Integer,
39
+ timeout: Float,
40
+ initial_retry_delay: Float,
41
+ max_retry_delay: Float
42
+ ).returns(T.attached_class)
43
+ end
44
+ def self.new(
45
+ # Defaults to `ENV["OPENLAYER_API_KEY"]`
46
+ api_key: ENV["OPENLAYER_API_KEY"],
47
+ # Override the default base URL for the API, e.g.,
48
+ # `"https://api.example.com/v2/"`. Defaults to `ENV["OPENLAYER_BASE_URL"]`
49
+ base_url: ENV["OPENLAYER_BASE_URL"],
50
+ # Max number of retries to attempt after a failed retryable request.
51
+ max_retries: Openlayer::Client::DEFAULT_MAX_RETRIES,
52
+ timeout: Openlayer::Client::DEFAULT_TIMEOUT_IN_SECONDS,
53
+ initial_retry_delay: Openlayer::Client::DEFAULT_INITIAL_RETRY_DELAY,
54
+ max_retry_delay: Openlayer::Client::DEFAULT_MAX_RETRY_DELAY
55
+ )
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,205 @@
1
+ # typed: strong
2
+
3
+ module Openlayer
4
+ module Errors
5
+ class Error < StandardError
6
+ sig { returns(T.nilable(StandardError)) }
7
+ attr_accessor :cause
8
+ end
9
+
10
+ class ConversionError < Openlayer::Errors::Error
11
+ sig { returns(T.nilable(StandardError)) }
12
+ def cause
13
+ end
14
+
15
+ # @api private
16
+ sig do
17
+ params(
18
+ on: T::Class[StandardError],
19
+ method: Symbol,
20
+ target: T.anything,
21
+ value: T.anything,
22
+ cause: T.nilable(StandardError)
23
+ ).returns(T.attached_class)
24
+ end
25
+ def self.new(on:, method:, target:, value:, cause: nil)
26
+ end
27
+ end
28
+
29
+ class APIError < Openlayer::Errors::Error
30
+ sig { returns(URI::Generic) }
31
+ attr_accessor :url
32
+
33
+ sig { returns(T.nilable(Integer)) }
34
+ attr_accessor :status
35
+
36
+ sig { returns(T.nilable(T::Hash[String, String])) }
37
+ attr_accessor :headers
38
+
39
+ sig { returns(T.nilable(T.anything)) }
40
+ attr_accessor :body
41
+
42
+ # @api private
43
+ sig do
44
+ params(
45
+ url: URI::Generic,
46
+ status: T.nilable(Integer),
47
+ headers: T.nilable(T::Hash[String, String]),
48
+ body: T.nilable(Object),
49
+ request: NilClass,
50
+ response: NilClass,
51
+ message: T.nilable(String)
52
+ ).returns(T.attached_class)
53
+ end
54
+ def self.new(
55
+ url:,
56
+ status: nil,
57
+ headers: nil,
58
+ body: nil,
59
+ request: nil,
60
+ response: nil,
61
+ message: nil
62
+ )
63
+ end
64
+ end
65
+
66
+ class APIConnectionError < Openlayer::Errors::APIError
67
+ sig { returns(NilClass) }
68
+ attr_accessor :status
69
+
70
+ sig { returns(NilClass) }
71
+ attr_accessor :body
72
+
73
+ # @api private
74
+ sig do
75
+ params(
76
+ url: URI::Generic,
77
+ status: NilClass,
78
+ headers: T.nilable(T::Hash[String, String]),
79
+ body: NilClass,
80
+ request: NilClass,
81
+ response: NilClass,
82
+ message: T.nilable(String)
83
+ ).returns(T.attached_class)
84
+ end
85
+ def self.new(
86
+ url:,
87
+ status: nil,
88
+ headers: nil,
89
+ body: nil,
90
+ request: nil,
91
+ response: nil,
92
+ message: "Connection error."
93
+ )
94
+ end
95
+ end
96
+
97
+ class APITimeoutError < Openlayer::Errors::APIConnectionError
98
+ # @api private
99
+ sig do
100
+ params(
101
+ url: URI::Generic,
102
+ status: NilClass,
103
+ headers: T.nilable(T::Hash[String, String]),
104
+ body: NilClass,
105
+ request: NilClass,
106
+ response: NilClass,
107
+ message: T.nilable(String)
108
+ ).returns(T.attached_class)
109
+ end
110
+ def self.new(
111
+ url:,
112
+ status: nil,
113
+ headers: nil,
114
+ body: nil,
115
+ request: nil,
116
+ response: nil,
117
+ message: "Request timed out."
118
+ )
119
+ end
120
+ end
121
+
122
+ class APIStatusError < Openlayer::Errors::APIError
123
+ # @api private
124
+ sig do
125
+ params(
126
+ url: URI::Generic,
127
+ status: Integer,
128
+ headers: T.nilable(T::Hash[String, String]),
129
+ body: T.nilable(Object),
130
+ request: NilClass,
131
+ response: NilClass,
132
+ message: T.nilable(String)
133
+ ).returns(T.attached_class)
134
+ end
135
+ def self.for(
136
+ url:,
137
+ status:,
138
+ headers:,
139
+ body:,
140
+ request:,
141
+ response:,
142
+ message: nil
143
+ )
144
+ end
145
+
146
+ sig { returns(Integer) }
147
+ attr_accessor :status
148
+
149
+ # @api private
150
+ sig do
151
+ params(
152
+ url: URI::Generic,
153
+ status: Integer,
154
+ headers: T.nilable(T::Hash[String, String]),
155
+ body: T.nilable(Object),
156
+ request: NilClass,
157
+ response: NilClass,
158
+ message: T.nilable(String)
159
+ ).returns(T.attached_class)
160
+ end
161
+ def self.new(
162
+ url:,
163
+ status:,
164
+ headers:,
165
+ body:,
166
+ request:,
167
+ response:,
168
+ message: nil
169
+ )
170
+ end
171
+ end
172
+
173
+ class BadRequestError < Openlayer::Errors::APIStatusError
174
+ HTTP_STATUS = 400
175
+ end
176
+
177
+ class AuthenticationError < Openlayer::Errors::APIStatusError
178
+ HTTP_STATUS = 401
179
+ end
180
+
181
+ class PermissionDeniedError < Openlayer::Errors::APIStatusError
182
+ HTTP_STATUS = 403
183
+ end
184
+
185
+ class NotFoundError < Openlayer::Errors::APIStatusError
186
+ HTTP_STATUS = 404
187
+ end
188
+
189
+ class ConflictError < Openlayer::Errors::APIStatusError
190
+ HTTP_STATUS = 409
191
+ end
192
+
193
+ class UnprocessableEntityError < Openlayer::Errors::APIStatusError
194
+ HTTP_STATUS = 422
195
+ end
196
+
197
+ class RateLimitError < Openlayer::Errors::APIStatusError
198
+ HTTP_STATUS = 429
199
+ end
200
+
201
+ class InternalServerError < Openlayer::Errors::APIStatusError
202
+ HTTP_STATUS = T.let((500..), T::Range[Integer])
203
+ end
204
+ end
205
+ end
@@ -0,0 +1,37 @@
1
+ # typed: strong
2
+
3
+ module Openlayer
4
+ class FilePart
5
+ sig { returns(T.any(Pathname, StringIO, IO, String)) }
6
+ attr_reader :content
7
+
8
+ sig { returns(T.nilable(String)) }
9
+ attr_reader :content_type
10
+
11
+ sig { returns(T.nilable(String)) }
12
+ attr_reader :filename
13
+
14
+ # @api private
15
+ sig { returns(String) }
16
+ private def read
17
+ end
18
+
19
+ sig { params(a: T.anything).returns(String) }
20
+ def to_json(*a)
21
+ end
22
+
23
+ sig { params(a: T.anything).returns(String) }
24
+ def to_yaml(*a)
25
+ end
26
+
27
+ sig do
28
+ params(
29
+ content: T.any(Pathname, StringIO, IO, String),
30
+ filename: T.nilable(T.any(Pathname, String)),
31
+ content_type: T.nilable(String)
32
+ ).returns(T.attached_class)
33
+ end
34
+ def self.new(content, filename: nil, content_type: nil)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,293 @@
1
+ # typed: strong
2
+
3
+ module Openlayer
4
+ module Internal
5
+ module Transport
6
+ # @api private
7
+ class BaseClient
8
+ extend Openlayer::Internal::Util::SorbetRuntimeSupport
9
+
10
+ abstract!
11
+
12
+ RequestComponents =
13
+ T.type_alias do
14
+ {
15
+ method: Symbol,
16
+ path: T.any(String, T::Array[String]),
17
+ query:
18
+ T.nilable(
19
+ T::Hash[String, T.nilable(T.any(T::Array[String], String))]
20
+ ),
21
+ headers:
22
+ T.nilable(
23
+ T::Hash[
24
+ String,
25
+ T.nilable(
26
+ T.any(
27
+ String,
28
+ Integer,
29
+ T::Array[T.nilable(T.any(String, Integer))]
30
+ )
31
+ )
32
+ ]
33
+ ),
34
+ body: T.nilable(T.anything),
35
+ unwrap:
36
+ T.nilable(
37
+ T.any(
38
+ Symbol,
39
+ Integer,
40
+ T::Array[T.any(Symbol, Integer)],
41
+ T.proc.params(arg0: T.anything).returns(T.anything)
42
+ )
43
+ ),
44
+ page:
45
+ T.nilable(
46
+ T::Class[
47
+ Openlayer::Internal::Type::BasePage[
48
+ Openlayer::Internal::Type::BaseModel
49
+ ]
50
+ ]
51
+ ),
52
+ stream: T.nilable(T::Class[T.anything]),
53
+ model: T.nilable(Openlayer::Internal::Type::Converter::Input),
54
+ options: T.nilable(Openlayer::RequestOptions::OrHash)
55
+ }
56
+ end
57
+
58
+ RequestInput =
59
+ T.type_alias do
60
+ {
61
+ method: Symbol,
62
+ url: URI::Generic,
63
+ headers: T::Hash[String, String],
64
+ body: T.anything,
65
+ max_retries: Integer,
66
+ timeout: Float
67
+ }
68
+ end
69
+
70
+ # from whatwg fetch spec
71
+ MAX_REDIRECTS = 20
72
+
73
+ PLATFORM_HEADERS = T::Hash[String, String]
74
+
75
+ class << self
76
+ # @api private
77
+ sig do
78
+ params(
79
+ req: Openlayer::Internal::Transport::BaseClient::RequestComponents
80
+ ).void
81
+ end
82
+ def validate!(req)
83
+ end
84
+
85
+ # @api private
86
+ sig do
87
+ params(status: Integer, headers: T::Hash[String, String]).returns(
88
+ T::Boolean
89
+ )
90
+ end
91
+ def should_retry?(status, headers:)
92
+ end
93
+
94
+ # @api private
95
+ sig do
96
+ params(
97
+ request: Openlayer::Internal::Transport::BaseClient::RequestInput,
98
+ status: Integer,
99
+ response_headers: T::Hash[String, String]
100
+ ).returns(Openlayer::Internal::Transport::BaseClient::RequestInput)
101
+ end
102
+ def follow_redirect(request, status:, response_headers:)
103
+ end
104
+
105
+ # @api private
106
+ sig do
107
+ params(
108
+ status: T.any(Integer, Openlayer::Errors::APIConnectionError),
109
+ stream: T.nilable(T::Enumerable[String])
110
+ ).void
111
+ end
112
+ def reap_connection!(status, stream:)
113
+ end
114
+ end
115
+
116
+ sig { returns(URI::Generic) }
117
+ attr_reader :base_url
118
+
119
+ sig { returns(Float) }
120
+ attr_reader :timeout
121
+
122
+ sig { returns(Integer) }
123
+ attr_reader :max_retries
124
+
125
+ sig { returns(Float) }
126
+ attr_reader :initial_retry_delay
127
+
128
+ sig { returns(Float) }
129
+ attr_reader :max_retry_delay
130
+
131
+ sig { returns(T::Hash[String, String]) }
132
+ attr_reader :headers
133
+
134
+ sig { returns(T.nilable(String)) }
135
+ attr_reader :idempotency_header
136
+
137
+ # @api private
138
+ sig { returns(Openlayer::Internal::Transport::PooledNetRequester) }
139
+ attr_reader :requester
140
+
141
+ # @api private
142
+ sig do
143
+ params(
144
+ base_url: String,
145
+ timeout: Float,
146
+ max_retries: Integer,
147
+ initial_retry_delay: Float,
148
+ max_retry_delay: Float,
149
+ headers:
150
+ T::Hash[
151
+ String,
152
+ T.nilable(
153
+ T.any(
154
+ String,
155
+ Integer,
156
+ T::Array[T.nilable(T.any(String, Integer))]
157
+ )
158
+ )
159
+ ],
160
+ idempotency_header: T.nilable(String)
161
+ ).returns(T.attached_class)
162
+ end
163
+ def self.new(
164
+ base_url:,
165
+ timeout: 0.0,
166
+ max_retries: 0,
167
+ initial_retry_delay: 0.0,
168
+ max_retry_delay: 0.0,
169
+ headers: {},
170
+ idempotency_header: nil
171
+ )
172
+ end
173
+
174
+ # @api private
175
+ sig { overridable.returns(T::Hash[String, String]) }
176
+ private def auth_headers
177
+ end
178
+
179
+ # @api private
180
+ sig { returns(String) }
181
+ private def generate_idempotency_key
182
+ end
183
+
184
+ # @api private
185
+ sig do
186
+ overridable
187
+ .params(
188
+ req:
189
+ Openlayer::Internal::Transport::BaseClient::RequestComponents,
190
+ opts: Openlayer::Internal::AnyHash
191
+ )
192
+ .returns(Openlayer::Internal::Transport::BaseClient::RequestInput)
193
+ end
194
+ private def build_request(req, opts)
195
+ end
196
+
197
+ # @api private
198
+ sig do
199
+ params(
200
+ headers: T::Hash[String, String],
201
+ retry_count: Integer
202
+ ).returns(Float)
203
+ end
204
+ private def retry_delay(headers, retry_count:)
205
+ end
206
+
207
+ # @api private
208
+ sig do
209
+ params(
210
+ request: Openlayer::Internal::Transport::BaseClient::RequestInput,
211
+ redirect_count: Integer,
212
+ retry_count: Integer,
213
+ send_retry_header: T::Boolean
214
+ ).returns([Integer, Net::HTTPResponse, T::Enumerable[String]])
215
+ end
216
+ def send_request(
217
+ request,
218
+ redirect_count:,
219
+ retry_count:,
220
+ send_retry_header:
221
+ )
222
+ end
223
+
224
+ # Execute the request specified by `req`. This is the method that all resource
225
+ # methods call into.
226
+ #
227
+ # @overload request(method, path, query: {}, headers: {}, body: nil, unwrap: nil, page: nil, stream: nil, model: Openlayer::Internal::Type::Unknown, options: {})
228
+ sig do
229
+ params(
230
+ method: Symbol,
231
+ path: T.any(String, T::Array[String]),
232
+ query:
233
+ T.nilable(
234
+ T::Hash[String, T.nilable(T.any(T::Array[String], String))]
235
+ ),
236
+ headers:
237
+ T.nilable(
238
+ T::Hash[
239
+ String,
240
+ T.nilable(
241
+ T.any(
242
+ String,
243
+ Integer,
244
+ T::Array[T.nilable(T.any(String, Integer))]
245
+ )
246
+ )
247
+ ]
248
+ ),
249
+ body: T.nilable(T.anything),
250
+ unwrap:
251
+ T.nilable(
252
+ T.any(
253
+ Symbol,
254
+ Integer,
255
+ T::Array[T.any(Symbol, Integer)],
256
+ T.proc.params(arg0: T.anything).returns(T.anything)
257
+ )
258
+ ),
259
+ page:
260
+ T.nilable(
261
+ T::Class[
262
+ Openlayer::Internal::Type::BasePage[
263
+ Openlayer::Internal::Type::BaseModel
264
+ ]
265
+ ]
266
+ ),
267
+ stream: T.nilable(T::Class[T.anything]),
268
+ model: T.nilable(Openlayer::Internal::Type::Converter::Input),
269
+ options: T.nilable(Openlayer::RequestOptions::OrHash)
270
+ ).returns(T.anything)
271
+ end
272
+ def request(
273
+ method,
274
+ path,
275
+ query: {},
276
+ headers: {},
277
+ body: nil,
278
+ unwrap: nil,
279
+ page: nil,
280
+ stream: nil,
281
+ model: Openlayer::Internal::Type::Unknown,
282
+ options: {}
283
+ )
284
+ end
285
+
286
+ # @api private
287
+ sig { returns(String) }
288
+ def inspect
289
+ end
290
+ end
291
+ end
292
+ end
293
+ end
@@ -0,0 +1,79 @@
1
+ # typed: strong
2
+
3
+ module Openlayer
4
+ module Internal
5
+ module Transport
6
+ # @api private
7
+ class PooledNetRequester
8
+ extend Openlayer::Internal::Util::SorbetRuntimeSupport
9
+
10
+ Request =
11
+ T.type_alias do
12
+ {
13
+ method: Symbol,
14
+ url: URI::Generic,
15
+ headers: T::Hash[String, String],
16
+ body: T.anything,
17
+ deadline: Float
18
+ }
19
+ end
20
+
21
+ # from the golang stdlib
22
+ # https://github.com/golang/go/blob/c8eced8580028328fde7c03cbfcb720ce15b2358/src/net/http/transport.go#L49
23
+ KEEP_ALIVE_TIMEOUT = 30
24
+
25
+ DEFAULT_MAX_CONNECTIONS = T.let(T.unsafe(nil), Integer)
26
+
27
+ class << self
28
+ # @api private
29
+ sig { params(url: URI::Generic).returns(Net::HTTP) }
30
+ def connect(url)
31
+ end
32
+
33
+ # @api private
34
+ sig { params(conn: Net::HTTP, deadline: Float).void }
35
+ def calibrate_socket_timeout(conn, deadline)
36
+ end
37
+
38
+ # @api private
39
+ sig do
40
+ params(
41
+ request:
42
+ Openlayer::Internal::Transport::PooledNetRequester::Request,
43
+ blk: T.proc.params(arg0: String).void
44
+ ).returns([Net::HTTPGenericRequest, T.proc.void])
45
+ end
46
+ def build_request(request, &blk)
47
+ end
48
+ end
49
+
50
+ # @api private
51
+ sig do
52
+ params(
53
+ url: URI::Generic,
54
+ deadline: Float,
55
+ blk: T.proc.params(arg0: Net::HTTP).void
56
+ ).void
57
+ end
58
+ private def with_pool(url, deadline:, &blk)
59
+ end
60
+
61
+ # @api private
62
+ sig do
63
+ params(
64
+ request: Openlayer::Internal::Transport::PooledNetRequester::Request
65
+ ).returns([Integer, Net::HTTPResponse, T::Enumerable[String]])
66
+ end
67
+ def execute(request)
68
+ end
69
+
70
+ # @api private
71
+ sig { params(size: Integer).returns(T.attached_class) }
72
+ def self.new(
73
+ size: Openlayer::Internal::Transport::PooledNetRequester::DEFAULT_MAX_CONNECTIONS
74
+ )
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end