Skip to content

Commit 74e7a6a

Browse files
feat(api): fix spec indentation
1 parent d2ffbf3 commit 74e7a6a

9 files changed

Lines changed: 131 additions & 23 deletions

File tree

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 47
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/imagekit-inc%2Fimagekit-1422f7513f230162270b197061e5768c2e0c803b94b8cd03a5e72544ac75a27f.yml
3-
openapi_spec_hash: 41175e752e6f6ce900b36aecba687fa7
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/imagekit-inc%2Fimagekit-f4cd00365ba96133e0675eae3d5d3c6ac13874789e2ce69a84310ab64a4f87dd.yml
3+
openapi_spec_hash: dce632cfbb5464a98c0f5d8eb9573d68
44
config_hash: 17e408231b0b01676298010c7405f483

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ gem "imagekitio", "~> 4.3.0"
5555
```ruby
5656
require "imagekitio"
5757

58-
image_kit = Imagekitio::Client.new(private_key: "My Private Key")
58+
image_kit = Imagekitio::Client.new(
59+
private_key: ENV["IMAGEKIT_PRIVATE_KEY"], # This is the default and can be omitted
60+
password: ENV["OPTIONAL_IMAGEKIT_IGNORES_THIS"] # This is the default and can be omitted
61+
)
5962

6063
response = image_kit.files.upload(
6164
file: Pathname("/path/to/file"),
@@ -571,8 +574,7 @@ You can use the `max_retries` option to configure or disable this:
571574
```ruby
572575
# Configure the default for all requests:
573576
image_kit = Imagekitio::Client.new(
574-
max_retries: 0, # default is 2
575-
private_key: "My Private Key"
577+
max_retries: 0 # default is 2
576578
)
577579

