Skip to content

Commit 24f9f11

Browse files
feat(api): manual updates
1 parent 8ac0ad3 commit 24f9f11

File tree

10 files changed

+73
-42
lines changed

10 files changed

+73
-42
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 42
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/imagekit-inc%2Fimagekit-911102f2eaf3be4b34381f6ba089330bed099bb72eb93667ce2f6e72b5934c8c.yml
3-
openapi_spec_hash: 637ad417a580137914441bd790b04cc2
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/imagekit-inc%2Fimagekit-0726d89b19f532c7fb92990d688a9bfb5aa4a9a871d64f49d4ba45bac6998e4a.yml
3+
openapi_spec_hash: 9525bb02ab496b3459a1f93ac50968e3
44
config_hash: 70f9408b8d1dfbcf262a20d6eed50e1c

README.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ image_kit = Imagekit::Client.new(
3333
password: ENV["OPTIONAL_IMAGEKIT_IGNORES_THIS"] # This is the default and can be omitted
3434
)
3535

36-
response = image_kit.files.upload(file: "https://www.example.com/public-url.jpg", file_name: "file-name.jpg")
36+
response = image_kit.files.upload(
37+
file: StringIO.new("https://www.example.com/public-url.jpg"),
38+
file_name: "file-name.jpg"
39+
)
3740

3841
puts(response.videoCodec)
3942
```
@@ -46,14 +49,14 @@ Request parameters that correspond to file uploads can be passed as raw contents
4649
require "pathname"
4750

4851
# Use `Pathname` to send the filename and/or avoid paging a large file into memory:
49-
response = image_kit.beta.v2.files.upload(file: Pathname("/path/to/file"))
52+
response = image_kit.files.upload(file: Pathname("/path/to/file"))
5053

5154
# Alternatively, pass file contents or a `StringIO` directly:
52-
response = image_kit.beta.v2.files.upload(file: File.read("/path/to/file"))
55+
response = image_kit.files.upload(file: File.read("/path/to/file"))
5356

5457
# Or, to control the filename and/or content type:
5558
file = Imagekit::FilePart.new(File.read("/path/to/file"), filename: "/path/to/file", content_type: "")
56-
response = image_kit.beta.v2.files.upload(file: file)
59+
response = image_kit.files.upload(file: file)
5760

5861
puts(response.videoCodec)
5962
```
@@ -66,7 +69,10 @@ When the library is unable to connect to the API, or if the API returns a non-su
6669

