imagekitio 4.2.0 → 4.3.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 (102) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -0
  3. data/README.md +1 -1
  4. data/lib/imagekitio/client.rb +14 -0
  5. data/lib/imagekitio/helpers/helper.rb +6 -0
  6. data/lib/imagekitio/internal/transport/pooled_net_requester.rb +1 -1
  7. data/lib/imagekitio/internal/util.rb +51 -7
  8. data/lib/imagekitio/models/accounts/origin_create_params.rb +1 -9
  9. data/lib/imagekitio/models/accounts/origin_delete_params.rb +13 -1
  10. data/lib/imagekitio/models/accounts/origin_get_params.rb +13 -1
  11. data/lib/imagekitio/models/accounts/origin_update_params.rb +10 -6
  12. data/lib/imagekitio/models/accounts/url_endpoint_delete_params.rb +14 -1
  13. data/lib/imagekitio/models/accounts/url_endpoint_get_params.rb +14 -1
  14. data/lib/imagekitio/models/accounts/url_endpoint_update_params.rb +14 -1
  15. data/lib/imagekitio/models/cache/invalidation_get_params.rb +7 -1
  16. data/lib/imagekitio/models/custom_metadata_field_delete_params.rb +7 -1
  17. data/lib/imagekitio/models/custom_metadata_field_update_params.rb +8 -1
  18. data/lib/imagekitio/models/extension_config.rb +10 -5
  19. data/lib/imagekitio/models/extensions.rb +10 -5
  20. data/lib/imagekitio/models/file_delete_params.rb +7 -1
  21. data/lib/imagekitio/models/file_get_params.rb +7 -1
  22. data/lib/imagekitio/models/file_update_params.rb +5 -7
  23. data/lib/imagekitio/models/files/metadata_get_params.rb +7 -1
  24. data/lib/imagekitio/models/files/version_delete_params.rb +7 -1
  25. data/lib/imagekitio/models/files/version_get_params.rb +7 -1
  26. data/lib/imagekitio/models/files/version_list_params.rb +7 -1
  27. data/lib/imagekitio/models/files/version_restore_params.rb +7 -1
  28. data/lib/imagekitio/models/folders/job_get_params.rb +7 -1
  29. data/lib/imagekitio/models/overlay_position.rb +99 -5
  30. data/lib/imagekitio/models/saved_extension_delete_params.rb +7 -1
  31. data/lib/imagekitio/models/saved_extension_get_params.rb +7 -1
  32. data/lib/imagekitio/models/saved_extension_update_params.rb +8 -1
  33. data/lib/imagekitio/resources/accounts/origins.rb +4 -14
  34. data/lib/imagekitio/resources/accounts/usage.rb +2 -1
  35. data/lib/imagekitio/resources/assets.rb +2 -1
  36. data/lib/imagekitio/resources/beta/v2/files.rb +5 -4
  37. data/lib/imagekitio/resources/custom_metadata_fields.rb +2 -1
  38. data/lib/imagekitio/resources/files/metadata.rb +2 -1
  39. data/lib/imagekitio/resources/files.rb +7 -11
  40. data/lib/imagekitio/resources/webhooks.rb +11 -1
  41. data/lib/imagekitio/version.rb +1 -1
  42. data/lib/imagekitio.rb +1 -0
  43. data/rbi/imagekitio/client.rbi +13 -0
  44. data/rbi/imagekitio/internal/util.rbi +29 -1
  45. data/rbi/imagekitio/models/accounts/origin_create_params.rbi +4 -51
  46. data/rbi/imagekitio/models/accounts/origin_delete_params.rbi +18 -5
  47. data/rbi/imagekitio/models/accounts/origin_get_params.rbi +18 -5
  48. data/rbi/imagekitio/models/accounts/origin_update_params.rbi +9 -43
  49. data/rbi/imagekitio/models/accounts/url_endpoint_delete_params.rbi +20 -5
  50. data/rbi/imagekitio/models/accounts/url_endpoint_get_params.rbi +20 -5
  51. data/rbi/imagekitio/models/accounts/url_endpoint_update_params.rbi +20 -5
  52. data/rbi/imagekitio/models/cache/invalidation_get_params.rbi +11 -5
  53. data/rbi/imagekitio/models/custom_metadata_field_delete_params.rbi +13 -5
  54. data/rbi/imagekitio/models/custom_metadata_field_update_params.rbi +6 -0
  55. data/rbi/imagekitio/models/extension_config.rbi +16 -6
  56. data/rbi/imagekitio/models/extensions.rbi +16 -6
  57. data/rbi/imagekitio/models/file_delete_params.rbi +13 -5
  58. data/rbi/imagekitio/models/file_get_params.rbi +13 -5
  59. data/rbi/imagekitio/models/file_update_params.rbi +5 -28
  60. data/rbi/imagekitio/models/files/metadata_get_params.rbi +11 -5
  61. data/rbi/imagekitio/models/files/version_delete_params.rbi +10 -2
  62. data/rbi/imagekitio/models/files/version_get_params.rbi +10 -2
  63. data/rbi/imagekitio/models/files/version_list_params.rbi +11 -5
  64. data/rbi/imagekitio/models/files/version_restore_params.rbi +10 -2
  65. data/rbi/imagekitio/models/folders/job_get_params.rbi +11 -5
  66. data/rbi/imagekitio/models/overlay_position.rbi +165 -9
  67. data/rbi/imagekitio/models/saved_extension_delete_params.rbi +13 -5
  68. data/rbi/imagekitio/models/saved_extension_get_params.rbi +13 -5
  69. data/rbi/imagekitio/models/saved_extension_update_params.rbi +6 -0
  70. data/rbi/imagekitio/resources/accounts/origins.rbi +22 -2
  71. data/rbi/imagekitio/resources/beta/v2/files.rbi +5 -4
  72. data/rbi/imagekitio/resources/files.rbi +10 -5
  73. data/rbi/imagekitio/resources/webhooks.rbi +10 -2
  74. data/sig/imagekitio/client.rbs +3 -0
  75. data/sig/imagekitio/internal/util.rbs +14 -0
  76. data/sig/imagekitio/models/accounts/origin_create_params.rbs +3 -16
  77. data/sig/imagekitio/models/accounts/origin_delete_params.rbs +11 -3
  78. data/sig/imagekitio/models/accounts/origin_get_params.rbs +11 -3
  79. data/sig/imagekitio/models/accounts/origin_update_params.rbs +4 -9
  80. data/sig/imagekitio/models/accounts/url_endpoint_delete_params.rbs +11 -3
  81. data/sig/imagekitio/models/accounts/url_endpoint_get_params.rbs +11 -3
  82. data/sig/imagekitio/models/accounts/url_endpoint_update_params.rbs +13 -3
  83. data/sig/imagekitio/models/cache/invalidation_get_params.rbs +11 -3
  84. data/sig/imagekitio/models/custom_metadata_field_delete_params.rbs +11 -3
  85. data/sig/imagekitio/models/custom_metadata_field_update_params.rbs +5 -0
  86. data/sig/imagekitio/models/file_delete_params.rbs +11 -3
  87. data/sig/imagekitio/models/file_get_params.rbs +12 -3
  88. data/sig/imagekitio/models/file_update_params.rbs +4 -9
  89. data/sig/imagekitio/models/files/metadata_get_params.rbs +11 -3
  90. data/sig/imagekitio/models/files/version_delete_params.rbs +6 -1
  91. data/sig/imagekitio/models/files/version_get_params.rbs +6 -1
  92. data/sig/imagekitio/models/files/version_list_params.rbs +11 -3
  93. data/sig/imagekitio/models/files/version_restore_params.rbs +6 -1
  94. data/sig/imagekitio/models/folders/job_get_params.rbs +11 -3
  95. data/sig/imagekitio/models/overlay_position.rbs +73 -3
  96. data/sig/imagekitio/models/saved_extension_delete_params.rbs +11 -3
  97. data/sig/imagekitio/models/saved_extension_get_params.rbs +11 -3
  98. data/sig/imagekitio/models/saved_extension_update_params.rbs +5 -0
  99. data/sig/imagekitio/resources/accounts/origins.rbs +2 -2
  100. data/sig/imagekitio/resources/files.rbs +1 -1
  101. data/sig/imagekitio/resources/webhooks.rbs +3 -1
  102. metadata +16 -2
