autorender 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. checksums.yaml +7 -0
  2. data/.ignore +2 -0
  3. data/CHANGELOG.md +41 -0
  4. data/README.md +266 -0
  5. data/SECURITY.md +27 -0
  6. data/lib/autorender/client.rb +98 -0
  7. data/lib/autorender/errors.rb +228 -0
  8. data/lib/autorender/file_part.rb +58 -0
  9. data/lib/autorender/internal/page_pagination.rb +96 -0
  10. data/lib/autorender/internal/transport/base_client.rb +576 -0
  11. data/lib/autorender/internal/transport/pooled_net_requester.rb +210 -0
  12. data/lib/autorender/internal/type/array_of.rb +168 -0
  13. data/lib/autorender/internal/type/base_model.rb +531 -0
  14. data/lib/autorender/internal/type/base_page.rb +55 -0
  15. data/lib/autorender/internal/type/boolean.rb +77 -0
  16. data/lib/autorender/internal/type/converter.rb +327 -0
  17. data/lib/autorender/internal/type/enum.rb +131 -0
  18. data/lib/autorender/internal/type/file_input.rb +111 -0
  19. data/lib/autorender/internal/type/hash_of.rb +188 -0
  20. data/lib/autorender/internal/type/request_parameters.rb +42 -0
  21. data/lib/autorender/internal/type/union.rb +237 -0
  22. data/lib/autorender/internal/type/unknown.rb +81 -0
  23. data/lib/autorender/internal/util.rb +968 -0
  24. data/lib/autorender/internal.rb +20 -0
  25. data/lib/autorender/models/file_delete_params.rb +20 -0
  26. data/lib/autorender/models/file_list_params.rb +65 -0
  27. data/lib/autorender/models/file_list_response.rb +167 -0
  28. data/lib/autorender/models/file_rename_params.rb +29 -0
  29. data/lib/autorender/models/file_rename_response.rb +143 -0
  30. data/lib/autorender/models/file_retrieve_params.rb +20 -0
  31. data/lib/autorender/models/file_retrieve_response.rb +143 -0
  32. data/lib/autorender/models/folder_create_params.rb +30 -0
  33. data/lib/autorender/models/folder_create_response.rb +54 -0
  34. data/lib/autorender/models/folder_delete_params.rb +20 -0
  35. data/lib/autorender/models/folder_list_params.rb +49 -0
  36. data/lib/autorender/models/folder_list_response.rb +65 -0
  37. data/lib/autorender/models/folder_rename_params.rb +29 -0
  38. data/lib/autorender/models/folder_rename_response.rb +54 -0
  39. data/lib/autorender/models/multipart_upload_complete_params.rb +26 -0
  40. data/lib/autorender/models/multipart_upload_complete_response.rb +144 -0
  41. data/lib/autorender/models/multipart_upload_start_params.rb +82 -0
  42. data/lib/autorender/models/multipart_upload_start_response.rb +105 -0
  43. data/lib/autorender/models/upload_create_from_url_params.rb +76 -0
  44. data/lib/autorender/models/upload_create_from_url_response.rb +144 -0
  45. data/lib/autorender/models/upload_create_params.rb +86 -0
  46. data/lib/autorender/models/upload_create_response.rb +144 -0
  47. data/lib/autorender/models.rb +65 -0
  48. data/lib/autorender/request_options.rb +77 -0
  49. data/lib/autorender/resources/files.rb +108 -0
  50. data/lib/autorender/resources/folders.rb +109 -0
  51. data/lib/autorender/resources/multipart_uploads.rb +66 -0
  52. data/lib/autorender/resources/uploads.rb +90 -0
  53. data/lib/autorender/version.rb +5 -0
  54. data/lib/autorender.rb +82 -0
  55. data/manifest.yaml +17 -0
  56. data/rbi/autorender/client.rbi +62 -0
  57. data/rbi/autorender/errors.rbi +205 -0
  58. data/rbi/autorender/file_part.rbi +37 -0
  59. data/rbi/autorender/internal/page_pagination.rbi +28 -0
  60. data/rbi/autorender/internal/transport/base_client.rbi +300 -0
  61. data/rbi/autorender/internal/transport/pooled_net_requester.rbi +84 -0
  62. data/rbi/autorender/internal/type/array_of.rbi +104 -0
  63. data/rbi/autorender/internal/type/base_model.rbi +308 -0
  64. data/rbi/autorender/internal/type/base_page.rbi +42 -0
  65. data/rbi/autorender/internal/type/boolean.rbi +58 -0
  66. data/rbi/autorender/internal/type/converter.rbi +216 -0
  67. data/rbi/autorender/internal/type/enum.rbi +82 -0
  68. data/rbi/autorender/internal/type/file_input.rbi +59 -0
  69. data/rbi/autorender/internal/type/hash_of.rbi +104 -0
  70. data/rbi/autorender/internal/type/request_parameters.rbi +29 -0
  71. data/rbi/autorender/internal/type/union.rbi +128 -0
  72. data/rbi/autorender/internal/type/unknown.rbi +58 -0
  73. data/rbi/autorender/internal/util.rbi +515 -0
  74. data/rbi/autorender/internal.rbi +18 -0
  75. data/rbi/autorender/models/file_delete_params.rbi +35 -0
  76. data/rbi/autorender/models/file_list_params.rbi +116 -0
  77. data/rbi/autorender/models/file_list_response.rbi +227 -0
  78. data/rbi/autorender/models/file_rename_params.rbi +49 -0
  79. data/rbi/autorender/models/file_rename_response.rbi +205 -0
  80. data/rbi/autorender/models/file_retrieve_params.rbi +35 -0
  81. data/rbi/autorender/models/file_retrieve_response.rbi +209 -0
  82. data/rbi/autorender/models/folder_create_params.rbi +54 -0
  83. data/rbi/autorender/models/folder_create_response.rbi +75 -0
  84. data/rbi/autorender/models/folder_delete_params.rbi +35 -0
  85. data/rbi/autorender/models/folder_list_params.rbi +97 -0
  86. data/rbi/autorender/models/folder_list_response.rbi +105 -0
  87. data/rbi/autorender/models/folder_rename_params.rbi +49 -0
  88. data/rbi/autorender/models/folder_rename_response.rbi +75 -0
  89. data/rbi/autorender/models/multipart_upload_complete_params.rbi +49 -0
  90. data/rbi/autorender/models/multipart_upload_complete_response.rbi +174 -0
  91. data/rbi/autorender/models/multipart_upload_start_params.rbi +138 -0
  92. data/rbi/autorender/models/multipart_upload_start_response.rbi +146 -0
  93. data/rbi/autorender/models/upload_create_from_url_params.rbi +119 -0
  94. data/rbi/autorender/models/upload_create_from_url_response.rbi +174 -0
  95. data/rbi/autorender/models/upload_create_params.rbi +128 -0
  96. data/rbi/autorender/models/upload_create_response.rbi +174 -0
  97. data/rbi/autorender/models.rbi +28 -0
  98. data/rbi/autorender/request_options.rbi +59 -0
  99. data/rbi/autorender/resources/files.rbi +72 -0
  100. data/rbi/autorender/resources/folders.rbi +75 -0
  101. data/rbi/autorender/resources/multipart_uploads.rbi +53 -0
  102. data/rbi/autorender/resources/uploads.rbi +84 -0
  103. data/rbi/autorender/version.rbi +5 -0
  104. data/sig/autorender/client.rbs +32 -0
  105. data/sig/autorender/errors.rbs +117 -0
  106. data/sig/autorender/file_part.rbs +21 -0
  107. data/sig/autorender/internal/page_pagination.rbs +17 -0
  108. data/sig/autorender/internal/transport/base_client.rbs +133 -0
  109. data/sig/autorender/internal/transport/pooled_net_requester.rbs +48 -0
  110. data/sig/autorender/internal/type/array_of.rbs +48 -0
  111. data/sig/autorender/internal/type/base_model.rbs +102 -0
  112. data/sig/autorender/internal/type/base_page.rbs +24 -0
  113. data/sig/autorender/internal/type/boolean.rbs +26 -0
  114. data/sig/autorender/internal/type/converter.rbs +79 -0
  115. data/sig/autorender/internal/type/enum.rbs +32 -0
  116. data/sig/autorender/internal/type/file_input.rbs +25 -0
  117. data/sig/autorender/internal/type/hash_of.rbs +48 -0
  118. data/sig/autorender/internal/type/request_parameters.rbs +19 -0
  119. data/sig/autorender/internal/type/union.rbs +52 -0
  120. data/sig/autorender/internal/type/unknown.rbs +26 -0
  121. data/sig/autorender/internal/util.rbs +199 -0
  122. data/sig/autorender/internal.rbs +9 -0
  123. data/sig/autorender/models/file_delete_params.rbs +23 -0
  124. data/sig/autorender/models/file_list_params.rbs +79 -0
  125. data/sig/autorender/models/file_list_response.rbs +159 -0
  126. data/sig/autorender/models/file_rename_params.rbs +28 -0
  127. data/sig/autorender/models/file_rename_response.rbs +132 -0
  128. data/sig/autorender/models/file_retrieve_params.rbs +23 -0
  129. data/sig/autorender/models/file_retrieve_response.rbs +132 -0
  130. data/sig/autorender/models/folder_create_params.rbs +30 -0
  131. data/sig/autorender/models/folder_create_response.rbs +50 -0
  132. data/sig/autorender/models/folder_delete_params.rbs +23 -0
  133. data/sig/autorender/models/folder_list_params.rbs +57 -0
  134. data/sig/autorender/models/folder_list_response.rbs +65 -0
  135. data/sig/autorender/models/folder_rename_params.rbs +28 -0
  136. data/sig/autorender/models/folder_rename_response.rbs +50 -0
  137. data/sig/autorender/models/multipart_upload_complete_params.rbs +30 -0
  138. data/sig/autorender/models/multipart_upload_complete_response.rbs +131 -0
  139. data/sig/autorender/models/multipart_upload_start_params.rbs +90 -0
  140. data/sig/autorender/models/multipart_upload_start_response.rbs +92 -0
  141. data/sig/autorender/models/upload_create_from_url_params.rbs +75 -0
  142. data/sig/autorender/models/upload_create_from_url_response.rbs +131 -0
  143. data/sig/autorender/models/upload_create_params.rbs +80 -0
  144. data/sig/autorender/models/upload_create_response.rbs +131 -0
  145. data/sig/autorender/models.rbs +25 -0
  146. data/sig/autorender/request_options.rbs +36 -0
  147. data/sig/autorender/resources/files.rbs +32 -0
  148. data/sig/autorender/resources/folders.rbs +31 -0
  149. data/sig/autorender/resources/multipart_uploads.rbs +26 -0
  150. data/sig/autorender/resources/uploads.rbs +32 -0
  151. data/sig/autorender/version.rbs +3 -0
  152. metadata +223 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 373ec94788881627b00078f509dc031303c957a3fdc39df844de1855eeb8a636