6770
```ruby
6871
begin
69-
file = image_kit.files.upload(file: "https://www.example.com/public-url.jpg", file_name: "file-name.jpg")
72+
file = image_kit.files.upload(
73+
file: StringIO.new("https://www.example.com/public-url.jpg"),
74+
file_name: "file-name.jpg"
75+
)
7076
rescue Imagekit::Errors::APIConnectionError => e
7177
puts("The server could not be reached")
7278
puts(e.cause) # an underlying Exception, likely raised within `net/http`
@@ -110,7 +116,7 @@ image_kit = Imagekit::Client.new(
110116

111117
# Or, configure per-request:
112118
image_kit.files.upload(
113-
file: "https://www.example.com/public-url.jpg",
119+
file: StringIO.new("https://www.example.com/public-url.jpg"),
114120
file_name: "file-name.jpg",
115121
request_options: {max_retries: 5}
116122
)
@@ -128,7 +134,7 @@ image_kit = Imagekit::Client.new(
128134

129135
# Or, configure per-request:
130136
image_kit.files.upload(
131-
file: "https://www.example.com/public-url.jpg",
137+
file: StringIO.new("https://www.example.com/public-url.jpg"),
132138
file_name: "file-name.jpg",
133139
request_options: {timeout: 5}
134140
)
@@ -163,7 +169,7 @@ Note: the `extra_` parameters of the same name overrides the documented paramete
163169
```ruby
164170
response =
165171
image_kit.files.upload(
166-
file: "https://www.example.com/public-url.jpg",
172+
file: StringIO.new("https://www.example.com/public-url.jpg"),
167173
file_name: "file-name.jpg",
168174
request_options: {
169175
extra_query: {my_query_parameter: value},
@@ -210,17 +216,26 @@ This library provides comprehensive [RBI](https://sorbet.org/docs/rbi) definitio
210216
You can provide typesafe request parameters like so:
211217

212218
```ruby
213-
image_kit.files.upload(file: "https://www.example.com/public-url.jpg", file_name: "file-name.jpg")
219+
image_kit.files.upload(
220+
file: StringIO.new("https://www.example.com/public-url.jpg"),
221+
file_name: "file-name.jpg"
222+
)
214223
```
215224

216225
Or, equivalently:
217226

218227
```ruby
219228
# Hashes work, but are not typesafe:
220-
image_kit.files.upload(file: "https://www.example.com/public-url.jpg", file_name: "file-name.jpg")
229+
image_kit.files.upload(
230+
file: StringIO.new("https://www.example.com/public-url.jpg"),
231+
file_name: "file-name.jpg"
232+
)
221233

222234
# You can also splat a full Params class:
223-
params = Imagekit::FileUploadParams.new(file: "https://www.example.com/public-url.jpg", file_name: "file-name.jpg")
235+
params = Imagekit::FileUploadParams.new(
236+
file: StringIO.new("https://www.example.com/public-url.jpg"),
237+
file_name: "file-name.jpg"
238+
)
224239
image_kit.files.upload(**params)
225240
```
226241

lib/imagekit/models/file_upload_params.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class FileUploadParams < Imagekit::Internal::Type::BaseModel
1818
# When supplying a URL, the server must receive the response headers within 8
1919
# seconds; otherwise the request fails with 400 Bad Request.
2020
#
21-
# @return [String]
22-
required :file, String
21+
# @return [Pathname, StringIO, IO, String, Imagekit::FilePart]
22+
required :file, Imagekit::Internal::Type::FileInput
2323

2424
# @!attribute file_name
2525
# The name with which the file has to be uploaded. The file name can contain:
@@ -240,7 +240,7 @@ class FileUploadParams < Imagekit::Internal::Type::BaseModel
240240
# Some parameter documentations has been truncated, see
241241
# {Imagekit::Models::FileUploadParams} for more details.
242242
#
243-
# @param file [String] The API accepts any of the following:
243+
# @param file [Pathname, StringIO, IO, String, Imagekit::FilePart] The API accepts any of the following:
244244
#
245245
# @param file_name [String] The name with which the file has to be uploaded.
246246
#

lib/imagekit/resources/files.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def rename(params)
221221
#
222222
# @overload upload(file:, file_name:, token: nil, checks: nil, custom_coordinates: nil, custom_metadata: nil, description: nil, expire: nil, extensions: nil, folder: nil, is_private_file: nil, is_published: nil, overwrite_ai_tags: nil, overwrite_custom_metadata: nil, overwrite_file: nil, overwrite_tags: nil, public_key: nil, response_fields: nil, signature: nil, tags: nil, transformation: nil, use_unique_file_name: nil, webhook_url: nil, request_options: {})
223223
#
224-
# @param file [String] The API accepts any of the following:
224+
# @param file [Pathname, StringIO, IO, String, Imagekit::FilePart] The API accepts any of the following:
225225
#
226226
# @param file_name [String] The name with which the file has to be uploaded.
227227
#

rbi/imagekit/models/file_upload_params.rbi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module Imagekit
2020
#
2121
# When supplying a URL, the server must receive the response headers within 8
2222
# seconds; otherwise the request fails with 400 Bad Request.
23-
sig { returns(String) }
23+
sig { returns(Imagekit::Internal::FileInput) }
2424
attr_accessor :file
2525

2626
# The name with which the file has to be uploaded. The file name can contain:
@@ -290,7 +290,7 @@ module Imagekit
290290

291291
sig do
292292
params(
293-
file: String,
293+
file: Imagekit::Internal::FileInput,
294294
file_name: String,
295295
token: String,
296296
checks: String,
@@ -462,7 +462,7 @@ module Imagekit
462462
sig do
463463
override.returns(
464464
{
465-
file: String,
465+
file: Imagekit::Internal::FileInput,
466466
file_name: String,
467467
token: String,
468468
checks: String,

rbi/imagekit/resources/files.rbi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ module Imagekit
189189
# technologies.
190190
sig do
191191
params(
192-
file: String,
192+
file: Imagekit::Internal::FileInput,
193193
file_name: String,
194194
token: String,
195195
checks: String,

sig/imagekit/models/file_upload_params.rbs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Imagekit
22
module Models
33
type file_upload_params =
44
{
5-
file: String,
5+
file: Imagekit::Internal::file_input,
66
file_name: String,
77
token: String,
88
checks: String,
@@ -32,7 +32,7 @@ module Imagekit
3232
extend Imagekit::Internal::Type::RequestParameters::Converter
3333
include Imagekit::Internal::Type::RequestParameters
3434

35-
attr_accessor file: String
35+
attr_accessor file: Imagekit::Internal::file_input
3636

3737
attr_accessor file_name: String
3838

@@ -127,7 +127,7 @@ module Imagekit
127127
def webhook_url=: (String) -> String
128128

129129
def initialize: (
130-
file: String,
130+
file: Imagekit::Internal::file_input,
131131
file_name: String,
132132
?token: String,
133133
?checks: String,
@@ -154,7 +154,7 @@ module Imagekit
154154
) -> void
155155

156156
def to_hash: -> {
157-
file: String,
157+
file: Imagekit::Internal::file_input,
158158
file_name: String,
159159
token: String,
160160
checks: String,

sig/imagekit/resources/files.rbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module Imagekit
4444
) -> Imagekit::Models::FileRenameResponse
4545

4646
def upload: (
47-
file: String,
47+
file: Imagekit::Internal::file_input,
4848
file_name: String,
4949
?token: String,
5050
?checks: String,

test/imagekit/client_test.rb

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_client_default_request_default_retry_attempts
4545
)
4646

4747
assert_raises(Imagekit::Errors::InternalServerError) do
48-
image_kit.files.upload(file: "file", file_name: "fileName")
48+
image_kit.files.upload(file: Pathname(__FILE__), file_name: "fileName")
4949
end
5050

5151
assert_requested(:any, /./, times: 3)
@@ -63,7 +63,7 @@ def test_client_given_request_default_retry_attempts
6363
)
6464

6565
assert_raises(Imagekit::Errors::InternalServerError) do
66-
image_kit.files.upload(file: "file", file_name: "fileName")
66+
image_kit.files.upload(file: Pathname(__FILE__), file_name: "fileName")
6767
end
6868

6969
assert_requested(:any, /./, times: 4)
@@ -80,7 +80,11 @@ def test_client_default_request_given_retry_attempts
8080
)
8181

8282
assert_raises(Imagekit::Errors::InternalServerError) do
83-
image_kit.files.upload(file: "file", file_name: "fileName", request_options: {max_retries: 3})
83+
image_kit.files.upload(
84+
file: Pathname(__FILE__),
85+
file_name: "fileName",
86+
request_options: {max_retries: 3}
87+
)
8488
end
8589

8690
assert_requested(:any, /./, times: 4)
@@ -98,7 +102,11 @@ def test_client_given_request_given_retry_attempts
98102
)
99103

100104
assert_raises(Imagekit::Errors::InternalServerError) do
101-
image_kit.files.upload(file: "file", file_name: "fileName", request_options: {max_retries: 4})
105+
image_kit.files.upload(
106+
file: Pathname(__FILE__),
107+
file_name: "fileName",
108+
request_options: {max_retries: 4}
109+
)
102110
end
103111

104112
assert_requested(:any, /./, times: 5)
@@ -120,7 +128,7 @@ def test_client_retry_after_seconds
120128
)
121129

122130
assert_raises(Imagekit::Errors::InternalServerError) do
123-
image_kit.files.upload(file: "file", file_name: "fileName")
131+
image_kit.files.upload(file: Pathname(__FILE__), file_name: "fileName")
124132
end
125133

126134
assert_requested(:any, /./, times: 2)
@@ -144,7 +152,7 @@ def test_client_retry_after_date
144152

145153
assert_raises(Imagekit::Errors::InternalServerError) do
146154
Thread.current.thread_variable_set(:time_now, Time.now)
147-
image_kit.files.upload(file: "file", file_name: "fileName")
155+
image_kit.files.upload(file: Pathname(__FILE__), file_name: "fileName")
148156
Thread.current.thread_variable_set(:time_now, nil)
149157
end
150158

@@ -168,7 +176,7 @@ def test_client_retry_after_ms
168176
)
169177

170178
assert_raises(Imagekit::Errors::InternalServerError) do
171-
image_kit.files.upload(file: "file", file_name: "fileName")
179+
image_kit.files.upload(file: Pathname(__FILE__), file_name: "fileName")
172180
end
173181

174182
assert_requested(:any, /./, times: 2)
@@ -186,7 +194,7 @@ def test_retry_count_header
186194
)
187195

188196
assert_raises(Imagekit::Errors::InternalServerError) do
189-
image_kit.files.upload(file: "file", file_name: "fileName")
197+
image_kit.files.upload(file: Pathname(__FILE__), file_name: "fileName")
190198
end
191199

192200
3.times do
@@ -206,7 +214,7 @@ def test_omit_retry_count_header
206214

207215
assert_raises(Imagekit::Errors::InternalServerError) do
208216
image_kit.files.upload(
209-
file: "file",
217+
file: Pathname(__FILE__),
210218
file_name: "fileName",
211219
request_options: {extra_headers: {"x-stainless-retry-count" => nil}}
212220
)
@@ -229,7 +237,7 @@ def test_overwrite_retry_count_header
229237

230238
assert_raises(Imagekit::Errors::InternalServerError) do
231239
image_kit.files.upload(
232-
file: "file",
240+
file: Pathname(__FILE__),
233241
file_name: "fileName",
234242
request_options: {extra_headers: {"x-stainless-retry-count" => "42"}}
235243
)
@@ -257,7 +265,11 @@ def test_client_redirect_307
257265
)
258266

259267
assert_raises(Imagekit::Errors::APIConnectionError) do
260-
image_kit.files.upload(file: "file", file_name: "fileName", request_options: {extra_headers: {}})
268+
image_kit.files.upload(
269+
file: Pathname(__FILE__),
270+
file_name: "fileName",
271+
request_options: {extra_headers: {}}
272+
)
261273
end
262274

263275
recorded, = WebMock::RequestRegistry.instance.requested_signatures.hash.first
@@ -291,7 +303,11 @@ def test_client_redirect_303
291303
)
292304