@@ -13,8 +13,14 @@ module Imagekitio
13
13
  # @return [String]
14
14
  required :file_id, String
15
15
 
16
- # @!method initialize(file_id:, request_options: {})
16
+ # @!attribute version_id
17
+ #
18
+ # @return [String]
19
+ required :version_id, String
20
+
21
+ # @!method initialize(file_id:, version_id:, request_options: {})
17
22
  # @param file_id [String]
23
+ # @param version_id [String]
18
24
  # @param request_options [Imagekitio::RequestOptions, Hash{Symbol=>Object}]
19
25
  end
20
26
  end
@@ -8,7 +8,13 @@ module Imagekitio
8
8
  extend Imagekitio::Internal::Type::RequestParameters::Converter
9
9
  include Imagekitio::Internal::Type::RequestParameters
10
10
 
11
- # @!method initialize(request_options: {})
11
+ # @!attribute file_id
12
+ #
13
+ # @return [String]
14
+ required :file_id, String
15
+
16
+ # @!method initialize(file_id:, request_options: {})
17
+ # @param file_id [String]
12
18
  # @param request_options [Imagekitio::RequestOptions, Hash{Symbol=>Object}]
13
19
  end
14
20
  end
@@ -13,8 +13,14 @@ module Imagekitio
13
13
  # @return [String]
14
14
  required :file_id, String
15
15
 
16
- # @!method initialize(file_id:, request_options: {})
16
+ # @!attribute version_id
17
+ #
18
+ # @return [String]
19
+ required :version_id, String
20
+
21
+ # @!method initialize(file_id:, version_id:, request_options: {})
17
22
  # @param file_id [String]