578580
# Or, configure per-request:
@@ -590,8 +592,7 @@ By default, requests will time out after 60 seconds. You can use the timeout opt
590592
```ruby
591593
# Configure the default for all requests:
592594
image_kit = Imagekitio::Client.new(
593-
timeout: nil, # default is 60
594-
private_key: "My Private Key"
595+
timeout: nil # default is 60
595596
)
596597

597598
# Or, configure per-request:

lib/imagekitio/client.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ class Client < Imagekitio::Internal::Transport::BaseClient
6262
# @return [Imagekitio::Helper]
6363
attr_reader :helper
6464

65+
# @api private
66+
#
67+
# @return [Hash{String=>String}]
68+
private def auth_headers
69+
return {} if @private_key.nil? || @password.nil?
70+
71+
base64_credentials = ["#{@private_key}:#{@password}"].pack("m0")
72+
{"authorization" => "Basic #{base64_credentials}"}
73+
end
74+
6575
# @api private
6676
#
6777
# @return [Boolean]

lib/imagekitio/internal/transport/base_client.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ def initialize(
215215
@max_retry_delay = max_retry_delay
216216
end
217217

218+
# @api private
219+
#
220+
# @return [Hash{String=>String}]
221+
private def auth_headers = {}
222+
218223
# @api private
219224
#
220225
# @return [String]
@@ -271,6 +276,7 @@ def initialize(
271276

272277
headers = Imagekitio::Internal::Util.normalized_headers(
273278
@headers,
279+
auth_headers,
274280
req[:headers].to_h,
275281
opts[:extra_headers].to_h
276282
)

rbi/imagekitio/client.rbi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ module Imagekitio
5757
sig { returns(Imagekitio::Helper) }
5858
attr_reader :helper
5959

60+
# @api private
61+
sig { override.returns(T::Hash[String, String]) }
62+
private def auth_headers
63+
end
64+
6065
# @api private
6166
sig { returns(T::Boolean) }
6267
def base_url_overridden?

rbi/imagekitio/internal/transport/base_client.rbi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ module Imagekitio
173173
)
174174
end
175175

176+
# @api private
177+
sig { overridable.returns(T::Hash[String, String]) }
178+
private def auth_headers
179+
end
180+
176181
# @api private
177182
sig { returns(String) }
178183
private def user_agent

sig/imagekitio/internal/transport/base_client.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ module Imagekitio
8585
?idempotency_header: String?
8686
) -> void
8787

88+
private def auth_headers: -> ::Hash[String, String]
89+
8890
private def user_agent: -> String
8991

9092
private def generate_idempotency_key: -> String

test/imagekitio/client_test.rb

Lines changed: 90 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ def test_raises_on_missing_non_nullable_opts
3737
def test_client_default_request_default_retry_attempts
3838
stub_request(:post, "http://localhost/api/v1/files/upload").to_return_json(status: 500, body: {})
3939

40-
image_kit = Imagekitio::Client.new(base_url: "http://localhost", private_key: "My Private Key")
40+
image_kit =
41+
Imagekitio::Client.new(
42+
base_url: "http://localhost",
43+
private_key: "My Private Key",
44+
password: "My Password"
45+
)
4146

4247
assert_raises(Imagekitio::Errors::InternalServerError) do
4348
image_kit.files.upload(file: StringIO.new("Example data"), file_name: "fileName")
@@ -50,7 +55,12 @@ def test_client_given_request_default_retry_attempts
5055
stub_request(:post, "http://localhost/api/v1/files/upload").to_return_json(status: 500, body: {})
5156

5257
image_kit =
53-
Imagekitio::Client.new(base_url: "http://localhost", private_key: "My Private Key", max_retries: 3)
58+
Imagekitio::Client.new(
59+
base_url: "http://localhost",
60+
private_key: "My Private Key",
61+
password: "My Password",
62+
max_retries: 3
63+
)
5464

5565
assert_raises(Imagekitio::Errors::InternalServerError) do
5666
image_kit.files.upload(file: StringIO.new("Example data"), file_name: "fileName")
@@ -62,7 +72,12 @@ def test_client_given_request_default_retry_attempts
6272
def test_client_default_request_given_retry_attempts
6373
stub_request(:post, "http://localhost/api/v1/files/upload").to_return_json(status: 500, body: {})
6474

65-
image_kit = Imagekitio::Client.new(base_url: "http://localhost", private_key: "My Private Key")
75+
image_kit =
76+
Imagekitio::Client.new(
77+
base_url: "http://localhost",
78+
private_key: "My Private Key",
79+
password: "My Password"
80+
)
6681

6782
assert_raises(Imagekitio::Errors::InternalServerError) do
6883
image_kit.files.upload(
@@ -79,7 +94,12 @@ def test_client_given_request_given_retry_attempts
7994
stub_request(:post, "http://localhost/api/v1/files/upload").to_return_json(status: 500, body: {})
8095

8196
image_kit =
82-
Imagekitio::Client.new(base_url: "http://localhost", private_key: "My Private Key", max_retries: 3)
97+
Imagekitio::Client.new(
98+
base_url: "http://localhost",
99+
private_key: "My Private Key",
100+
password: "My Password",
101+
max_retries: 3
102+
)
83103

84104
assert_raises(Imagekitio::Errors::InternalServerError) do
85105
image_kit.files.upload(
@@ -100,7 +120,12 @@ def test_client_retry_after_seconds
100120
)
101121

102122
image_kit =
103-
Imagekitio::Client.new(base_url: "http://localhost", private_key: "My Private Key", max_retries: 1)
123+
Imagekitio::Client.new(
124+
base_url: "http://localhost",
125+
private_key: "My Private Key",
126+
password: "My Password",
127+
max_retries: 1
128+
)
104129

105130
assert_raises(Imagekitio::Errors::InternalServerError) do
106131
image_kit.files.upload(file: StringIO.new("Example data"), file_name: "fileName")
@@ -120,7 +145,12 @@ def test_client_retry_after_date
120145
)
121146

122147
image_kit =
123-
Imagekitio::Client.new(base_url: "http://localhost", private_key: "My Private Key", max_retries: 1)
148+
Imagekitio::Client.new(
149+
base_url: "http://localhost",
150+
private_key: "My Private Key",
151+
password: "My Password",
152+
max_retries: 1
153+
)
124154

125155
Thread.current.thread_variable_set(:time_now, time_now)
126156
assert_raises(Imagekitio::Errors::InternalServerError) do
@@ -140,7 +170,12 @@ def test_client_retry_after_ms
140170
)
141171

142172
image_kit =
143-
Imagekitio::Client.new(base_url: "http://localhost", private_key: "My Private Key", max_retries: 1)
173+
Imagekitio::Client.new(
174+
base_url: "http://localhost",
175+
private_key: "My Private Key",
176+
password: "My Password",
177+
max_retries: 1
178+
)
144179

145180
assert_raises(Imagekitio::Errors::InternalServerError) do
146181
image_kit.files.upload(file: StringIO.new("Example data"), file_name: "fileName")
@@ -153,7 +188,12 @@ def test_client_retry_after_ms
153188
def test_retry_count_header
154189
stub_request(:post, "http://localhost/api/v1/files/upload").to_return_json(status: 500, body: {})
155190

156-
image_kit = Imagekitio::Client.new(base_url: "http://localhost", private_key: "My Private Key")
191+
image_kit =
192+
Imagekitio::Client.new(
193+
base_url: "http://localhost",
194+
private_key: "My Private Key",
195+
password: "My Password"
196+
)
157197

158198
assert_raises(Imagekitio::Errors::InternalServerError) do
159199
image_kit.files.upload(file: StringIO.new("Example data"), file_name: "fileName")
@@ -167,7 +207,12 @@ def test_retry_count_header
167207
def test_omit_retry_count_header
168208
stub_request(:post, "http://localhost/api/v1/files/upload").to_return_json(status: 500, body: {})
169209

170-
image_kit = Imagekitio::Client.new(base_url: "http://localhost", private_key: "My Private Key")
210+
image_kit =
211+
Imagekitio::Client.new(
212+
base_url: "http://localhost",
213+
private_key: "My Private Key",
214+
password: "My Password"
215+
)
171216

172217
assert_raises(Imagekitio::Errors::InternalServerError) do
173218
image_kit.files.upload(
@@ -185,7 +230,12 @@ def test_omit_retry_count_header
185230
def test_overwrite_retry_count_header
186231
stub_request(:post, "http://localhost/api/v1/files/upload").to_return_json(status: 500, body: {})
187232

188-
image_kit = Imagekitio::Client.new(base_url: "http://localhost", private_key: "My Private Key")
233+
image_kit =
234+
Imagekitio::Client.new(
235+
base_url: "http://localhost",
236+
private_key: "My Private Key",
237+
password: "My Password"
238+
)
189239

190240
assert_raises(Imagekitio::Errors::InternalServerError) do
191241
image_kit.files.upload(
@@ -209,7 +259,12 @@ def test_client_redirect_307
209259
headers: {"location" => "/redirected"}
210260
)
211261

212-
image_kit = Imagekitio::Client.new(base_url: "http://localhost", private_key: "My Private Key")
262+
image_kit =
263+
Imagekitio::Client.new(
264+
base_url: "http://localhost",
265+
private_key: "My Private Key",
266+
password: "My Password"
267+
)
213268

214269
assert_raises(Imagekitio::Errors::APIConnectionError) do
215270
image_kit.files.upload(
@@ -242,7 +297,12 @@ def test_client_redirect_303
242297
headers: {"location" => "/redirected"}
243298
)
244299

245-
image_kit = Imagekitio::Client.new(base_url: "http://localhost", private_key: "My Private Key")
300+
image_kit =
301+
Imagekitio::Client.new(
302+
base_url: "http://localhost",
303+
private_key: "My Private Key",
304+
password: "My Password"
305+
)
246306

247307
assert_raises(Imagekitio::Errors::APIConnectionError) do
248308
image_kit.files.upload(
@@ -270,7 +330,12 @@ def test_client_redirect_auth_keep_same_origin
270330
headers: {"location" => "/redirected"}
271331
)
272332

273-
image_kit = Imagekitio::Client.new(base_url: "http://localhost", private_key: "My Private Key")
333+
image_kit =
334+
Imagekitio::Client.new(
335+
base_url: "http://localhost",
336+
private_key: "My Private Key",
337+
password: "My Password"
338+
)
274339

275340
assert_raises(Imagekitio::Errors::APIConnectionError) do
276341
image_kit.files.upload(
@@ -301,7 +366,12 @@ def test_client_redirect_auth_strip_cross_origin
301366
headers: {"location" => "https://example.com/redirected"}
302367
)
303368

304-
image_kit = Imagekitio::Client.new(base_url: "http://localhost", private_key: "My Private Key")
369+
image_kit =
370+
Imagekitio::Client.new(
371+
base_url: "http://localhost",
372+
private_key: "My Private Key",
373+
password: "My Password"
374+
)
305375

306376
assert_raises(Imagekitio::Errors::APIConnectionError) do
307377
image_kit.files.upload(
@@ -320,7 +390,12 @@ def test_client_redirect_auth_strip_cross_origin
320390
def test_default_headers
321391
stub_request(:post, "http://localhost/api/v1/files/upload").to_return_json(status: 200, body: {})
322392

323-
image_kit = Imagekitio::Client.new(base_url: "http://localhost", private_key: "My Private Key")
393+
image_kit =
394+
Imagekitio::Client.new(
395+
base_url: "http://localhost",
396+
private_key: "My Private Key",
397+
password: "My Password"
398+
)
324399

325400
image_kit.files.upload(file: StringIO.new("Example data"), file_name: "fileName")
326401

test/imagekitio/test_helper.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ class Imagekitio::Test::SingletonClient < Imagekitio::Client
4848
TEST_API_BASE_URL = ENV.fetch("TEST_API_BASE_URL", "http://localhost:4010")
4949

5050
def initialize
51-
super(base_url: Imagekitio::Test::SingletonClient::TEST_API_BASE_URL, private_key: "My Private Key")
51+
super(
52+
base_url: Imagekitio::Test::SingletonClient::TEST_API_BASE_URL,
53+
private_key: "My Private Key",
54+
password: "My Password"
55+
)
5256
end
5357
end
5458

0 commit comments

Comments
 (0)