Skip to content

Commit f736fef

Browse files
committed
refactor: standardize method naming for URL and transformation string generation
1 parent 028871e commit f736fef

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

lib/imagekit/helpers/helper.rb

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Helper
77
#
88
# @param transformations [Array<Imagekit::Models::Transformation>] Array of transformation objects
99
# @return [String] The built URL with transformations
10-
def buildURL(transformations)
10+
def build_url(transformations)
1111
# TODO: Implement actual URL building logic
1212
# For now, return a fixed URL as requested
1313
"https://ik.imagekit.io/your_imagekit_id/sample-image.jpg?tr=w-400,h-300"
@@ -17,23 +17,31 @@ def buildURL(transformations)
1717
#
1818
# @param transformations [Array<Imagekit::Models::Transformation>] Array of transformation objects
1919
# @return [String] The transformation string (e.g., "w-400,h-300")
20-
def buildTransformationString(transformations)
20+
def build_transformation_string(transformations)
2121
# TODO: Implement actual transformation string generation
2222
# For now, return a fixed transformation string
2323
"w-400,h-300"
2424
end
2525

26-
# Gets authentication parameters for ImageKit requests
26+
# Generates authentication parameters for client-side file uploads using ImageKit's Upload API V1.
2727
#
28-
# @param token [String, nil] Optional token for authentication
29-
# @return [Hash] Authentication parameters
30-
def GetAuthenticationParameters(token = nil)
28+
# This method creates the required authentication signature that allows secure file uploads
29+
# directly from the browser or mobile applications without exposing your private API key.
30+
# The generated parameters include a unique token, expiration timestamp, and HMAC signature.
31+
#
32+
# @param token [String, nil] Custom token for the upload session. If not provided, a UUID v4 will be generated automatically.
33+
# @param expire [Integer, nil] Expiration time in seconds from now. If not provided, defaults to 1800 seconds (30 minutes).
34+
# @return [Hash] Authentication parameters object containing:
35+
# - token: Unique identifier for this upload session
36+
# - expire: Unix timestamp when these parameters expire
37+
# - signature: HMAC-SHA1 signature for authenticating the upload
38+
def get_authentication_parameters(token = nil, expire = nil)
3139
# TODO: Implement actual authentication parameter generation
3240
# For now, return a fixed hash
3341
{
34-
signature: "dummy_signature",
35-
expire: Time.now.to_i + 3600,
36-
token: token || "dummy_token"
42+
token: token || "dummy_token",
43+
expire: expire || (Time.now.to_i + 1800),
44+
signature: "dummy_signature"
3745
}
3846
end
3947

rbi/imagekit/helpers/helper.rbi

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,24 @@ module Imagekit
1212
transformations: T::Array[Imagekit::Models::Transformation]
1313
).returns(String)
1414
end
15-
def buildURL(transformations); end
15+
def build_url(transformations); end
1616

1717
# Generates transformation string from transformation objects
1818
sig do
1919
params(
2020
transformations: T::Array[Imagekit::Models::Transformation]
2121
).returns(String)
2222
end
23-
def buildTransformationString(transformations); end
23+
def build_transformation_string(transformations); end
2424

25-
# Gets authentication parameters for ImageKit requests
25+
# Generates authentication parameters for client-side file uploads
2626
sig do
27-
params(token: T.nilable(String)).returns(
28-
T::Hash[Symbol, T.any(String, Integer)]
29-
)
27+
params(
28+
token: T.nilable(String),
29+
expire: T.nilable(Integer)
30+
).returns(T::Hash[Symbol, T.any(String, Integer)])
3031
end
31-
def GetAuthenticationParameters(token = nil); end
32+
def get_authentication_parameters(token = nil, expire = nil); end
3233
end
3334
end
3435
end

sig/imagekit/helpers/helper.rbs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ module Imagekit
44
def initialize: (client: Imagekit::Client) -> void
55

66
# Builds a URL with transformations applied
7-
def buildURL: (Array[Imagekit::Models::Transformation] transformations) -> String
7+
def build_url: (Array[Imagekit::Models::Transformation] transformations) -> String
88

99
# Generates transformation string from transformation objects
10-
def buildTransformationString: (Array[Imagekit::Models::Transformation] transformations) -> String
10+
def build_transformation_string: (Array[Imagekit::Models::Transformation] transformations) -> String
1111

12-
# Gets authentication parameters for ImageKit requests
13-
def GetAuthenticationParameters: (?String? token) -> Hash[Symbol, (String | Integer)]
12+
# Generates authentication parameters for client-side file uploads
13+
def get_authentication_parameters: (?String? token, ?Integer? expire) -> Hash[Symbol, (String | Integer)]
1414
end
1515
end
1616
end

0 commit comments

Comments
 (0)