23
+ # @param version_id [String]
18
24
  # @param request_options [Imagekitio::RequestOptions, Hash{Symbol=>Object}]
19
25
  end
20
26
  end
@@ -8,7 +8,13 @@ module Imagekitio
8
8
  extend Imagekitio::Internal::Type::RequestParameters::Converter
9
9
  include Imagekitio::Internal::Type::RequestParameters
10
10
 
11
- # @!method initialize(request_options: {})
11
+ # @!attribute job_id
12
+ #
13
+ # @return [String]
14
+ required :job_id, String
15
+
16
+ # @!method initialize(job_id:, request_options: {})
17
+ # @param job_id [String]
12
18
  # @param request_options [Imagekitio::RequestOptions, Hash{Symbol=>Object}]
13
19
  end
14
20
  end
@@ -3,9 +3,18 @@
3
3
  module Imagekitio
4
4
  module Models
5
5
  class OverlayPosition < Imagekitio::Internal::Type::BaseModel
6
+ # @!attribute anchor_point
7
+ # Sets the anchor point on the base asset from which the overlay offset is
8
+ # calculated. The default value is `top_left`. Maps to `lap` in the URL. Can only
9
+ # be used with one or more of `x`, `y`, `xCenter`, or `yCenter`.
10
+ #
11
+ # @return [Symbol, Imagekitio::Models::OverlayPosition::AnchorPoint, nil]
12
+ optional :anchor_point, enum: -> { Imagekitio::OverlayPosition::AnchorPoint }, api_name: :anchorPoint
13
+
6
14
  # @!attribute focus
7
- # Specifies the position of the overlay relative to the parent image or video.
8
- # Maps to `lfo` in the URL.
15
+ # Specifies the position of the overlay relative to the parent image or video. If
16
+ # one or more of `x`, `y`, `xCenter`, or `yCenter` parameters are specified, this
17
+ # parameter is ignored. Maps to `lfo` in the URL.
9
18
  #
10
19
  # @return [Symbol, Imagekitio::Models::OverlayPosition::Focus, nil]
11
20
  optional :focus, enum: -> { Imagekitio::OverlayPosition::Focus }
@@ -20,6 +29,16 @@ module Imagekitio
20
29
  # @return [Float, String, nil]
21
30
  optional :x, union: -> { Imagekitio::OverlayPosition::X }
22
31
 
32
+ # @!attribute x_center
33
+ # Specifies the x-coordinate on the base asset where the overlay's center will be
34
+ # positioned. It also accepts arithmetic expressions such as `bw_mul_0.4` or
35
+ # `bw_sub_cw`. Maps to `lxc` in the URL. Cannot be used together with `x`, but can
36
+ # be used with `y`. Learn about
37
+ # [Arithmetic expressions](https://imagekit.io/docs/arithmetic-expressions-in-transformations).
38
+ #
39
+ # @return [Float, String, nil]
40
+ optional :x_center, union: -> { Imagekitio::OverlayPosition::XCenter }, api_name: :xCenter
41
+
23
42
  # @!attribute y_
24
43
  # Specifies the y-coordinate of the top-left corner of the base asset where the
25
44
  # overlay's top-left corner will be positioned. It also accepts arithmetic
@@ -30,18 +49,57 @@ module Imagekitio
30
49
  # @return [Float, String, nil]
31
50
  optional :y_, union: -> { Imagekitio::OverlayPosition::Y }, api_name: :y
32
51
 
33
- # @!method initialize(focus: nil, x: nil, y_: nil)
52
+ # @!attribute y_center
53
+ # Specifies the y-coordinate on the base asset where the overlay's center will be
54
+ # positioned. It also accepts arithmetic expressions such as `bh_mul_0.4` or
55
+ # `bh_sub_ch`. Maps to `lyc` in the URL. Cannot be used together with `y`, but can
56
+ # be used with `x`. Learn about
57
+ # [Arithmetic expressions](https://imagekit.io/docs/arithmetic-expressions-in-transformations).
58
+ #
59
+ # @return [Float, String, nil]
60
+ optional :y_center, union: -> { Imagekitio::OverlayPosition::YCenter }, api_name: :yCenter
61
+
62
+ # @!method initialize(anchor_point: nil, focus: nil, x: nil, x_center: nil, y_: nil, y_center: nil)
34
63
  # Some parameter documentations has been truncated, see
35
64
  # {Imagekitio::Models::OverlayPosition} for more details.
36
65
  #
66
+ # @param anchor_point [Symbol, Imagekitio::Models::OverlayPosition::AnchorPoint] Sets the anchor point on the base asset from which the overlay offset is calcula
67
+ #
37
68
  # @param focus [Symbol, Imagekitio::Models::OverlayPosition::Focus] Specifies the position of the overlay relative to the parent image or video.
38
69
  #
39
70
  # @param x [Float, String] Specifies the x-coordinate of the top-left corner of the base asset where the ov
40
71
  #