4
+ data.tar.gz: 337b6109d9222d7cbaa362033821c8112061a82fc601097d36528ffb2321152b
5
+ SHA512:
6
+ metadata.gz: c9e8f4c35784f3a1302f51267ab17fcf93ae52a252974e54ce6857132b55bb991a9941bd10de676f54b83108d9cd1ffbca3cc3245e992629266cde4796d6d510
7
+ data.tar.gz: 3c7ef1cf3bded72de42fdc0b7f90d21eae1ea80107e1a1339587313df3dd49dbf216c0d6fa67a0a416d58b6512501bb34c4cd434ed3f26812447200882b4886d
data/.ignore ADDED
@@ -0,0 +1,2 @@
1
+ rbi/*
2
+ sig/*
data/CHANGELOG.md ADDED
@@ -0,0 +1,41 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0](https://github.com/autorenderhq/autorender-ruby/compare/v0.0.1...v0.1.0) (2026-05-25)
4
+
5
+
6
+ ### Features
7
+
8
+ * add stlc generate workflow and setup-stlc action ([33702ec](https://github.com/autorenderhq/autorender-ruby/commit/33702eca050ca28e7f94e57cfec04b73f23c9df5))
9
+ * add test CI job ([a8fbe66](https://github.com/autorenderhq/autorender-ruby/commit/a8fbe662d965ca5f29d9e3c6c22d566f4c2a8fc1))
10
+ * **api:** api update ([5e0fc16](https://github.com/autorenderhq/autorender-ruby/commit/5e0fc16a5851c3352fbde1e93e7dfe113c01174d))
11
+ * **api:** api update ([6dc9820](https://github.com/autorenderhq/autorender-ruby/commit/6dc98208876904a00fe6060c77bf37444402772b))
12
+ * **api:** api update ([dd609a7](https://github.com/autorenderhq/autorender-ruby/commit/dd609a73898016e39ade678854a3eeeaa2b48238))
13
+ * **api:** api update ([4cc94ad](https://github.com/autorenderhq/autorender-ruby/commit/4cc94adc26ad538f01d79808130029bd744a2ee3))
14
+ * **api:** api update ([c8a41c7](https://github.com/autorenderhq/autorender-ruby/commit/c8a41c7d7564bc736de43fa4c791608348bdb0f7))
15
+ * **api:** api update ([0e228df](https://github.com/autorenderhq/autorender-ruby/commit/0e228df68c6f36ce4daa497df77bbb053c2244f7))
16
+ * **api:** api update ([4367475](https://github.com/autorenderhq/autorender-ruby/commit/4367475283baab31f04e1617ea462ae8784758d1))
17
+ * **api:** api update ([a9470bb](https://github.com/autorenderhq/autorender-ruby/commit/a9470bb8ea34fd597ba981dd1aedbceda9bd0210))
18
+ * **api:** api update ([df3c1b1](https://github.com/autorenderhq/autorender-ruby/commit/df3c1b1561943ccc9de1b51abe60adabcd576aa8))
19
+ * **api:** api update ([fb07d3e](https://github.com/autorenderhq/autorender-ruby/commit/fb07d3eff80815340117fca67aae513e3a91b987))
20
+ * initial stlc build ([8972f10](https://github.com/autorenderhq/autorender-ruby/commit/8972f10cca09ae385f9757795c55e658923c949b))
21
+ * support setting headers via env ([3707a7d](https://github.com/autorenderhq/autorender-ruby/commit/3707a7d00abf789957185ad54eeddca000b3e398))
22
+
23
+
24
+ ### Bug Fixes
25
+
26
+ * **client:** elide content type header on requests without body ([553ad30](https://github.com/autorenderhq/autorender-ruby/commit/553ad304fe2053211d95d0cefce4ed9c922f1d92))
27
+ * patch multipart buffer replay, bodyless DELETE content-type, and test adapter ([eb66723](https://github.com/autorenderhq/autorender-ruby/commit/eb667233b4b537e158d25f357bf91adee5304675))
28
+ * **python:** rename pagination field has_next_page -> has_next to fix pyright lint ([d49e480](https://github.com/autorenderhq/autorender-ruby/commit/d49e480c617a82896affa131551605b80ab84004))
29
+ * restore content-type stripping and eager multipart buffering ([a67c6fb](https://github.com/autorenderhq/autorender-ruby/commit/a67c6fb5b4e7efc52152d6a8d9b642e198ab406b))
30
+ * restore content-type stripping and eager multipart buffering ([5ae6d69](https://github.com/autorenderhq/autorender-ruby/commit/5ae6d69493de87916ed23ddaf7753fae116a4aa8))
31
+ * restore content-type stripping and eager multipart buffering for retries ([8fc3542](https://github.com/autorenderhq/autorender-ruby/commit/8fc3542cbd8a1a5df00057846b890dbb2f1fde24))
32
+ * restore content-type stripping and eager multipart buffering for retries ([c1ea3dd](https://github.com/autorenderhq/autorender-ruby/commit/c1ea3dd618ab041d7753b6d7ec0b99a5f94c349f))
33
+ * restore content-type stripping and eager multipart buffering for retries ([16b199f](https://github.com/autorenderhq/autorender-ruby/commit/16b199ff3f5541ace9bc55bee9724db1c398c153))
34
+ * **test:** pass body as String to ReadIOAdapter so CGI can multi-read ([09e3684](https://github.com/autorenderhq/autorender-ruby/commit/09e3684b6a6e9a921f4bf2ea2927d360622b5189))
35
+ * update FakeCGI test helper to handle buffered String body ([b0bd179](https://github.com/autorenderhq/autorender-ruby/commit/b0bd179fb8ac25c6953fc75db832fe2ab734dd16))
36
+
37
+
38
+ ### Chores
39
+
40
+ * **internal:** more robust bootstrap script ([127a1d1](https://github.com/autorenderhq/autorender-ruby/commit/127a1d1ae9215aff1f662e563de5dc48d269115e))
41
+ * **tests:** bump steady to v0.22.1 ([9ddf2e0](https://github.com/autorenderhq/autorender-ruby/commit/9ddf2e0d1b60a4dd82f50d6c6c74e6e901c01e11))
data/README.md ADDED
@@ -0,0 +1,266 @@
1
+ # Autorender Ruby API library
2
+
3
+ The Autorender Ruby library provides convenient access to the Autorender REST API from any Ruby 3.2.0+ application. It ships with comprehensive types & docstrings in Yard, RBS, and RBI – [see below](https://github.com/autorenderhq/autorender-ruby#Sorbet) for usage with Sorbet. The standard library's `net/http` is used as the HTTP transport, with connection pooling via the `connection_pool` gem.
4
+
5
+ It is generated with [Stainless](https://www.stainless.com/).
6
+
7
+ ## Documentation
8
+
9
+ Documentation for releases of this gem can be found [on RubyDoc](https://gemdocs.org/gems/autorender).
10
+
11
+ The REST API documentation can be found on [autorender.mintlify.app](https://autorender.mintlify.app/).
12
+
13
+ ## Installation
14
+
15
+ To use this gem, install via Bundler by adding the following to your application's `Gemfile`:
16
+
17
+ <!-- x-release-please-start-version -->
18
+
19
+ ```ruby
20
+ gem "autorender", "~> 0.1.0"
21
+ ```
22
+
23
+ <!-- x-release-please-end -->
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ require "bundler/setup"
29
+ require "autorender"
30
+
31
+ autorender = Autorender::Client.new(
32
+ api_key: ENV["AUTORENDER_API_KEY"] # This is the default and can be omitted
33
+ )
34
+
35
+ files = autorender.files.list(limit: 10)
36
+
37
+ puts(files.files)
38
+ ```
39
+
40
+ ### File uploads
41
+
42
+ Request parameters that correspond to file uploads can be passed as raw contents, a [`Pathname`](https://rubyapi.org/3.2/o/pathname) instance, [`StringIO`](https://rubyapi.org/3.2/o/stringio), or more.
43
+
44
+ ```ruby
45
+ require "pathname"
46
+
47
+ # Use `Pathname` to send the filename and/or avoid paging a large file into memory:
48
+ upload = autorender.uploads.create(file: Pathname("/path/to/file"))
49
+
50
+ # Alternatively, pass file contents or a `StringIO` directly:
51
+ upload = autorender.uploads.create(file: File.read("/path/to/file"))
52
+
53
+ # Or, to control the filename and/or content type:
54
+ file = Autorender::FilePart.new(File.read("/path/to/file"), filename: "/path/to/file", content_type: "…")
55
+ upload = autorender.uploads.create(file: file)
56
+
57
+ puts(upload.id)
58
+ ```
59
+
60
+ Note that you can also pass a raw `IO` descriptor, but this disables retries, as the library can't be sure if the descriptor is a file or pipe (which cannot be rewound).
61
+
62
+ ### Handling errors
63
+
64
+ When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of `Autorender::Errors::APIError` will be thrown:
65
+
66
+ ```ruby
67
+ begin
68
+ upload = autorender.uploads.create(file: StringIO.new("<binary>"), file_name: "photo.jpg")
69
+ rescue Autorender::Errors::APIConnectionError => e
70
+ puts("The server could not be reached")
71
+ puts(e.cause) # an underlying Exception, likely raised within `net/http`
72
+ rescue Autorender::Errors::RateLimitError => e
73
+ puts("A 429 status code was received; we should back off a bit.")
74
+ rescue Autorender::Errors::APIStatusError => e
75
+ puts("Another non-200-range status code was received")
76
+ puts(e.status)
77
+ end
78
+ ```
79
+
80
+ Error codes are as follows:
81
+
82
+ | Cause | Error Type |
83
+ | ---------------- | -------------------------- |
84
+ | HTTP 400 | `BadRequestError` |
85
+ | HTTP 401 | `AuthenticationError` |
86
+ | HTTP 403 | `PermissionDeniedError` |
87
+ | HTTP 404 | `NotFoundError` |
88
+ | HTTP 409 | `ConflictError` |
89
+ | HTTP 422 | `UnprocessableEntityError` |
90
+ | HTTP 429 | `RateLimitError` |
91
+ | HTTP >= 500 | `InternalServerError` |
92
+ | Other HTTP error | `APIStatusError` |
93
+ | Timeout | `APITimeoutError` |
94
+ | Network error | `APIConnectionError` |
95
+
96
+ ### Retries
97
+
98
+ Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
99
+
100
+ Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, >=500 Internal errors, and timeouts will all be retried by default.
101
+
102
+ You can use the `max_retries` option to configure or disable this:
103
+
104
+ ```ruby
105
+ # Configure the default for all requests:
106
+ autorender = Autorender::Client.new(
107
+ max_retries: 0 # default is 2
108
+ )
109
+
110
+ # Or, configure per-request:
111
+ autorender.uploads.create(
112
+ file: StringIO.new("<binary>"),
113
+ file_name: "photo.jpg",
114
+ request_options: {max_retries: 5}
115
+ )
116
+ ```
117
+
118
+ ### Timeouts
119
+
120
+ By default, requests will time out after 60 seconds. You can use the timeout option to configure or disable this:
121
+
122
+ ```ruby
123
+ # Configure the default for all requests:
124
+ autorender = Autorender::Client.new(
125
+ timeout: nil # default is 60
126
+ )
127
+
128
+ # Or, configure per-request:
129
+ autorender.uploads.create(
130
+ file: StringIO.new("<binary>"),
131
+ file_name: "photo.jpg",
132
+ request_options: {timeout: 5}
133
+ )
134
+ ```
135
+
136
+ On timeout, `Autorender::Errors::APITimeoutError` is raised.
137
+
138
+ Note that requests that time out are retried by default.
139
+
140
+ ## Advanced concepts
141
+
142
+ ### BaseModel
143
+
144
+ All parameter and response objects inherit from `Autorender::Internal::Type::BaseModel`, which provides several conveniences, including:
145
+
146
+ 1. All fields, including unknown ones, are accessible with `obj[:prop]` syntax, and can be destructured with `obj => {prop: prop}` or pattern-matching syntax.
147
+
148
+ 2. Structural equivalence for equality; if two API calls return the same values, comparing the responses with == will return true.
149
+
150
+ 3. Both instances and the classes themselves can be pretty-printed.
151
+
152
+ 4. Helpers such as `#to_h`, `#deep_to_h`, `#to_json`, and `#to_yaml`.
153
+
154
+ ### Making custom or undocumented requests
155
+
156
+ #### Undocumented properties
157
+
158
+ You can send undocumented parameters to any endpoint, and read undocumented response properties, like so:
159
+
160
+ Note: the `extra_` parameters of the same name overrides the documented parameters.
161
+
162
+ ```ruby
163
+ upload =
164
+ autorender.uploads.create(
165
+ file: StringIO.new("<binary>"),
166
+ file_name: "photo.jpg",
167
+ request_options: {
168
+ extra_query: {my_query_parameter: value},
169
+ extra_body: {my_body_parameter: value},
170
+ extra_headers: {"my-header": value}
171
+ }
172
+ )
173
+
174
+ puts(upload[:my_undocumented_property])
175
+ ```
176
+
177
+ #### Undocumented request params
178
+
179
+ If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` under the `request_options:` parameter when making a request, as seen in the examples above.
180
+
181
+ #### Undocumented endpoints
182
+
183
+ To make requests to undocumented endpoints while retaining the benefit of auth, retries, and so on, you can make requests using `client.request`, like so:
184
+
185
+ ```ruby
186
+ response = client.request(
187
+ method: :post,
188
+ path: '/undocumented/endpoint',
189
+ query: {"dog": "woof"},
190
+ headers: {"useful-header": "interesting-value"},
191
+ body: {"hello": "world"}
192
+ )
193
+ ```
194
+
195
+ ### Concurrency & connection pooling
196
+
197
+ The `Autorender::Client` instances are threadsafe, but are only are fork-safe when there are no in-flight HTTP requests.
198
+
199
+ Each instance of `Autorender::Client` has its own HTTP connection pool with a default size of 99. As such, we recommend instantiating the client once per application in most settings.
200
+
201
+ When all available connections from the pool are checked out, requests wait for a new connection to become available, with queue time counting towards the request timeout.
202
+
203
+ Unless otherwise specified, other classes in the SDK do not have locks protecting their underlying data structure.
204
+
205
+ ## Sorbet
206
+
207
+ This library provides comprehensive [RBI](https://sorbet.org/docs/rbi) definitions, and has no dependency on sorbet-runtime.
208
+
209
+ You can provide typesafe request parameters like so:
210
+
211
+ ```ruby
212
+ autorender.files.list(limit: 10)
213
+ ```
214
+
215
+ Or, equivalently:
216
+
217
+ ```ruby
218
+ # Hashes work, but are not typesafe:
219
+ autorender.files.list(limit: 10)
220
+
221
+ # You can also splat a full Params class:
222
+ params = Autorender::FileListParams.new(limit: 10)
223
+ autorender.files.list(**params)
224
+ ```
225
+
226
+ ### Enums
227
+
228
+ Since this library does not depend on `sorbet-runtime`, it cannot provide [`T::Enum`](https://sorbet.org/docs/tenum) instances. Instead, we provide "tagged symbols" instead, which is always a primitive at runtime:
229
+
230
+ ```ruby
231
+ # :name_asc
232
+ puts(Autorender::FileListParams::Sort::NAME_ASC)
233
+
234
+ # Revealed type: `T.all(Autorender::FileListParams::Sort, Symbol)`
235
+ T.reveal_type(Autorender::FileListParams::Sort::NAME_ASC)
236
+ ```
237
+
238
+ Enum parameters have a "relaxed" type, so you can either pass in enum constants or their literal value:
239
+
240
+ ```ruby
241
+ # Using the enum constants preserves the tagged type information:
242
+ autorender.files.list(
243
+ sort: Autorender::FileListParams::Sort::NAME_ASC,
244
+ # …
245
+ )
246
+
247
+ # Literal values are also permissible:
248
+ autorender.files.list(
249
+ sort: :name_asc,
250
+ # …
251
+ )
252
+ ```
253
+
254
+ ## Versioning
255
+
256
+ This package follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions. As the library is in initial development and has a major version of `0`, APIs may change at any time.
257
+
258
+ This package considers improvements to the (non-runtime) `*.rbi` and `*.rbs` type definitions to be non-breaking changes.
259
+
260
+ ## Requirements
261
+
262
+ Ruby 3.2.0 or higher.
263
+
264
+ ## Contributing
265
+
266
+ See [the contributing documentation](https://github.com/autorenderhq/autorender-ruby/tree/main/CONTRIBUTING.md).
data/SECURITY.md ADDED
@@ -0,0 +1,27 @@
1
+ # Security Policy
2
+
3
+ ## Reporting Security Issues
4
+
5
+ This SDK is generated by [Stainless Software Inc](http://stainless.com). Stainless takes security seriously, and encourages you to report any security vulnerability promptly so that appropriate action can be taken.
6
+
7
+ To report a security issue, please contact the Stainless team at security@stainless.com.
8
+
9
+ ## Responsible Disclosure
10
+
11
+ We appreciate the efforts of security researchers and individuals who help us maintain the security of
12
+ SDKs we generate. If you believe you have found a security vulnerability, please adhere to responsible
13
+ disclosure practices by allowing us a reasonable amount of time to investigate and address the issue
14
+ before making any information public.
15
+
16
+ ## Reporting Non-SDK Related Security Issues
17
+
18
+ If you encounter security issues that are not directly related to SDKs but pertain to the services
19
+ or products provided by Autorender, please follow the respective company's security reporting guidelines.
20
+
21
+ ### Autorender Terms and Policies
22
+
23
+ Please contact engineering@autorender.io for any questions or concerns regarding the security of our services.
24
+
25
+ ---
26
+
27
+ Thank you for helping us keep the SDKs and systems they interact with secure.
@@ -0,0 +1,98 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Autorender
4
+ class Client < Autorender::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
17
+
18
+ # @return [String, nil]
19
+ attr_reader :api_key
20
+
21
+ # Upload endpoints (API key required)
22
+ # @return [Autorender::Resources::Uploads]
23
+ attr_reader :uploads
24
+
25
+ # File management endpoints (API key required)
26
+ # @return [Autorender::Resources::Files]
27
+ attr_reader :files
28
+
29
+ # Folder management endpoints (API key required)
30
+ # @return [Autorender::Resources::Folders]
31
+ attr_reader :folders
32
+
33
+ # Upload endpoints (API key required)
34
+ # @return [Autorender::Resources::MultipartUploads]
35
+ attr_reader :multipart_uploads
36
+
37
+ # @api private
38
+ #
39
+ # @return [Hash{String=>String}]
40
+ private def auth_headers
41
+ {"x-api-key" => @api_key}
42
+ end
43
+
44
+ # Creates and returns a new client for interacting with the API.
45
+ #
46
+ # @param api_key [String, nil] Defaults to `ENV["AUTORENDER_API_KEY"]`
47
+ #
48
+ # @param base_url [String, nil] Override the default base URL for the API, e.g.,
49
+ # `"https://api.example.com/v2/"`. Defaults to `ENV["AUTORENDER_BASE_URL"]`
50
+ #
51
+ # @param max_retries [Integer] Max number of retries to attempt after a failed retryable request.
52
+ #
53
+ # @param timeout [Float]
54
+ #
55
+ # @param initial_retry_delay [Float]
56
+ #
57
+ # @param max_retry_delay [Float]
58
+ def initialize(
59
+ api_key: ENV["AUTORENDER_API_KEY"],
60
+ base_url: ENV["AUTORENDER_BASE_URL"],
61
+ max_retries: self.class::DEFAULT_MAX_RETRIES,
62
+ timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
63
+ initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
64
+ max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
65
+ )
66
+ base_url ||= "https://upload.autorender.io"
67
+
68
+ headers = {}
69
+ custom_headers_env = ENV["AUTORENDER_CUSTOM_HEADERS"]
70
+ unless custom_headers_env.nil?
71
+ parsed = {}
72
+ custom_headers_env.split("\n").each do |line|
73
+ colon = line.index(":")
74
+ unless colon.nil?
75
+ parsed[line[0...colon].strip] = line[(colon + 1)..].strip
76
+ end
77
+ end
78
+ headers = parsed.merge(headers)
79
+ end
80
+
81
+ @api_key = api_key&.to_s
82
+
83
+ super(
84
+ base_url: base_url,
85
+ timeout: timeout,
86
+ max_retries: max_retries,
87
+ initial_retry_delay: initial_retry_delay,
88
+ max_retry_delay: max_retry_delay,
89
+ headers: headers
90
+ )
91
+
92
+ @uploads = Autorender::Resources::Uploads.new(client: self)
93
+ @files = Autorender::Resources::Files.new(client: self)
94
+ @folders = Autorender::Resources::Folders.new(client: self)
95
+ @multipart_uploads = Autorender::Resources::MultipartUploads.new(client: self)
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,228 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Autorender
4
+ module Errors
5
+ class Error < StandardError
6
+ # @!attribute cause
7
+ #
8
+ # @return [StandardError, nil]
9
+ end
10
+
11
+ class ConversionError < Autorender::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 < Autorender::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 < Autorender::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 < Autorender::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 < Autorender::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
+ Autorender::Errors::BadRequestError.new(**kwargs)
150
+ in 401
151
+ Autorender::Errors::AuthenticationError.new(**kwargs)
152
+ in 403
153
+ Autorender::Errors::PermissionDeniedError.new(**kwargs)
154
+ in 404
155
+ Autorender::Errors::NotFoundError.new(**kwargs)
156
+ in 409
157
+ Autorender::Errors::ConflictError.new(**kwargs)
158
+ in 422
159
+ Autorender::Errors::UnprocessableEntityError.new(**kwargs)
160
+ in 429
161
+ Autorender::Errors::RateLimitError.new(**kwargs)
162
+ in (500..)
163
+ Autorender::Errors::InternalServerError.new(**kwargs)
164
+ else
165
+ Autorender::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 < Autorender::Errors::APIStatusError
197
+ HTTP_STATUS = 400
198
+ end
199
+
200
+ class AuthenticationError < Autorender::Errors::APIStatusError
201
+ HTTP_STATUS = 401
202
+ end
203
+
204
+ class PermissionDeniedError < Autorender::Errors::APIStatusError
205
+ HTTP_STATUS = 403
206
+ end
207
+
208
+ class NotFoundError < Autorender::Errors::APIStatusError
209
+ HTTP_STATUS = 404
210
+ end
211
+
212
+ class ConflictError < Autorender::Errors::APIStatusError
213
+ HTTP_STATUS = 409
214
+ end
215
+
216
+ class UnprocessableEntityError < Autorender::Errors::APIStatusError
217
+ HTTP_STATUS = 422
218
+ end
219
+
220
+ class RateLimitError < Autorender::Errors::APIStatusError
221
+ HTTP_STATUS = 429
222
+ end
223
+
224
+ class InternalServerError < Autorender::Errors::APIStatusError
225
+ HTTP_STATUS = (500..)
226
+ end
227
+ end
228
+ end