Skip to content

Commit 56a4db1

Browse files
committed
basic working
1 parent 86d5b43 commit 56a4db1

File tree

10 files changed

+186
-0
lines changed

10 files changed

+186
-0
lines changed

.vscode/extensions.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"recommendations": [
3+
"shopify.ruby-lsp",
4+
"sorbet.sorbet-vscode-extension",
5+
"soutaro.rbs-syntax",
6+
"bradlc.vscode-tailwindcss",
7+
"github.copilot",
8+
"github.copilot-chat"
9+
],
10+
"unwantedRecommendations": [
11+
"rebornix.ruby",
12+
"castwide.solargraph"
13+
]
14+
}

.vscode/settings.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"ruby.interpreter": "ruby",
3+
"ruby.pathToBundler": "bundle",
4+
"ruby.useLanguageServer": true,
5+
"ruby.lint": {
6+
"rubocop": true,
7+
"ruby": true
8+
},
9+
"ruby.format": "rubocop",
10+
"sorbet.enabled": true,
11+
"sorbet.typeCheckingMode": "strict",
12+
"sorbet.watchmanPath": "watchman",
13+
"files.associations": {
14+
"*.rb": "ruby",
15+
"*.rbi": "ruby",
16+
"*.rbs": "rbs",
17+
"Gemfile": "ruby",
18+
"Rakefile": "ruby"
19+
},
20+
"editor.formatOnSave": true,
21+
"editor.codeActionsOnSave": {
22+
"source.fixAll.rubocop": "explicit"
23+
},
24+
"[ruby]": {
25+
"editor.defaultFormatter": "Shopify.ruby-lsp",
26+
"editor.formatOnSave": true,
27+
"editor.tabSize": 2,
28+
"editor.insertSpaces": true,
29+
"editor.semanticHighlighting.enabled": true,
30+
"editor.suggest.insertMode": "replace"
31+
},
32+
"[rbs]": {
33+
"editor.defaultFormatter": "soutaro.rbs-syntax",
34+
"editor.tabSize": 2,
35+
"editor.insertSpaces": true
36+
}
37+
}

examples/test_helper.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
5+
require_relative "../lib/imagekit"
6+
7+
# Create an ImageKit client
8+
image_kit = Imagekit::Client.new(
9+
private_key: "private_test_key_123",
10+
password: "test_password"
11+
)
12+
13+
# Create some sample transformations (they can be empty for now since we're returning a fixed URL)
14+
transformations = [
15+
Imagekit::Models::Transformation.new(
16+
height: 300,
17+
width: 400,
18+
shadow: true
19+
)
20+
]
21+
22+
# Test all helper functions
23+
puts "Testing helper functions:"
24+
puts "1. buildURL: #{image_kit.helpers.buildURL(transformations)}"
25+
puts "2. generateTransformationString: #{image_kit.helpers.generateTransformationString(transformations)}"
26+
puts "3. GetAuthenticationParameters: #{image_kit.helpers.GetAuthenticationParameters}"
27+
puts "All helper functions are working!"

lib/imagekit.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,4 @@
175175
require_relative "imagekit/resources/folders"
176176
require_relative "imagekit/resources/folders/job"
177177
require_relative "imagekit/resources/webhooks"
178+
require_relative "imagekit/helpers/helper"

lib/imagekit/client.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class Client < Imagekit::Internal::Transport::BaseClient
4949
# @return [Imagekit::Resources::Webhooks]
5050
attr_reader :webhooks
5151