72
+ # @param x_center [Float, String] Specifies the x-coordinate on the base asset where the overlay's center will be
73
+ #
41
74
  # @param y_ [Float, String] Specifies the y-coordinate of the top-left corner of the base asset where the ov
75
+ #
76
+ # @param y_center [Float, String] Specifies the y-coordinate on the base asset where the overlay's center will be
77
+
78
+ # Sets the anchor point on the base asset from which the overlay offset is
79
+ # calculated. The default value is `top_left`. Maps to `lap` in the URL. Can only
80
+ # be used with one or more of `x`, `y`, `xCenter`, or `yCenter`.
81
+ #
82
+ # @see Imagekitio::Models::OverlayPosition#anchor_point
83
+ module AnchorPoint
84
+ extend Imagekitio::Internal::Type::Enum
85
+
86
+ TOP = :top
87
+ LEFT = :left
88
+ RIGHT = :right
89
+ BOTTOM = :bottom
90
+ TOP_LEFT = :top_left
91
+ TOP_RIGHT = :top_right
92
+ BOTTOM_LEFT = :bottom_left
93
+ BOTTOM_RIGHT = :bottom_right
94
+ CENTER = :center
95
+
96
+ # @!method self.values
97
+ # @return [Array<Symbol>]
98
+ end
42
99
 
43
- # Specifies the position of the overlay relative to the parent image or video.
44
- # Maps to `lfo` in the URL.
100
+ # Specifies the position of the overlay relative to the parent image or video. If
101
+ # one or more of `x`, `y`, `xCenter`, or `yCenter` parameters are specified, this
102
+ # parameter is ignored. Maps to `lfo` in the URL.
45
103
  #
46
104
  # @see Imagekitio::Models::OverlayPosition#focus
47
105
  module Focus
@@ -79,6 +137,24 @@ module Imagekitio
79
137
  # @return [Array(Float, String)]
80
138
  end
81
139
 
140
+ # Specifies the x-coordinate on the base asset where the overlay's center will be
141
+ # positioned. It also accepts arithmetic expressions such as `bw_mul_0.4` or
142
+ # `bw_sub_cw`. Maps to `lxc` in the URL. Cannot be used together with `x`, but can
143
+ # be used with `y`. Learn about
144
+ # [Arithmetic expressions](https://imagekit.io/docs/arithmetic-expressions-in-transformations).
145
+ #
146
+ # @see Imagekitio::Models::OverlayPosition#x_center
147
+ module XCenter
148
+ extend Imagekitio::Internal::Type::Union
149
+
150
+ variant Float
151
+
152
+ variant String
153
+
154
+ # @!method self.variants
155
+ # @return [Array(Float, String)]
156
+ end
157
+
82
158
  # Specifies the y-coordinate of the top-left corner of the base asset where the
83
159
  # overlay's top-left corner will be positioned. It also accepts arithmetic
84
160
  # expressions such as `bh_mul_0.4` or `bh_sub_ch`. Maps to `ly` in the URL. Learn
@@ -96,6 +172,24 @@ module Imagekitio
96
172
  # @!method self.variants
97
173
  # @return [Array(Float, String)]
98
174
  end
175
+
176
+ # Specifies the y-coordinate on the base asset where the overlay's center will be
177
+ # positioned. It also accepts arithmetic expressions such as `bh_mul_0.4` or
178
+ # `bh_sub_ch`. Maps to `lyc` in the URL. Cannot be used together with `y`, but can
179
+ # be used with `x`. Learn about
180
+ # [Arithmetic expressions](https://imagekit.io/docs/arithmetic-expressions-in-transformations).
181
+ #
182
+ # @see Imagekitio::Models::OverlayPosition#y_center
183
+ module YCenter
184
+ extend Imagekitio::Internal::Type::Union
185
+
186
+ variant Float
187
+
188
+ variant String
189
+
190
+ # @!method self.variants
191
+ # @return [Array(Float, String)]
192
+ end
99
193
  end
100
194
  end
101
195
  end
@@ -7,7 +7,13 @@ module Imagekitio
7
7
  extend Imagekitio::Internal::Type::RequestParameters::Converter
8
8
  include Imagekitio::Internal::Type::RequestParameters
9
9
 
10
- # @!method initialize(request_options: {})
10
+ # @!attribute id
11
+ #
12
+ # @return [String]
13
+ required :id, String
14
+
15
+ # @!method initialize(id:, request_options: {})
16
+ # @param id [String]
11
17
  # @param request_options [Imagekitio::RequestOptions, Hash{Symbol=>Object}]
12
18
  end
13
19
  end
@@ -7,7 +7,13 @@ module Imagekitio
7
7
  extend Imagekitio::Internal::Type::RequestParameters::Converter
8
8
  include Imagekitio::Internal::Type::RequestParameters
9
9
 
10
- # @!method initialize(request_options: {})
10
+ # @!attribute id
11
+ #
12
+ # @return [String]
13
+ required :id, String
14
+
15
+ # @!method initialize(id:, request_options: {})
16
+ # @param id [String]
11
17
  # @param request_options [Imagekitio::RequestOptions, Hash{Symbol=>Object}]