293305
assert_raises(Imagekit::Errors::APIConnectionError) do
294-
image_kit.files.upload(file: "file", file_name: "fileName", request_options: {extra_headers: {}})
306+
image_kit.files.upload(
307+
file: Pathname(__FILE__),
308+
file_name: "fileName",
309+
request_options: {extra_headers: {}}
310+
)
295311
end
296312

297313
assert_requested(:get, "http://localhost/redirected", times: Imagekit::Client::MAX_REDIRECTS) do
@@ -321,7 +337,7 @@ def test_client_redirect_auth_keep_same_origin
321337

322338
assert_raises(Imagekit::Errors::APIConnectionError) do
323339
image_kit.files.upload(
324-
file: "file",
340+
file: Pathname(__FILE__),
325341
file_name: "fileName",
326342
request_options: {extra_headers: {"authorization" => "Bearer xyz"}}
327343
)
@@ -357,7 +373,7 @@ def test_client_redirect_auth_strip_cross_origin
357373

358374
assert_raises(Imagekit::Errors::APIConnectionError) do
359375
image_kit.files.upload(
360-
file: "file",
376+
file: Pathname(__FILE__),
361377
file_name: "fileName",
362378
request_options: {extra_headers: {"authorization" => "Bearer xyz"}}
363379
)
@@ -379,7 +395,7 @@ def test_default_headers
379395
password: "My Password"
380396
)
381397

382-
image_kit.files.upload(file: "file", file_name: "fileName")
398+
image_kit.files.upload(file: Pathname(__FILE__), file_name: "fileName")
383399

384400
assert_requested(:any, /./) do |req|
385401
headers = req.headers.transform_keys(&:downcase).fetch_values("accept", "content-type")

test/imagekit/resources/files_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def test_rename_required_params
113113
def test_upload_required_params
114114
skip("Prism tests are disabled")
115115

116-
response = @image_kit.files.upload(file: "file", file_name: "fileName")
116+
response = @image_kit.files.upload(file: Pathname(__FILE__), file_name: "fileName")
117117

118118
assert_pattern do
119119
response => Imagekit::Models::FileUploadResponse

0 commit comments

Comments
 (0)