52+
# @return [Imagekit::Helpers::Helper]
53+
attr_reader :helpers
54+
5255
# @api private
5356
#
5457
# @return [Hash{String=>String}]
@@ -120,6 +123,7 @@ def initialize(
120123
@accounts = Imagekit::Resources::Accounts.new(client: self)
121124
@beta = Imagekit::Resources::Beta.new(client: self)
122125
@webhooks = Imagekit::Resources::Webhooks.new(client: self)
126+
@helpers = Imagekit::Helpers::Helper.new(client: self)
123127
end
124128
end
125129
end

lib/imagekit/helpers/helper.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# frozen_string_literal: true
2+
3+
module Imagekit
4+
module Helpers
5+
class Helper
6+
# Builds a URL with transformations applied
7+
#
8+
# @param transformations [Array<Imagekit::Models::Transformation>] Array of transformation objects
9+
# @return [String] The built URL with transformations
10+
def buildURL(transformations)
11+
# TODO: Implement actual URL building logic
12+
# For now, return a fixed URL as requested
13+
"https://ik.imagekit.io/your_imagekit_id/sample-image.jpg?tr=w-400,h-300"
14+
end
15+
16+
# Generates transformation string from transformation objects
17+
#
18+
# @param transformations [Array<Imagekit::Models::Transformation>] Array of transformation objects
19+
# @return [String] The transformation string (e.g., "w-400,h-300")
20+
def generateTransformationString(transformations)
21+
# TODO: Implement actual transformation string generation
22+
# For now, return a fixed transformation string
23+
"w-400,h-300"
24+
end
25+
26+
# Gets authentication parameters for ImageKit requests
27+
#
28+
# @param token [String, nil] Optional token for authentication
29+
# @return [Hash] Authentication parameters
30+
def GetAuthenticationParameters(token = nil)
31+
# TODO: Implement actual authentication parameter generation
32+
# For now, return a fixed hash
33+
{
34+
signature: "dummy_signature",
35+
expire: Time.now.to_i + 3600,
36+
token: token || "dummy_token"
37+
}
38+
end
39+
40+
# @api private
41+
#
42+
# @param client [Imagekit::Client]
43+
def initialize(client:)
44+
@client = client
45+
end
46+
end
47+
end
48+
end

rbi/imagekit/client.rbi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ module Imagekit
4444
sig { returns(Imagekit::Resources::Webhooks) }
4545
attr_reader :webhooks
4646

47+
sig { returns(Imagekit::Helpers::Helper) }
48+
attr_reader :helpers
49+
4750
# @api private
4851
sig { override.returns(T::Hash[String, String]) }
4952
private def auth_headers

rbi/imagekit/helpers/helper.rbi

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# typed: strong
2+
3+
module Imagekit
4+
module Helpers
5+
class Helper
6+
sig { params(client: Imagekit::Client).void }
7+
def initialize(client:); end
8+
9+
# Builds a URL with transformations applied
10+
sig do
11+
params(
12+
transformations: T::Array[Imagekit::Models::Transformation]
13+
).returns(String)
14+
end
15+
def buildURL(transformations); end
16+
17+
# Generates transformation string from transformation objects
18+
sig do
19+
params(
20+
transformations: T::Array[Imagekit::Models::Transformation]
21+
).returns(String)
22+
end
23+
def generateTransformationString(transformations); end
24+
25+
# Gets authentication parameters for ImageKit requests
26+
sig do
27+
params(token: T.nilable(String)).returns(
28+
T::Hash[Symbol, T.any(String, Integer)]
29+
)
30+
end
31+
def GetAuthenticationParameters(token = nil); end
32+
end
33+
end
34+
end

sig/imagekit/client.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ module Imagekit
2828

2929
attr_reader webhooks: Imagekit::Resources::Webhooks
3030

31+
attr_reader helpers: Imagekit::Helpers::Helper
32+
3133
private def auth_headers: -> ::Hash[String, String]
3234

3335
def base_url_overridden?: -> bool

sig/imagekit/helpers/helper.rbs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Imagekit
2+
module Helpers
3+
class Helper
4+
def initialize: (client: Imagekit::Client) -> void
5+
6+
# Builds a URL with transformations applied
7+
def buildURL: (Array[Imagekit::Models::Transformation] transformations) -> String
8+
9+
# Generates transformation string from transformation objects
10+
def generateTransformationString: (Array[Imagekit::Models::Transformation] transformations) -> String
11+
12+
# Gets authentication parameters for ImageKit requests
13+
def GetAuthenticationParameters: (?String? token) -> Hash[Symbol, (String | Integer)]
14+
end
15+
end
16+
end

0 commit comments

Comments
 (0)