12
18
  end
13
19
  end
@@ -7,6 +7,11 @@ module Imagekitio
7
7
  extend Imagekitio::Internal::Type::RequestParameters::Converter
8
8
  include Imagekitio::Internal::Type::RequestParameters
9
9
 
10
+ # @!attribute id
11
+ #
12
+ # @return [String]
13
+ required :id, String
14
+
10
15
  # @!attribute config
11
16
  # Configuration object for an extension (base extensions only, not saved extension
12
17
  # references).
@@ -26,10 +31,12 @@ module Imagekitio
26
31
  # @return [String, nil]
27
32
  optional :name, String
28
33
 
29
- # @!method initialize(config: nil, description: nil, name: nil, request_options: {})
34
+ # @!method initialize(id:, config: nil, description: nil, name: nil, request_options: {})
30
35
  # Some parameter documentations has been truncated, see
31
36
  # {Imagekitio::Models::SavedExtensionUpdateParams} for more details.
32
37
  #
38
+ # @param id [String]
39
+ #
33
40
  # @param config [Imagekitio::Models::ExtensionConfig::RemoveBg, Imagekitio::Models::ExtensionConfig::AIAutoDescription, Imagekitio::Models::ExtensionConfig::AITasks, Imagekitio::Models::ExtensionConfig::AutoTaggingExtension] Configuration object for an extension (base extensions only, not saved extension
34
41
  #
35
42
  # @param description [String] Updated description of the saved extension.
@@ -9,7 +9,7 @@ module Imagekitio
9
9
  #
10
10
  # @overload create(origin_request:, request_options: {})
11
11
  #
12
- # @param origin_request [Imagekitio::Accounts::OriginRequest] Schema for origin request resources.
12
+ # @param origin_request [Imagekitio::Models::Accounts::OriginRequest::S3, Imagekitio::Models::Accounts::OriginRequest::S3Compatible, Imagekitio::Models::Accounts::OriginRequest::CloudinaryBackup, Imagekitio::Models::Accounts::OriginRequest::WebFolder, Imagekitio::Models::Accounts::OriginRequest::WebProxy, Imagekitio::Models::Accounts::OriginRequest::Gcs, Imagekitio::Models::Accounts::OriginRequest::AzureBlob, Imagekitio::Models::Accounts::OriginRequest::AkeneoPim] Schema for origin request resources.
13
13
  #
14
14
  # @param request_options [Imagekitio::RequestOptions, Hash{Symbol=>Object}, nil]
15
15
  #
@@ -18,15 +18,10 @@ module Imagekitio
18
18
  # @see Imagekitio::Models::Accounts::OriginCreateParams
19
19
  def create(params)
20
20
  parsed, options = Imagekitio::Accounts::OriginCreateParams.dump_request(params)
21
- case parsed
22
- in {origin_request: Hash => union, **rest}
23
- parsed = {**rest, **union}
24
- else
25
- end
26
21
  @client.request(
27
22
  method: :post,
28
23
  path: "v1/accounts/origins",
29
- body: parsed,
24
+ body: parsed[:origin_request],
30
25
  model: Imagekitio::Accounts::OriginResponse,
31
26
  options: options
32
27
  )
@@ -42,7 +37,7 @@ module Imagekitio
42
37
  #
43
38
  # @param id [String] Unique identifier for the origin. This is generated by ImageKit when you create
44
39
  #
45
- # @param origin_request [Imagekitio::Accounts::OriginRequest] Schema for origin request resources.
40
+ # @param origin_request [Imagekitio::Models::Accounts::OriginRequest::S3, Imagekitio::Models::Accounts::OriginRequest::S3Compatible, Imagekitio::Models::Accounts::OriginRequest::CloudinaryBackup, Imagekitio::Models::Accounts::OriginRequest::WebFolder, Imagekitio::Models::Accounts::OriginRequest::WebProxy, Imagekitio::Models::Accounts::OriginRequest::Gcs, Imagekitio::Models::Accounts::OriginRequest::AzureBlob, Imagekitio::Models::Accounts::OriginRequest::AkeneoPim] Schema for origin request resources.
46
41
  #
47
42
  # @param request_options [Imagekitio::RequestOptions, Hash{Symbol=>Object}, nil]
48
43
  #
@@ -51,15 +46,10 @@ module Imagekitio
51
46
  # @see Imagekitio::Models::Accounts::OriginUpdateParams
52
47
  def update(id, params)
53
48
  parsed, options = Imagekitio::Accounts::OriginUpdateParams.dump_request(params)
54
- case parsed
55
- in {origin_request: Hash => union, **rest}
56
- parsed = {**rest, **union}
57
- else
58
- end
59
49
  @client.request(
60
50
  method: :put,
61
51
  path: ["v1/accounts/origins/%1$s", id],
62
- body: parsed,
52
+ body: parsed[:origin_request],
63
53
  model: Imagekitio::Accounts::OriginResponse,
64
54
  options: options
65
55
  )
@@ -25,10 +25,11 @@ module Imagekitio
25
25
  # @see Imagekitio::Models::Accounts::UsageGetParams
26
26
  def get(params)
27
27
  parsed, options = Imagekitio::Accounts::UsageGetParams.dump_request(params)
28
+ query = Imagekitio::Internal::Util.encode_query_params(parsed)
28
29
  @client.request(
29
30
  method: :get,
30
31
  path: "v1/accounts/usage",
31
- query: parsed.transform_keys(end_date: "endDate", start_date: "startDate"),
32
+ query: query.transform_keys(end_date: "endDate", start_date: "startDate"),
32
33
  model: Imagekitio::Models::Accounts::UsageGetResponse,
33
34
  options: options
34
35
  )
@@ -34,10 +34,11 @@ module Imagekitio
34
34
  # @see Imagekitio::Models::AssetListParams
35
35
  def list(params = {})
36
36
  parsed, options = Imagekitio::AssetListParams.dump_request(params)
37
+ query = Imagekitio::Internal::Util.encode_query_params(parsed)
37
38
  @client.request(
38
39
  method: :get,
39
40
  path: "v1/files",
40
- query: parsed.transform_keys(file_type: "fileType", search_query: "searchQuery"),
41
+ query: query.transform_keys(file_type: "fileType", search_query: "searchQuery"),
41
42
  model: Imagekitio::Internal::Type::ArrayOf[union: Imagekitio::Models::AssetListResponseItem],
42
43
  options: options
43
44
  )
@@ -19,10 +19,11 @@ module Imagekitio
19
19
  # about how to implement secure client-side file upload.
20
20
  #
21
21
  # **File size limit** \
22
- # On the free plan, the maximum upload file sizes are 20MB for images, audio, and raw
23
- # files, and 100MB for videos. On the paid plan, these limits increase to 40MB for
24
- # images, audio, and raw files, and 2GB for videos. These limits can be further increased
25
- # with higher-tier plans.
22
+ # On the free plan, the maximum upload file sizes are 25MB for images, audio, and raw
23
+ # files, and 100MB for videos. On the Lite paid plan, these limits increase to 40MB
24
+ # for images, audio, and raw files and 300MB for videos, whereas on the Pro paid plan,
25
+ # these limits increase to 50MB for images, audio, and raw files and 2GB for videos.
26
+ # These limits can be further increased with enterprise plans.
26
27
  #
27
28
  # **Version limit** \
28
29
  # A file can have a maximum of 100 versions.
@@ -89,10 +89,11 @@ module Imagekitio
89
89
  # @see Imagekitio::Models::CustomMetadataFieldListParams
90
90
  def list(params = {})
91
91
  parsed, options = Imagekitio::CustomMetadataFieldListParams.dump_request(params)
92
+ query = Imagekitio::Internal::Util.encode_query_params(parsed)
92
93
  @client.request(
93
94
  method: :get,
94
95
  path: "v1/customMetadataFields",
95
- query: parsed.transform_keys(folder_path: "folderPath", include_deleted: "includeDeleted"),
96
+ query: query.transform_keys(folder_path: "folderPath", include_deleted: "includeDeleted"),
96
97
  model: Imagekitio::Internal::Type::ArrayOf[Imagekitio::CustomMetadataField],
97
98
  options: options
98
99
  )
@@ -48,10 +48,11 @@ module Imagekitio
48
48
  # @see Imagekitio::Models::Files::MetadataGetFromURLParams
49
49
  def get_from_url(params)
50
50
  parsed, options = Imagekitio::Files::MetadataGetFromURLParams.dump_request(params)
51
+ query = Imagekitio::Internal::Util.encode_query_params(parsed)
51
52
  @client.request(
52
53
  method: :get,
53
54
  path: "v1/metadata",
54
- query: parsed,
55
+ query: query,
55
56
  model: Imagekitio::Metadata,
56
57
  options: options
57
58
  )
@@ -23,7 +23,7 @@ module Imagekitio
23
23
  #
24
24
  # @param file_id [String] The unique `fileId` of the uploaded file. `fileId` is returned in list and searc
25
25
  #
26
- # @param update_file_request [Imagekitio::UpdateFileRequest] Schema for update file update request.
26
+ # @param update_file_request [Imagekitio::Models::UpdateFileRequest::UpdateFileDetails, Imagekitio::Models::UpdateFileRequest::ChangePublicationStatus] Schema for update file update request.
27
27
  #
28
28
  # @param request_options [Imagekitio::RequestOptions, Hash{Symbol=>Object}, nil]
29
29
  #
@@ -32,15 +32,10 @@ module Imagekitio
32
32
  # @see Imagekitio::Models::FileUpdateParams
33
33
  def update(file_id, params)
34
34
  parsed, options = Imagekitio::FileUpdateParams.dump_request(params)
35
- case parsed
36
- in {update_file_request: Hash => union, **rest}
37
- parsed = {**rest, **union}
38
- else
39
- end
40
35
  @client.request(
41
36
  method: :patch,
42
37
  path: ["v1/files/%1$s/details", file_id],
43
- body: parsed,
38
+ body: parsed[:update_file_request],
44
39
  model: Imagekitio::Models::FileUpdateResponse,
45
40
  options: options
46
41
  )
@@ -207,10 +202,11 @@ module Imagekitio
207
202
  # by verifying the entire payload using JWT.
208
203
  #
209
204
  # **File size limit** \
210
- # On the free plan, the maximum upload file sizes are 20MB for images, audio, and raw
211
- # files and 100MB for videos. On the paid plan, these limits increase to 40MB for images,
212
- # audio, and raw files and 2GB for videos. These limits can be further increased with
213
- # higher-tier plans.
205
+ # On the free plan, the maximum upload file sizes are 25MB for images, audio, and raw
206
+ # files and 100MB for videos. On the Lite paid plan, these limits increase to 40MB
207
+ # for images, audio, and raw files and 300MB for videos, whereas on the Pro paid plan,
208
+ # these limits increase to 50MB for images, audio, and raw files and 2GB for videos.
209
+ # These limits can be further increased with enterprise plans.
214
210
  #
215
211
  # **Version limit** \
216
212
  # A file can have a maximum of 100 versions.
@@ -13,8 +13,18 @@ module Imagekitio
13
13
 
14
14
  # @param payload [String] The raw webhook payload as a string
15
15
  #
16
+ # @param headers [Hash{String=>String}] The raw HTTP headers that came with the payload
17
+ #
18
+ # @param key [String, nil] The webhook signing key
19
+ #
16
20
  # @return [Imagekitio::Models::VideoTransformationAcceptedEvent, Imagekitio::Models::VideoTransformationReadyEvent, Imagekitio::Models::VideoTransformationErrorEvent, Imagekitio::Models::UploadPreTransformSuccessEvent, Imagekitio::Models::UploadPreTransformErrorEvent, Imagekitio::Models::UploadPostTransformSuccessEvent, Imagekitio::Models::UploadPostTransformErrorEvent]
17
- def unwrap(payload)
21
+ def unwrap(payload, headers:, key: @client.webhook_secret)
22
+ if key.nil?
23
+ raise ArgumentError.new("Cannot verify a webhook without a key on either the client's webhook_secret or passed in as an argument")
24
+ end
25
+
26
+ ::StandardWebhooks::Webhook.new(key).verify(payload, headers)
27
+
18
28
  parsed = JSON.parse(payload, symbolize_names: true)
19
29
  Imagekitio::Internal::Type::Converter.coerce(Imagekitio::Models::UnwrapWebhookEvent, parsed)
20
30
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Imagekitio
4
- VERSION = "4.2.0"
4
+ VERSION = "4.3.0"
5
5
  end
data/lib/imagekitio.rb CHANGED
@@ -30,6 +30,7 @@ end
30
30
 
31
31
  # Gems.
32
32
  require "connection_pool"
33
+ require "standardwebhooks"
33
34
 
34
35
  # Package files.
35
36
  require_relative "imagekitio/version"
@@ -20,6 +20,13 @@ module Imagekitio
20
20
  sig { returns(T.nilable(String)) }
21
21
  attr_reader :password
22
22
 
23
+ # Your ImageKit webhook secret for verifying webhook signatures (starts with
24
+ # `whsec_`). You can find this in the
25
+ # [ImageKit dashboard](https://imagekit.io/dashboard/developer/webhooks). Only
26
+ # required if you're using webhooks.
27
+ sig { returns(T.nilable(String)) }
28
+ attr_reader :webhook_secret
29
+
23
30
  sig { returns(Imagekitio::Resources::CustomMetadataFields) }
24
31
  attr_reader :custom_metadata_fields
25
32
 
@@ -65,6 +72,7 @@ module Imagekitio
65
72
  params(
66
73
  private_key: T.nilable(String),
67
74
  password: T.nilable(String),
75
+ webhook_secret: T.nilable(String),
68
76
  base_url: T.nilable(String),
69
77
  max_retries: Integer,
70
78
  timeout: Float,
@@ -81,6 +89,11 @@ module Imagekitio
81
89
  # dummy value. You can ignore this field. Defaults to
82
90
  # `ENV["OPTIONAL_IMAGEKIT_IGNORES_THIS"]`
83
91
  password: ENV.fetch("OPTIONAL_IMAGEKIT_IGNORES_THIS", "do_not_set"),
92
+ # Your ImageKit webhook secret for verifying webhook signatures (starts with
93
+ # `whsec_`). You can find this in the
94
+ # [ImageKit dashboard](https://imagekit.io/dashboard/developer/webhooks). Only
95
+ # required if you're using webhooks. Defaults to `ENV["IMAGEKIT_WEBHOOK_SECRET"]`
96
+ webhook_secret: ENV["IMAGEKIT_WEBHOOK_SECRET"],
84
97
  # Override the default base URL for the API, e.g.,
85
98
  # `"https://api.example.com/v2/"`. Defaults to `ENV["IMAGE_KIT_BASE_URL"]`
86
99
  base_url: ENV["IMAGE_KIT_BASE_URL"],
@@ -148,12 +148,20 @@ module Imagekitio
148
148
  end
149
149
  end
150
150
 
151
+ # https://www.rfc-editor.org/rfc/rfc3986.html#section-3.3
152
+ RFC_3986_NOT_PCHARS = T.let(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/, Regexp)
153
+
151
154
  class << self
152
155
  # @api private
153
156
  sig { params(uri: URI::Generic).returns(String) }
154
157
  def uri_origin(uri)
155
158
  end
156
159
 
160
+ # @api private
161
+ sig { params(path: T.any(String, Integer)).returns(String) }
162
+ def encode_path(path)
163
+ end
164
+
157
165
  # @api private
158
166
  sig { params(path: T.any(String, T::Array[String])).returns(String) }
159
167
  def interpolate_path(path)
@@ -296,11 +304,31 @@ module Imagekitio
296
304
  end
297
305
 
298
306
  JSON_CONTENT =
299
- T.let(%r{^application/(?:vnd(?:\.[^.]+)*\+)?json(?!l)}, Regexp)
307
+ T.let(%r{^application/(?:[a-zA-Z0-9.-]+\+)?json(?!l)}, Regexp)
300
308
  JSONL_CONTENT =
301
309
  T.let(%r{^application/(:?x-(?:n|l)djson)|(:?(?:x-)?jsonl)}, Regexp)
302
310
 
303
311
  class << self
312
+ # @api private
313
+ sig do
314
+ params(query: Imagekitio::Internal::AnyHash).returns(
315
+ Imagekitio::Internal::AnyHash
316
+ )
317
+ end
318
+ def encode_query_params(query)
319
+ end
320
+
321
+ # @api private
322
+ sig do
323
+ params(
324
+ collection: Imagekitio::Internal::AnyHash,
325
+ key: String,
326
+ element: T.anything
327
+ ).void
328
+ end
329
+ private def write_query_param_element!(collection, key, element)
330
+ end
331
+
304
332
  # @api private
305
333
  sig do
306
334
  params(
@@ -15,63 +15,16 @@ module Imagekitio
15
15
  )
16
16
  end
17
17
 
18
- # Schema for origin request resources.
19
18
  sig do
20
- returns(
21
- T.any(
22
- Imagekitio::Accounts::OriginRequest::S3,
23
- Imagekitio::Accounts::OriginRequest::S3Compatible,
24
- Imagekitio::Accounts::OriginRequest::CloudinaryBackup,
25
- Imagekitio::Accounts::OriginRequest::WebFolder,
26
- Imagekitio::Accounts::OriginRequest::WebProxy,
27
- Imagekitio::Accounts::OriginRequest::Gcs,
28
- Imagekitio::Accounts::OriginRequest::AzureBlob,
29
- Imagekitio::Accounts::OriginRequest::AkeneoPim
30
- )
19
+ params(request_options: Imagekitio::RequestOptions::OrHash).returns(
20
+ T.attached_class
31
21
  )
32
22
  end
33
- attr_accessor :origin_request
34
-
35
- sig do
36
- params(
37
- origin_request:
38
- T.any(
39
- Imagekitio::Accounts::OriginRequest::S3::OrHash,
40
- Imagekitio::Accounts::OriginRequest::S3Compatible::OrHash,
41
- Imagekitio::Accounts::OriginRequest::CloudinaryBackup::OrHash,
42
- Imagekitio::Accounts::OriginRequest::WebFolder::OrHash,
43
- Imagekitio::Accounts::OriginRequest::WebProxy::OrHash,
44
- Imagekitio::Accounts::OriginRequest::Gcs::OrHash,
45
- Imagekitio::Accounts::OriginRequest::AzureBlob::OrHash,
46
- Imagekitio::Accounts::OriginRequest::AkeneoPim::OrHash
47
- ),
48
- request_options: Imagekitio::RequestOptions::OrHash
49
- ).returns(T.attached_class)
50
- end
51
- def self.new(
52
- # Schema for origin request resources.
53
- origin_request:,
54
- request_options: {}
55
- )
23
+ def self.new(request_options: {})
56
24
  end
57
25
 
58
26
  sig do
59
- override.returns(
60
- {
61
- origin_request:
62
- T.any(
63
- Imagekitio::Accounts::OriginRequest::S3,
64
- Imagekitio::Accounts::OriginRequest::S3Compatible,
65
- Imagekitio::Accounts::OriginRequest::CloudinaryBackup,
66
- Imagekitio::Accounts::OriginRequest::WebFolder,
67
- Imagekitio::Accounts::OriginRequest::WebProxy,
68
- Imagekitio::Accounts::OriginRequest::Gcs,
69
- Imagekitio::Accounts::OriginRequest::AzureBlob,
70
- Imagekitio::Accounts::OriginRequest::AkeneoPim
71
- ),
72
- request_options: Imagekitio::RequestOptions
73
- }
74
- )
27
+ override.returns({ request_options: Imagekitio::RequestOptions })
75
28
  end
76
29
  def to_hash
77
30
  end