imagekitio 3.1.0 → 4.0.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 (483) hide show
  1. checksums.yaml +4 -4
  2. data/.ignore +2 -0
  3. data/CHANGELOG.md +116 -0
  4. data/README.md +534 -705
  5. data/SECURITY.md +27 -0
  6. data/lib/imagekitio/client.rb +122 -195
  7. data/lib/imagekitio/errors.rb +226 -2
  8. data/lib/imagekitio/file_part.rb +58 -0
  9. data/lib/imagekitio/helpers/crypto_utils.rb +25 -0
  10. data/lib/imagekitio/helpers/helper.rb +689 -0
  11. data/lib/imagekitio/helpers/transformation_utils.rb +164 -0
  12. data/lib/imagekitio/helpers/uuid_utils.rb +18 -0
  13. data/lib/imagekitio/internal/transport/base_client.rb +567 -0
  14. data/lib/imagekitio/internal/transport/pooled_net_requester.rb +217 -0
  15. data/lib/imagekitio/internal/type/array_of.rb +168 -0
  16. data/lib/imagekitio/internal/type/base_model.rb +530 -0
  17. data/lib/imagekitio/internal/type/base_page.rb +55 -0
  18. data/lib/imagekitio/internal/type/boolean.rb +77 -0
  19. data/lib/imagekitio/internal/type/converter.rb +327 -0
  20. data/lib/imagekitio/internal/type/enum.rb +156 -0
  21. data/lib/imagekitio/internal/type/file_input.rb +111 -0
  22. data/lib/imagekitio/internal/type/hash_of.rb +188 -0
  23. data/lib/imagekitio/internal/type/request_parameters.rb +42 -0
  24. data/lib/imagekitio/internal/type/union.rb +250 -0
  25. data/lib/imagekitio/internal/type/unknown.rb +81 -0
  26. data/lib/imagekitio/internal/util.rb +915 -0
  27. data/lib/imagekitio/internal.rb +20 -0
  28. data/lib/imagekitio/models/accounts/origin_create_params.rb +24 -0
  29. data/lib/imagekitio/models/accounts/origin_delete_params.rb +16 -0
  30. data/lib/imagekitio/models/accounts/origin_get_params.rb +16 -0
  31. data/lib/imagekitio/models/accounts/origin_list_params.rb +16 -0
  32. data/lib/imagekitio/models/accounts/origin_list_response.rb +11 -0
  33. data/lib/imagekitio/models/accounts/origin_request.rb +547 -0
  34. data/lib/imagekitio/models/accounts/origin_response.rb +568 -0
  35. data/lib/imagekitio/models/accounts/origin_update_params.rb +24 -0
  36. data/lib/imagekitio/models/accounts/url_endpoint_create_params.rb +16 -0
  37. data/lib/imagekitio/models/accounts/url_endpoint_delete_params.rb +16 -0
  38. data/lib/imagekitio/models/accounts/url_endpoint_get_params.rb +16 -0
  39. data/lib/imagekitio/models/accounts/url_endpoint_list_params.rb +16 -0
  40. data/lib/imagekitio/models/accounts/url_endpoint_list_response.rb +11 -0
  41. data/lib/imagekitio/models/accounts/url_endpoint_request.rb +110 -0
  42. data/lib/imagekitio/models/accounts/url_endpoint_response.rb +123 -0
  43. data/lib/imagekitio/models/accounts/url_endpoint_update_params.rb +16 -0
  44. data/lib/imagekitio/models/accounts/usage_get_params.rb +37 -0
  45. data/lib/imagekitio/models/accounts/usage_get_response.rb +51 -0
  46. data/lib/imagekitio/models/asset_list_params.rb +158 -0
  47. data/lib/imagekitio/models/asset_list_response.rb +24 -0
  48. data/lib/imagekitio/models/base_overlay.rb +21 -0
  49. data/lib/imagekitio/models/base_webhook_event.rb +24 -0
  50. data/lib/imagekitio/models/beta/v2/file_upload_params.rb +510 -0
  51. data/lib/imagekitio/models/beta/v2/file_upload_response.rb +618 -0
  52. data/lib/imagekitio/models/cache/invalidation_create_params.rb +27 -0
  53. data/lib/imagekitio/models/cache/invalidation_create_response.rb +23 -0
  54. data/lib/imagekitio/models/cache/invalidation_get_params.rb +16 -0
  55. data/lib/imagekitio/models/cache/invalidation_get_response.rb +35 -0
  56. data/lib/imagekitio/models/custom_metadata_field.rb +243 -0
  57. data/lib/imagekitio/models/custom_metadata_field_create_params.rb +238 -0
  58. data/lib/imagekitio/models/custom_metadata_field_delete_params.rb +14 -0
  59. data/lib/imagekitio/models/custom_metadata_field_delete_response.rb +10 -0
  60. data/lib/imagekitio/models/custom_metadata_field_list_params.rb +36 -0
  61. data/lib/imagekitio/models/custom_metadata_field_list_response.rb +9 -0
  62. data/lib/imagekitio/models/custom_metadata_field_update_params.rb +212 -0
  63. data/lib/imagekitio/models/extensions.rb +136 -0
  64. data/lib/imagekitio/models/file.rb +497 -0
  65. data/lib/imagekitio/models/file_copy_params.rb +43 -0
  66. data/lib/imagekitio/models/file_copy_response.rb +10 -0
  67. data/lib/imagekitio/models/file_delete_params.rb +14 -0
  68. data/lib/imagekitio/models/file_get_params.rb +14 -0
  69. data/lib/imagekitio/models/file_move_params.rb +33 -0
  70. data/lib/imagekitio/models/file_move_response.rb +10 -0
  71. data/lib/imagekitio/models/file_rename_params.rb +61 -0
  72. data/lib/imagekitio/models/file_rename_response.rb +21 -0
  73. data/lib/imagekitio/models/file_update_params.rb +22 -0
  74. data/lib/imagekitio/models/file_update_response.rb +104 -0
  75. data/lib/imagekitio/models/file_upload_params.rb +540 -0
  76. data/lib/imagekitio/models/file_upload_response.rb +611 -0
  77. data/lib/imagekitio/models/files/bulk_add_tags_params.rb +35 -0
  78. data/lib/imagekitio/models/files/bulk_add_tags_response.rb +24 -0
  79. data/lib/imagekitio/models/files/bulk_delete_params.rb +27 -0
  80. data/lib/imagekitio/models/files/bulk_delete_response.rb +24 -0
  81. data/lib/imagekitio/models/files/bulk_remove_ai_tags_params.rb +35 -0
  82. data/lib/imagekitio/models/files/bulk_remove_ai_tags_response.rb +24 -0
  83. data/lib/imagekitio/models/files/bulk_remove_tags_params.rb +35 -0
  84. data/lib/imagekitio/models/files/bulk_remove_tags_response.rb +24 -0
  85. data/lib/imagekitio/models/files/metadata_get_from_url_params.rb +28 -0
  86. data/lib/imagekitio/models/files/metadata_get_params.rb +16 -0
  87. data/lib/imagekitio/models/files/version_delete_params.rb +22 -0
  88. data/lib/imagekitio/models/files/version_delete_response.rb +12 -0
  89. data/lib/imagekitio/models/files/version_get_params.rb +22 -0
  90. data/lib/imagekitio/models/files/version_list_params.rb +16 -0
  91. data/lib/imagekitio/models/files/version_list_response.rb +10 -0
  92. data/lib/imagekitio/models/files/version_restore_params.rb +22 -0
  93. data/lib/imagekitio/models/folder.rb +76 -0
  94. data/lib/imagekitio/models/folder_copy_params.rb +44 -0
  95. data/lib/imagekitio/models/folder_copy_response.rb +23 -0
  96. data/lib/imagekitio/models/folder_create_params.rb +43 -0
  97. data/lib/imagekitio/models/folder_create_response.rb +10 -0
  98. data/lib/imagekitio/models/folder_delete_params.rb +25 -0
  99. data/lib/imagekitio/models/folder_delete_response.rb +10 -0
  100. data/lib/imagekitio/models/folder_move_params.rb +34 -0
  101. data/lib/imagekitio/models/folder_move_response.rb +23 -0
  102. data/lib/imagekitio/models/folder_rename_params.rb +59 -0
  103. data/lib/imagekitio/models/folder_rename_response.rb +23 -0
  104. data/lib/imagekitio/models/folders/job_get_params.rb +16 -0
  105. data/lib/imagekitio/models/folders/job_get_response.rb +74 -0
  106. data/lib/imagekitio/models/get_image_attributes_options.rb +68 -0
  107. data/lib/imagekitio/models/image_overlay.rb +66 -0
  108. data/lib/imagekitio/models/metadata.rb +483 -0
  109. data/lib/imagekitio/models/overlay.rb +28 -0
  110. data/lib/imagekitio/models/overlay_position.rb +101 -0
  111. data/lib/imagekitio/models/overlay_timing.rb +97 -0
  112. data/lib/imagekitio/models/responsive_image_attributes.rb +48 -0
  113. data/lib/imagekitio/models/solid_color_overlay.rb +42 -0
  114. data/lib/imagekitio/models/solid_color_overlay_transformation.rb +135 -0
  115. data/lib/imagekitio/models/src_options.rb +96 -0
  116. data/lib/imagekitio/models/streaming_resolution.rb +22 -0
  117. data/lib/imagekitio/models/subtitle_overlay.rb +64 -0
  118. data/lib/imagekitio/models/subtitle_overlay_transformation.rb +113 -0
  119. data/lib/imagekitio/models/text_overlay.rb +65 -0
  120. data/lib/imagekitio/models/text_overlay_transformation.rb +267 -0
  121. data/lib/imagekitio/models/transformation.rb +1100 -0
  122. data/lib/imagekitio/models/transformation_position.rb +19 -0
  123. data/lib/imagekitio/models/unsafe_unwrap_webhook_event.rb +36 -0
  124. data/lib/imagekitio/models/unwrap_webhook_event.rb +36 -0
  125. data/lib/imagekitio/models/update_file_request.rb +164 -0
  126. data/lib/imagekitio/models/upload_post_transform_error_event.rb +180 -0
  127. data/lib/imagekitio/models/upload_post_transform_success_event.rb +143 -0
  128. data/lib/imagekitio/models/upload_pre_transform_error_event.rb +108 -0
  129. data/lib/imagekitio/models/upload_pre_transform_success_event.rb +690 -0
  130. data/lib/imagekitio/models/video_overlay.rb +64 -0
  131. data/lib/imagekitio/models/video_transformation_accepted_event.rb +279 -0
  132. data/lib/imagekitio/models/video_transformation_error_event.rb +326 -0
  133. data/lib/imagekitio/models/video_transformation_ready_event.rb +379 -0
  134. data/lib/imagekitio/models/webhook_unsafe_unwrap_params.rb +14 -0
  135. data/lib/imagekitio/models/webhook_unwrap_params.rb +14 -0
  136. data/lib/imagekitio/models.rb +160 -0
  137. data/lib/imagekitio/request_options.rb +77 -0
  138. data/lib/imagekitio/resources/accounts/origins.rb +145 -0
  139. data/lib/imagekitio/resources/accounts/url_endpoints.rb +151 -0
  140. data/lib/imagekitio/resources/accounts/usage.rb +46 -0
  141. data/lib/imagekitio/resources/accounts.rb +26 -0
  142. data/lib/imagekitio/resources/assets.rb +54 -0
  143. data/lib/imagekitio/resources/beta/v2/files.rb +110 -0
  144. data/lib/imagekitio/resources/beta/v2.rb +20 -0
  145. data/lib/imagekitio/resources/beta.rb +18 -0
  146. data/lib/imagekitio/resources/cache/invalidation.rb +66 -0
  147. data/lib/imagekitio/resources/cache.rb +18 -0
  148. data/lib/imagekitio/resources/custom_metadata_fields.rb +133 -0
  149. data/lib/imagekitio/resources/files/bulk.rb +131 -0
  150. data/lib/imagekitio/resources/files/metadata.rb +69 -0
  151. data/lib/imagekitio/resources/files/versions.rb +132 -0
  152. data/lib/imagekitio/resources/files.rb +305 -0
  153. data/lib/imagekitio/resources/folders/job.rb +39 -0
  154. data/lib/imagekitio/resources/folders.rb +166 -0
  155. data/lib/imagekitio/resources/webhooks.rb +30 -0
  156. data/lib/imagekitio/version.rb +5 -0
  157. data/lib/imagekitio.rb +181 -13
  158. data/manifest.yaml +15 -0
  159. data/rbi/imagekitio/client.rbi +92 -0
  160. data/rbi/imagekitio/errors.rbi +205 -0
  161. data/rbi/imagekitio/file_part.rbi +37 -0
  162. data/rbi/imagekitio/helpers/helper.rbi +41 -0
  163. data/rbi/imagekitio/internal/transport/base_client.rbi +295 -0
  164. data/rbi/imagekitio/internal/transport/pooled_net_requester.rbi +80 -0
  165. data/rbi/imagekitio/internal/type/array_of.rbi +104 -0
  166. data/rbi/imagekitio/internal/type/base_model.rbi +304 -0
  167. data/rbi/imagekitio/internal/type/base_page.rbi +42 -0
  168. data/rbi/imagekitio/internal/type/boolean.rbi +58 -0
  169. data/rbi/imagekitio/internal/type/converter.rbi +216 -0
  170. data/rbi/imagekitio/internal/type/enum.rbi +82 -0
  171. data/rbi/imagekitio/internal/type/file_input.rbi +59 -0
  172. data/rbi/imagekitio/internal/type/hash_of.rbi +104 -0
  173. data/rbi/imagekitio/internal/type/request_parameters.rbi +29 -0
  174. data/rbi/imagekitio/internal/type/union.rbi +128 -0
  175. data/rbi/imagekitio/internal/type/unknown.rbi +58 -0
  176. data/rbi/imagekitio/internal/util.rbi +487 -0
  177. data/rbi/imagekitio/internal.rbi +18 -0
  178. data/rbi/imagekitio/models/accounts/origin_create_params.rbi +81 -0
  179. data/rbi/imagekitio/models/accounts/origin_delete_params.rbi +34 -0
  180. data/rbi/imagekitio/models/accounts/origin_get_params.rbi +34 -0
  181. data/rbi/imagekitio/models/accounts/origin_list_params.rbi +34 -0
  182. data/rbi/imagekitio/models/accounts/origin_list_response.rbi +15 -0
  183. data/rbi/imagekitio/models/accounts/origin_request.rbi +775 -0
  184. data/rbi/imagekitio/models/accounts/origin_response.rbi +718 -0
  185. data/rbi/imagekitio/models/accounts/origin_update_params.rbi +81 -0
  186. data/rbi/imagekitio/models/accounts/url_endpoint_create_params.rbi +34 -0
  187. data/rbi/imagekitio/models/accounts/url_endpoint_delete_params.rbi +34 -0
  188. data/rbi/imagekitio/models/accounts/url_endpoint_get_params.rbi +34 -0
  189. data/rbi/imagekitio/models/accounts/url_endpoint_list_params.rbi +34 -0
  190. data/rbi/imagekitio/models/accounts/url_endpoint_list_response.rbi +15 -0
  191. data/rbi/imagekitio/models/accounts/url_endpoint_request.rbi +218 -0
  192. data/rbi/imagekitio/models/accounts/url_endpoint_response.rbi +213 -0
  193. data/rbi/imagekitio/models/accounts/url_endpoint_update_params.rbi +34 -0
  194. data/rbi/imagekitio/models/accounts/usage_get_params.rbi +60 -0
  195. data/rbi/imagekitio/models/accounts/usage_get_response.rbi +89 -0
  196. data/rbi/imagekitio/models/asset_list_params.rbi +281 -0
  197. data/rbi/imagekitio/models/asset_list_response.rbi +28 -0
  198. data/rbi/imagekitio/models/base_overlay.rbi +44 -0
  199. data/rbi/imagekitio/models/base_webhook_event.rbi +33 -0
  200. data/rbi/imagekitio/models/beta/v2/file_upload_params.rbi +861 -0
  201. data/rbi/imagekitio/models/beta/v2/file_upload_response.rbi +1197 -0
  202. data/rbi/imagekitio/models/cache/invalidation_create_params.rbi +45 -0
  203. data/rbi/imagekitio/models/cache/invalidation_create_response.rbi +37 -0
  204. data/rbi/imagekitio/models/cache/invalidation_get_params.rbi +34 -0
  205. data/rbi/imagekitio/models/cache/invalidation_get_response.rbi +93 -0
  206. data/rbi/imagekitio/models/custom_metadata_field.rbi +422 -0
  207. data/rbi/imagekitio/models/custom_metadata_field_create_params.rbi +443 -0
  208. data/rbi/imagekitio/models/custom_metadata_field_delete_params.rbi +30 -0
  209. data/rbi/imagekitio/models/custom_metadata_field_delete_response.rbi +23 -0
  210. data/rbi/imagekitio/models/custom_metadata_field_list_params.rbi +66 -0
  211. data/rbi/imagekitio/models/custom_metadata_field_list_response.rbi +11 -0
  212. data/rbi/imagekitio/models/custom_metadata_field_update_params.rbi +376 -0
  213. data/rbi/imagekitio/models/extensions.rbi +274 -0
  214. data/rbi/imagekitio/models/file.rbi +789 -0
  215. data/rbi/imagekitio/models/file_copy_params.rbi +66 -0
  216. data/rbi/imagekitio/models/file_copy_response.rbi +23 -0
  217. data/rbi/imagekitio/models/file_delete_params.rbi +27 -0
  218. data/rbi/imagekitio/models/file_get_params.rbi +27 -0
  219. data/rbi/imagekitio/models/file_move_params.rbi +51 -0
  220. data/rbi/imagekitio/models/file_move_response.rbi +23 -0
  221. data/rbi/imagekitio/models/file_rename_params.rbi +102 -0
  222. data/rbi/imagekitio/models/file_rename_response.rbi +35 -0
  223. data/rbi/imagekitio/models/file_update_params.rbi +58 -0
  224. data/rbi/imagekitio/models/file_update_response.rbi +322 -0
  225. data/rbi/imagekitio/models/file_upload_params.rbi +897 -0
  226. data/rbi/imagekitio/models/file_upload_response.rbi +1176 -0
  227. data/rbi/imagekitio/models/files/bulk_add_tags_params.rbi +56 -0
  228. data/rbi/imagekitio/models/files/bulk_add_tags_response.rbi +41 -0
  229. data/rbi/imagekitio/models/files/bulk_delete_params.rbi +48 -0
  230. data/rbi/imagekitio/models/files/bulk_delete_response.rbi +41 -0
  231. data/rbi/imagekitio/models/files/bulk_remove_ai_tags_params.rbi +56 -0
  232. data/rbi/imagekitio/models/files/bulk_remove_ai_tags_response.rbi +41 -0
  233. data/rbi/imagekitio/models/files/bulk_remove_tags_params.rbi +56 -0
  234. data/rbi/imagekitio/models/files/bulk_remove_tags_response.rbi +41 -0
  235. data/rbi/imagekitio/models/files/metadata_get_from_url_params.rbi +47 -0
  236. data/rbi/imagekitio/models/files/metadata_get_params.rbi +34 -0
  237. data/rbi/imagekitio/models/files/version_delete_params.rbi +40 -0
  238. data/rbi/imagekitio/models/files/version_delete_response.rbi +25 -0
  239. data/rbi/imagekitio/models/files/version_get_params.rbi +40 -0
  240. data/rbi/imagekitio/models/files/version_list_params.rbi +34 -0
  241. data/rbi/imagekitio/models/files/version_list_response.rbi +13 -0
  242. data/rbi/imagekitio/models/files/version_restore_params.rbi +40 -0
  243. data/rbi/imagekitio/models/folder.rbi +121 -0
  244. data/rbi/imagekitio/models/folder_copy_params.rbi +68 -0
  245. data/rbi/imagekitio/models/folder_copy_response.rbi +33 -0
  246. data/rbi/imagekitio/models/folder_create_params.rbi +71 -0
  247. data/rbi/imagekitio/models/folder_create_response.rbi +23 -0
  248. data/rbi/imagekitio/models/folder_delete_params.rbi +40 -0
  249. data/rbi/imagekitio/models/folder_delete_response.rbi +23 -0
  250. data/rbi/imagekitio/models/folder_move_params.rbi +53 -0
  251. data/rbi/imagekitio/models/folder_move_response.rbi +33 -0
  252. data/rbi/imagekitio/models/folder_rename_params.rbi +98 -0
  253. data/rbi/imagekitio/models/folder_rename_response.rbi +33 -0
  254. data/rbi/imagekitio/models/folders/job_get_params.rbi +34 -0
  255. data/rbi/imagekitio/models/folders/job_get_response.rbi +173 -0
  256. data/rbi/imagekitio/models/get_image_attributes_options.rbi +121 -0
  257. data/rbi/imagekitio/models/image_overlay.rbi +109 -0
  258. data/rbi/imagekitio/models/metadata.rbi +813 -0
  259. data/rbi/imagekitio/models/overlay.rbi +28 -0
  260. data/rbi/imagekitio/models/overlay_position.rbi +148 -0
  261. data/rbi/imagekitio/models/overlay_timing.rbi +135 -0
  262. data/rbi/imagekitio/models/responsive_image_attributes.rbi +74 -0
  263. data/rbi/imagekitio/models/solid_color_overlay.rbi +79 -0
  264. data/rbi/imagekitio/models/solid_color_overlay_transformation.rbi +218 -0
  265. data/rbi/imagekitio/models/src_options.rbi +159 -0
  266. data/rbi/imagekitio/models/streaming_resolution.rbi +38 -0
  267. data/rbi/imagekitio/models/subtitle_overlay.rbi +114 -0
  268. data/rbi/imagekitio/models/subtitle_overlay_transformation.rbi +215 -0
  269. data/rbi/imagekitio/models/text_overlay.rbi +110 -0
  270. data/rbi/imagekitio/models/text_overlay_transformation.rbi +451 -0
  271. data/rbi/imagekitio/models/transformation.rbi +1646 -0
  272. data/rbi/imagekitio/models/transformation_position.rbi +28 -0
  273. data/rbi/imagekitio/models/unsafe_unwrap_webhook_event.rbi +33 -0
  274. data/rbi/imagekitio/models/unwrap_webhook_event.rbi +31 -0
  275. data/rbi/imagekitio/models/update_file_request.rbi +316 -0
  276. data/rbi/imagekitio/models/upload_post_transform_error_event.rbi +434 -0
  277. data/rbi/imagekitio/models/upload_post_transform_success_event.rbi +327 -0
  278. data/rbi/imagekitio/models/upload_pre_transform_error_event.rbi +244 -0
  279. data/rbi/imagekitio/models/upload_pre_transform_success_event.rbi +1300 -0
  280. data/rbi/imagekitio/models/video_overlay.rbi +105 -0
  281. data/rbi/imagekitio/models/video_transformation_accepted_event.rbi +659 -0
  282. data/rbi/imagekitio/models/video_transformation_error_event.rbi +772 -0
  283. data/rbi/imagekitio/models/video_transformation_ready_event.rbi +864 -0
  284. data/rbi/imagekitio/models/webhook_unsafe_unwrap_params.rbi +30 -0
  285. data/rbi/imagekitio/models/webhook_unwrap_params.rbi +27 -0
  286. data/rbi/imagekitio/models.rbi +135 -0
  287. data/rbi/imagekitio/request_options.rbi +59 -0
  288. data/rbi/imagekitio/resources/accounts/origins.rbi +91 -0
  289. data/rbi/imagekitio/resources/accounts/url_endpoints.rbi +129 -0
  290. data/rbi/imagekitio/resources/accounts/usage.rbi +36 -0
  291. data/rbi/imagekitio/resources/accounts.rbi +21 -0
  292. data/rbi/imagekitio/resources/assets.rbi +74 -0
  293. data/rbi/imagekitio/resources/beta/v2/files.rbi +193 -0
  294. data/rbi/imagekitio/resources/beta/v2.rbi +17 -0
  295. data/rbi/imagekitio/resources/beta.rbi +15 -0
  296. data/rbi/imagekitio/resources/cache/invalidation.rbi +44 -0
  297. data/rbi/imagekitio/resources/cache.rbi +15 -0
  298. data/rbi/imagekitio/resources/custom_metadata_fields.rbi +106 -0
  299. data/rbi/imagekitio/resources/files/bulk.rbi +88 -0
  300. data/rbi/imagekitio/resources/files/metadata.rbi +49 -0
  301. data/rbi/imagekitio/resources/files/versions.rbi +89 -0
  302. data/rbi/imagekitio/resources/files.rbi +364 -0
  303. data/rbi/imagekitio/resources/folders/job.rbi +29 -0
  304. data/rbi/imagekitio/resources/folders.rbi +146 -0
  305. data/rbi/imagekitio/resources/webhooks.rbi +50 -0
  306. data/rbi/imagekitio/version.rbi +5 -0
  307. data/sig/imagekitio/client.rbs +47 -0
  308. data/sig/imagekitio/errors.rbs +117 -0
  309. data/sig/imagekitio/file_part.rbs +21 -0
  310. data/sig/imagekitio/helpers/helper.rbs +24 -0
  311. data/sig/imagekitio/internal/transport/base_client.rbs +131 -0
  312. data/sig/imagekitio/internal/transport/pooled_net_requester.rbs +45 -0
  313. data/sig/imagekitio/internal/type/array_of.rbs +48 -0
  314. data/sig/imagekitio/internal/type/base_model.rbs +102 -0
  315. data/sig/imagekitio/internal/type/base_page.rbs +24 -0
  316. data/sig/imagekitio/internal/type/boolean.rbs +26 -0
  317. data/sig/imagekitio/internal/type/converter.rbs +79 -0
  318. data/sig/imagekitio/internal/type/enum.rbs +32 -0
  319. data/sig/imagekitio/internal/type/file_input.rbs +25 -0
  320. data/sig/imagekitio/internal/type/hash_of.rbs +48 -0
  321. data/sig/imagekitio/internal/type/request_parameters.rbs +19 -0
  322. data/sig/imagekitio/internal/type/union.rbs +52 -0
  323. data/sig/imagekitio/internal/type/unknown.rbs +26 -0
  324. data/sig/imagekitio/internal/util.rbs +185 -0
  325. data/sig/imagekitio/internal.rbs +9 -0
  326. data/sig/imagekitio/models/accounts/origin_create_params.rbs +30 -0
  327. data/sig/imagekitio/models/accounts/origin_delete_params.rbs +17 -0
  328. data/sig/imagekitio/models/accounts/origin_get_params.rbs +17 -0
  329. data/sig/imagekitio/models/accounts/origin_list_params.rbs +17 -0
  330. data/sig/imagekitio/models/accounts/origin_list_response.rbs +10 -0
  331. data/sig/imagekitio/models/accounts/origin_request.rbs +468 -0
  332. data/sig/imagekitio/models/accounts/origin_response.rbs +418 -0
  333. data/sig/imagekitio/models/accounts/origin_update_params.rbs +30 -0
  334. data/sig/imagekitio/models/accounts/url_endpoint_create_params.rbs +17 -0
  335. data/sig/imagekitio/models/accounts/url_endpoint_delete_params.rbs +17 -0
  336. data/sig/imagekitio/models/accounts/url_endpoint_get_params.rbs +17 -0
  337. data/sig/imagekitio/models/accounts/url_endpoint_list_params.rbs +17 -0
  338. data/sig/imagekitio/models/accounts/url_endpoint_list_response.rbs +10 -0
  339. data/sig/imagekitio/models/accounts/url_endpoint_request.rbs +97 -0
  340. data/sig/imagekitio/models/accounts/url_endpoint_response.rbs +96 -0
  341. data/sig/imagekitio/models/accounts/url_endpoint_update_params.rbs +17 -0
  342. data/sig/imagekitio/models/accounts/usage_get_params.rbs +30 -0
  343. data/sig/imagekitio/models/accounts/usage_get_response.rbs +52 -0
  344. data/sig/imagekitio/models/asset_list_params.rbs +138 -0
  345. data/sig/imagekitio/models/asset_list_response.rbs +16 -0
  346. data/sig/imagekitio/models/base_overlay.rbs +31 -0
  347. data/sig/imagekitio/models/base_webhook_event.rbs +15 -0
  348. data/sig/imagekitio/models/beta/v2/file_upload_params.rbs +310 -0
  349. data/sig/imagekitio/models/beta/v2/file_upload_response.rbs +487 -0
  350. data/sig/imagekitio/models/cache/invalidation_create_params.rbs +25 -0
  351. data/sig/imagekitio/models/cache/invalidation_create_response.rbs +17 -0
  352. data/sig/imagekitio/models/cache/invalidation_get_params.rbs +17 -0
  353. data/sig/imagekitio/models/cache/invalidation_get_response.rbs +35 -0
  354. data/sig/imagekitio/models/custom_metadata_field.rbs +178 -0
  355. data/sig/imagekitio/models/custom_metadata_field_create_params.rbs +179 -0
  356. data/sig/imagekitio/models/custom_metadata_field_delete_params.rbs +15 -0
  357. data/sig/imagekitio/models/custom_metadata_field_delete_response.rbs +11 -0
  358. data/sig/imagekitio/models/custom_metadata_field_list_params.rbs +32 -0
  359. data/sig/imagekitio/models/custom_metadata_field_list_response.rbs +8 -0
  360. data/sig/imagekitio/models/custom_metadata_field_update_params.rbs +152 -0
  361. data/sig/imagekitio/models/extensions.rbs +132 -0
  362. data/sig/imagekitio/models/file.rbs +384 -0
  363. data/sig/imagekitio/models/file_copy_params.rbs +38 -0
  364. data/sig/imagekitio/models/file_copy_response.rbs +11 -0
  365. data/sig/imagekitio/models/file_delete_params.rbs +15 -0
  366. data/sig/imagekitio/models/file_get_params.rbs +14 -0
  367. data/sig/imagekitio/models/file_move_params.rbs +28 -0
  368. data/sig/imagekitio/models/file_move_response.rbs +11 -0
  369. data/sig/imagekitio/models/file_rename_params.rbs +34 -0
  370. data/sig/imagekitio/models/file_rename_response.rbs +15 -0
  371. data/sig/imagekitio/models/file_update_params.rbs +28 -0
  372. data/sig/imagekitio/models/file_update_response.rbs +120 -0
  373. data/sig/imagekitio/models/file_upload_params.rbs +327 -0
  374. data/sig/imagekitio/models/file_upload_response.rbs +483 -0
  375. data/sig/imagekitio/models/files/bulk_add_tags_params.rbs +30 -0
  376. data/sig/imagekitio/models/files/bulk_add_tags_response.rbs +20 -0
  377. data/sig/imagekitio/models/files/bulk_delete_params.rbs +26 -0
  378. data/sig/imagekitio/models/files/bulk_delete_response.rbs +20 -0
  379. data/sig/imagekitio/models/files/bulk_remove_ai_tags_params.rbs +30 -0
  380. data/sig/imagekitio/models/files/bulk_remove_ai_tags_response.rbs +20 -0
  381. data/sig/imagekitio/models/files/bulk_remove_tags_params.rbs +30 -0
  382. data/sig/imagekitio/models/files/bulk_remove_tags_response.rbs +20 -0
  383. data/sig/imagekitio/models/files/metadata_get_from_url_params.rbs +25 -0
  384. data/sig/imagekitio/models/files/metadata_get_params.rbs +17 -0
  385. data/sig/imagekitio/models/files/version_delete_params.rbs +25 -0
  386. data/sig/imagekitio/models/files/version_delete_response.rbs +13 -0
  387. data/sig/imagekitio/models/files/version_get_params.rbs +25 -0
  388. data/sig/imagekitio/models/files/version_list_params.rbs +17 -0
  389. data/sig/imagekitio/models/files/version_list_response.rbs +9 -0
  390. data/sig/imagekitio/models/files/version_restore_params.rbs +25 -0
  391. data/sig/imagekitio/models/folder.rbs +69 -0
  392. data/sig/imagekitio/models/folder_copy_params.rbs +38 -0
  393. data/sig/imagekitio/models/folder_copy_response.rbs +13 -0
  394. data/sig/imagekitio/models/folder_create_params.rbs +28 -0
  395. data/sig/imagekitio/models/folder_create_response.rbs +11 -0
  396. data/sig/imagekitio/models/folder_delete_params.rbs +23 -0
  397. data/sig/imagekitio/models/folder_delete_response.rbs +11 -0
  398. data/sig/imagekitio/models/folder_move_params.rbs +28 -0
  399. data/sig/imagekitio/models/folder_move_response.rbs +13 -0
  400. data/sig/imagekitio/models/folder_rename_params.rbs +34 -0
  401. data/sig/imagekitio/models/folder_rename_response.rbs +13 -0
  402. data/sig/imagekitio/models/folders/job_get_params.rbs +17 -0
  403. data/sig/imagekitio/models/folders/job_get_response.rbs +72 -0
  404. data/sig/imagekitio/models/get_image_attributes_options.rbs +43 -0
  405. data/sig/imagekitio/models/image_overlay.rbs +59 -0
  406. data/sig/imagekitio/models/metadata.rbs +546 -0
  407. data/sig/imagekitio/models/overlay.rbs +16 -0
  408. data/sig/imagekitio/models/overlay_position.rbs +85 -0
  409. data/sig/imagekitio/models/overlay_timing.rbs +66 -0
  410. data/sig/imagekitio/models/responsive_image_attributes.rbs +36 -0
  411. data/sig/imagekitio/models/solid_color_overlay.rbs +38 -0
  412. data/sig/imagekitio/models/solid_color_overlay_transformation.rbs +97 -0
  413. data/sig/imagekitio/models/src_options.rbs +64 -0
  414. data/sig/imagekitio/models/streaming_resolution.rbs +20 -0
  415. data/sig/imagekitio/models/subtitle_overlay.rbs +59 -0
  416. data/sig/imagekitio/models/subtitle_overlay_transformation.rbs +78 -0
  417. data/sig/imagekitio/models/text_overlay.rbs +59 -0
  418. data/sig/imagekitio/models/text_overlay_transformation.rbs +195 -0
  419. data/sig/imagekitio/models/transformation.rbs +763 -0
  420. data/sig/imagekitio/models/transformation_position.rbs +14 -0
  421. data/sig/imagekitio/models/unsafe_unwrap_webhook_event.rbs +18 -0
  422. data/sig/imagekitio/models/unwrap_webhook_event.rbs +18 -0
  423. data/sig/imagekitio/models/update_file_request.rbs +122 -0
  424. data/sig/imagekitio/models/upload_post_transform_error_event.rbs +192 -0
  425. data/sig/imagekitio/models/upload_post_transform_success_event.rbs +142 -0
  426. data/sig/imagekitio/models/upload_pre_transform_error_event.rbs +115 -0
  427. data/sig/imagekitio/models/upload_pre_transform_success_event.rbs +541 -0
  428. data/sig/imagekitio/models/video_overlay.rbs +59 -0
  429. data/sig/imagekitio/models/video_transformation_accepted_event.rbs +261 -0
  430. data/sig/imagekitio/models/video_transformation_error_event.rbs +300 -0
  431. data/sig/imagekitio/models/video_transformation_ready_event.rbs +359 -0
  432. data/sig/imagekitio/models/webhook_unsafe_unwrap_params.rbs +15 -0
  433. data/sig/imagekitio/models/webhook_unwrap_params.rbs +15 -0
  434. data/sig/imagekitio/models.rbs +119 -0
  435. data/sig/imagekitio/request_options.rbs +36 -0
  436. data/sig/imagekitio/resources/accounts/origins.rbs +34 -0
  437. data/sig/imagekitio/resources/accounts/url_endpoints.rbs +40 -0
  438. data/sig/imagekitio/resources/accounts/usage.rbs +15 -0
  439. data/sig/imagekitio/resources/accounts.rbs +13 -0
  440. data/sig/imagekitio/resources/assets.rbs +18 -0
  441. data/sig/imagekitio/resources/beta/v2/files.rbs +35 -0
  442. data/sig/imagekitio/resources/beta/v2.rbs +11 -0
  443. data/sig/imagekitio/resources/beta.rbs +9 -0
  444. data/sig/imagekitio/resources/cache/invalidation.rbs +19 -0
  445. data/sig/imagekitio/resources/cache.rbs +9 -0
  446. data/sig/imagekitio/resources/custom_metadata_fields.rbs +32 -0
  447. data/sig/imagekitio/resources/files/bulk.rbs +32 -0
  448. data/sig/imagekitio/resources/files/metadata.rbs +19 -0
  449. data/sig/imagekitio/resources/files/versions.rbs +32 -0
  450. data/sig/imagekitio/resources/files.rbs +76 -0
  451. data/sig/imagekitio/resources/folders/job.rbs +14 -0
  452. data/sig/imagekitio/resources/folders.rbs +40 -0
  453. data/sig/imagekitio/resources/webhooks.rbs +27 -0
  454. data/sig/imagekitio/version.rbs +3 -0
  455. metadata +470 -136
  456. data/Rakefile +0 -27
  457. data/lib/active_storage/active_storage.rb +0 -7
  458. data/lib/active_storage/service/ik_file.rb +0 -115
  459. data/lib/active_storage/service/image_kit_io_service.rb +0 -188
  460. data/lib/carrierwave/carrierwave.rb +0 -83
  461. data/lib/carrierwave/storage/ik_file.rb +0 -51
  462. data/lib/carrierwave/storage/imagekit_store.rb +0 -68
  463. data/lib/carrierwave/support/uri_filename.rb +0 -12
  464. data/lib/imagekitio/api_service/bulk.rb +0 -58
  465. data/lib/imagekitio/api_service/custom_metadata_field.rb +0 -52
  466. data/lib/imagekitio/api_service/file.rb +0 -221
  467. data/lib/imagekitio/api_service/folder.rb +0 -49
  468. data/lib/imagekitio/base.rb +0 -12
  469. data/lib/imagekitio/configurable.rb +0 -43
  470. data/lib/imagekitio/constant.rb +0 -36
  471. data/lib/imagekitio/constants/default.rb +0 -22
  472. data/lib/imagekitio/constants/error.rb +0 -69
  473. data/lib/imagekitio/constants/file.rb +0 -11
  474. data/lib/imagekitio/constants/supported_transformation.rb +0 -39
  475. data/lib/imagekitio/constants/url.rb +0 -14
  476. data/lib/imagekitio/railtie.rb +0 -4
  477. data/lib/imagekitio/request.rb +0 -98
  478. data/lib/imagekitio/sdk/version.rb +0 -5
  479. data/lib/imagekitio/url.rb +0 -216
  480. data/lib/imagekitio/utils/calculation.rb +0 -45
  481. data/lib/imagekitio/utils/formatter.rb +0 -48
  482. data/lib/imagekitio/utils/option_validator.rb +0 -36
  483. data/lib/tasks/imagekitio/imagekitio_tasks.rake +0 -4
data/README.md CHANGED
@@ -1,915 +1,744 @@
1
- [<img width="250" alt="ImageKit.io" src="https://raw.githubusercontent.com/imagekit-developer/imagekit-javascript/master/assets/imagekit-light-logo.svg"/>](https://imagekit.io)
2
-
3
- # Imagekit Ruby and Rails SDK
4
-
5
- [![Ruby Test](https://github.com/imagekit-developer/imagekit-ruby/workflows/Ruby%20Test/badge.svg)](https://github.com/imagekit-developer/imagekit-ruby)
6
- [![Gem Version](https://badge.fury.io/rb/imagekitio.svg)](https://badge.fury.io/rb/imagekitio)
7
- [![codecov](https://codecov.io/gh/imagekit-developer/imagekit-ruby/branch/master/graph/badge.svg)](https://codecov.io/gh/imagekit-developer/imagekit-ruby)
8
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
- [![Twitter Follow](https://img.shields.io/twitter/follow/imagekitio?label=Follow&style=social)](https://twitter.com/ImagekitIo)
10
-
11
- Ruby on Rails gem for [ImageKit](https://imagekit.io/) implements the new APIs and interface for different file operations.
12
-
13
- ImageKit is complete media storage, optimization, and transformation solution that comes with an [image and video CDN](https://imagekit.io/features/imagekit-infrastructure). It can be integrated with your existing infrastructure - storage like AWS S3, web servers, your CDN, and custom domain names, allowing you to deliver optimized images in minutes with minimal code changes.
14
-
15
- Table of contents -
16
- * [Changelog](#changelog)
17
- * [Installation](#installation)
18
- * [Initialization](#initialization)
19
- - [CarrierWave](#carrierwave)
20
- - [ActiveStorage](#activestorage)
21
- * [URL Generation](#url-generation)
22
- * [File Upload](#file-upload)
23
- * [File Management](#file-management)
24
- * [Utility Functions](#utility-functions)
25
- * [Sample applications](#sample-application)
26
- * [Upgrade to 2.x](#upgrade-to-2x)
27
- * [Support](#support)
28
- * [Links](#links)
29
-
30
-
31
- # Quick start guide
32
- Get started with [official quick start guide](https://docs.imagekit.io/getting-started/quickstart-guides/ruby-guides) for integrating ImageKit in Ruby on Rails.
33
-
34
- ## Changelog
35
- ### SDK Version 3.0.0
36
- #### Breaking changes
37
- **1. Overlay syntax update**
38
- * In version 3.0.0, we've removed the old overlay syntax parameters for transformations, such as `oi`, `ot`, `obg`, and [more](https://docs.imagekit.io/features/image-transformations/overlay). These parameters are deprecated and will start returning errors when used in URLs. Please migrate to the new layers syntax that supports overlay nesting, provides better positional control, and allows more transformations at the layer level. You can start with [examples](https://docs.imagekit.io/features/image-transformations/overlay-using-layers#examples) to learn quickly.
39
- * You can migrate to the new layers syntax using the `raw` transformation parameter.
1
+ # ImageKit.io Ruby SDK
2
+
3
+ The ImageKit Ruby library provides convenient access to the ImageKit REST API from any Ruby 3.2.0+ application. The library supports building and transforming URLs, generating signed URLs for secure content delivery, and handling file uploads. It ships with comprehensive types & docstrings in Yard, RBS, and RBI – [see below](https://github.com/imagekit-developer/imagekit-ruby#Sorbet) for usage with Sorbet. The standard library's `net/http` is used as the HTTP transport, with connection pooling via the `connection_pool` gem.
4
+
5
+ ## Documentation
6
+
7
+ The official [ImageKit Ruby documentation](https://imagekit.io/docs/integration/ruby) provides complete integration guides and examples.
8
+
9
+ If you're using Ruby on Rails, the [ImageKit Rails gem](https://github.com/imagekit-developer/imagekit-rails) builds on top of this SDK to provide [Rails-specific integrations](https://imagekit.io/docs/integration/ruby/ruby-on-rails) including Active Storage and view helpers.
10
+
11
+ ## Table of Contents
12
+
13
+ - [Documentation](#documentation)
14
+ - [Installation](#installation)
15
+ - [Usage](#usage)
16
+ - [File uploads](#file-uploads)
17
+ - [URL Generation](#url-generation)
18
+ - [Basic URL generation](#basic-url-generation)
19
+ - [URL generation with transformations](#url-generation-with-transformations)
20
+ - [URL generation with image overlay](#url-generation-with-image-overlay)
21
+ - [URL generation with text overlay](#url-generation-with-text-overlay)
22
+ - [Signed URLs for secure delivery](#signed-urls-for-secure-delivery)
23
+ - [Chained transformations](#chained-transformations)
24
+ - [Using raw parameter for custom transformations](#using-raw-parameter-for-custom-transformations)
25
+ - [Helper Methods](#helper-methods)
26
+ - [Authentication parameters for client-side uploads](#authentication-parameters-for-client-side-uploads)
27
+ - [Responsive image attributes](#responsive-image-attributes)
28
+ - [Handling errors](#handling-errors)
29
+ - [Retries](#retries)
30
+ - [Timeouts](#timeouts)
31
+ - [Advanced concepts](#advanced-concepts)
32
+ - [BaseModel](#basemodel)
33
+ - [Making custom or undocumented requests](#making-custom-or-undocumented-requests)
34
+ - [Concurrency & connection pooling](#concurrency--connection-pooling)
35
+ - [Sorbet](#sorbet)
36
+ - [Enums](#enums)
37
+ - [Versioning](#versioning)
38
+ - [Requirements](#requirements)
39
+ - [Contributing](#contributing)
40
40
 
41
41
  ## Installation
42
42
 
43
- Add `imagekitio` dependency to your application's Gemfile:
43
+ To use this gem, install via Bundler by adding the following to your application's `Gemfile`:
44
44
 
45
- ```ruby
46
- gem 'imagekitio'
47
- ```
48
-
49
- And then execute:
50
- ```
51
- $ bundle install
52
- ```
53
-
54
- Or install it yourself:
55
- ```
56
- $ gem install imagekitio
57
- ```
58
-
59
- ## Initialization
60
-
61
- Create a new file `config/initializers/imagekitio.rb` then add the configuration.
62
- ```ruby
63
- ImageKitIo.configure do |config|
64
- if Rails.env.development?
65
- config.public_key = 'your_public_api_key'
66
- config.private_key = 'your_private_api_key'
67
- config.url_endpoint = 'https://ik.imagekit.io/your_imagekit_id/'
68
- end
69
- config.service = :carrierwave
70
- #config.service = :active_storage
71
- #config.constants.MISSING_PRIVATE_KEY = 'custom error message'
72
- end
73
- ```
74
- #### CarrierWave
75
- You can create a CarrierWave uploader to attach pictures to your database objects as their attributes. Skip to [this section](https://github.com/imagekit-developer/imagekit-ruby#file-upload) to upload images without designating them as database attributes. Make sure to add service `:carrierwave` as shown in [initialization section](#initialization).
76
-
77
- ```bash
78
- rails g uploader <Uploading_attribute_name>
79
- # For example, if you want to create an uploader for Avatar attribute, then use
80
- rails g uploader Avatar
81
- # Generated uploader's path will be app/uploaders/avatar_uploader.rb
82
- ```
45
+ <!-- x-release-please-start-version -->
83
46
 
84
- After that, you need to edit your generated uploader and make the following changes:
85
47
  ```ruby
86
- # include this module inside the top of the uploader class
87
- include ImageKitIo::CarrierWave
88
-
89
- # If you want to add uploading options, then create this method inside the uploader file as an example
90
-
91
- def options
92
- options={
93
- response_fields: 'isPrivateFile, tags',
94
- tags: %w[abc def],
95
- use_unique_file_name: false,
96
- folder: "your_directory/"
97
- }
98
- end
99
-
100
- # If you want to set upload dir, then you can use the following method, or you can also use the options method.
101
- # This method should return a string
102
- def store_dir
103
- "your_directory/"
104
- end
48
+ gem "imagekitio", "~> 4.0.0"
105
49
  ```
106
50
 
107
- Then you need to modify your model. for example- if your model name is employee, then do these changes.
51
+ <!-- x-release-please-end -->
108
52
 
109
- ```ruby
110
- class Employee < ApplicationRecord
111
- attr_accessor :avatar
112
- mount_uploader :avatar, AvatarUploader
113
- end
114
- ```
53
+ ## Usage
115
54
 
116
- Get image url:
117
55
  ```ruby
118
- # If @employee is an object of your model that has data.
119
-
120
- # To get the original image url, use
121
- @employee.avatar.url
56
+ require "imagekitio"
122
57
 
123
- # To get the file metadata
124
- @employee.avatar.metadata
58
+ image_kit = Imagekitio::Client.new(
59
+ private_key: ENV["IMAGEKIT_PRIVATE_KEY"], # This is the default and can be omitted
60
+ )
125
61
 
62
+ response = image_kit.files.upload(
63
+ file: Pathname("/path/to/file"),
64
+ file_name: "file-name.jpg"
65
+ )
126
66
 
127
- # And to get transformed url use
128
- # options is a transformation options
129
- @employee.avatar.url_with(options)
67
+ puts(response.file_id)
130
68
  ```
131
69
 
132
- #### ActiveStorage
70
+ ### File uploads
133
71
 
134
- Once you [install](https://guides.rubyonrails.org/active_storage_overview.html#setup) the active_storage gem, then any model can have the attachment using `has_one_attached` or `has_many_attached` like below:
72
+ Request parameters that correspond to file uploads can be passed as raw contents, a [`Pathname`](https://rubyapi.org/3.2/o/pathname) instance, or an `IO` stream.
135
73
 
136
74
  ```ruby
137
- class Employee < ApplicationRecord
138
- has_one_attached :avatar
139
- end
140
- ```
75
+ require "pathname"
141
76
 
142
- Get image url:
143
- ```ruby
144
- # If @employee is an object of your model that has data.
77
+ # Use `Pathname` to stream from disk (memory efficient, supports retries):
78
+ response = image_kit.files.upload(file: Pathname("/path/to/file"))
145
79
 
146
- # To get the original image url, use
147
- @employee.avatar.url
148
- ```
149
-
150
- Now, let's configure active_storage as a service for the imagekitio.
80
+ # Or pass file contents directly
81
+ response = image_kit.files.upload(file: File.read("/path/to/file"))
151
82
 
152
- First add `:active_storage` in initializer file.
83
+ # Or, to control the filename and/or content type:
84
+ file = Imagekitio::FilePart.new(File.read("/path/to/file"), filename: "/path/to/file", content_type: "…")
85
+ response = image_kit.files.upload(file: file)
153
86
 
154
- ```ruby
155
- config.service = :active_storage
156
- ```
157
-
158
- Then add the imagekitio service in the `storage.yml` file:
159
-
160
- ```ruby
161
- imagekitio:
162
- service: ImageKitIo
87
+ puts(response.file_id)
163
88
  ```
164
89
 
90
+ Note that you can also pass a raw `IO` descriptor, but this disables retries, as the library can't be sure if the descriptor is a file or pipe (which cannot be rewound).
165
91
 
166
- ## Usage
92
+ ## URL Generation
167
93
 
168
- You can use this Ruby SDK for three different methods - URL generation, file upload, and media management operations. The usage of the SDK has been explained below.
94
+ The ImageKit SDK provides a powerful `helper.build_url()` method for generating optimized image and video URLs with transformations. Here are examples ranging from simple URLs to complex transformations with overlays and signed URLs.
169
95
 
170
- * `URL Generation`
171
- * `File Upload`
172
- * `File Management`
96
+ ### Basic URL generation
173
97
 
174
- ## URL generation
98
+ Generate a simple URL without any transformations:
175
99
 
176
- **1. Using Image path and image hostname or endpoint**
100
+ ```ruby
101
+ require "imagekitio"
177
102
 
178
- This method allows you to create an URL to access a file using the relative file path and the ImageKit URL endpoint (`urlEndpoint`). The file can be an image, video or any other static file supported by ImageKit.
103
+ image_kit = Imagekitio::Client.new(
104
+ private_key: ENV["IMAGEKIT_PRIVATE_KEY"]
105
+ )
179
106
 
180
- ```ruby
181
- imagekitio = ImageKitIo.client
182
- image_url = imagekitio.url({
183
- path: "/default-image.jpg",
184
- url_endpoint: "https://ik.imagekit.io/your_imagekit_id/endpoint/",
185
- transformation: [{height: "300", width: "400", raw: "ar-4-3,q-40"}]
107
+ # Basic URL without transformations
108
+ url = image_kit.helper.build_url({
109
+ src: "/default-image.jpg",
110
+ url_endpoint: "https://ik.imagekit.io/your_imagekit_id"
186
111
  })
187
- ```
188
112
 
189
- The result in a URL like
190
- ```
191
- https://ik.imagekit.io/your_imagekit_id/endpoint/tr:h-300,w-400,ar-4-3,q-40/default-image.jpg
113
+ puts url
114
+ # Output: https://ik.imagekit.io/your_imagekit_id/default-image.jpg
192
115
  ```
193
116
 
194
- **2.Using full image URL**
195
- This method allows you to add transformation parameters to an absolute URL. For example, if you have configured a custom CNAME and have absolute asset URLs in your database or CMS, you will often need this.
196
-
117
+ You can also use absolute URLs:
197
118
 
198
119
  ```ruby
199
- image_url = imagekitio.url({
200
- src: "https://ik.imagekit.io/your_imagekit_id/endpoint/default-image.jpg",
201
- transformation: [{height: "300", width: "400"}],
120
+ url = image_kit.helper.build_url({
121
+ src: "https://ik.imagekit.io/your_imagekit_id/default-image.jpg",
122
+ url_endpoint: "https://ik.imagekit.io/your_imagekit_id"
202
123
  })
203
124
  ```
204
125
 
205
- The results in a URL like
206
-
207
- ```
208
- https://ik.imagekit.io/your_imagekit_id/endpoint/default-image.jpg?tr=h-300%2Cw-400
209
- ```
210
-
211
-
212
- The `.url()` method accepts the following parameters
126
+ ### URL generation with transformations
213
127
 
214
- | Option | Description |
215
- | :---------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
216
- | url_endpoint | Optional. The base URL to be appended before the path of the image. If not specified, the URL Endpoint specified at the time of SDK initialization is used. For example, https://ik.imagekit.io/your_imagekit_id/endpoint/ |
217
- | path | Conditional. This is the path at which the image exists. For example, `/path/to/image.jpg`. Either the `path` or `src` parameter needs to be specified for URL generation. |
218
- | src | Conditional. This is the complete URL of an image already mapped to ImageKit. For example, `https://ik.imagekit.io/your_imagekit_id/endpoint/path/to/image.jpg`. Either the `path` or `src` parameter needs to be specified for URL generation. |
219
- | transformation | Optional. An array of objects specifying the transformation to be applied in the URL. The transformation name and the value should be specified as a key-value pair in the object. Different steps of a [chained transformation](https://docs.imagekit.io/features/image-transformations/chained-transformations) can be specified as different objects of the array. The complete list of supported transformations in the SDK and some examples of using them are given later. If you use a transformation name that is not specified in the SDK, it gets applied as it is in the URL. |
220
- | transformation_position | Optional. The default value is `path` that places the transformation string as a path parameter in the URL. It can also be specified as `query`, which adds the transformation string as the query parameter `tr` in the URL. If you use `src` parameter to create the URL, then the transformation string is always added as a query parameter. |
221
- | query_parameters | Optional. These are the other query parameters that you want to add to the final URL. These can be any query parameters and not necessarily related to ImageKit. Especially useful if you want to add some versioning parameters to your URLs. |
222
- | signed | Optional. Boolean. Default is `false`. If set to `true`, the SDK generates a signed image URL adding the image signature to the image URL. This can only be used if you are creating the URL with the `url_endpoint` and `path` parameters and not with the `src` parameter. |
223
- | expire_seconds | Optional. Integer. Meant to be used along with the `signed` parameter to specify the time in seconds from now when the URL should expire. If specified, the URL contains the expiry timestamp in the URL, and the image signature is modified accordingly. |
224
-
225
-
226
- ## Examples of generating URLs
227
- **1. Chained Transformations as a query parameter**
128
+ Apply common transformations like resizing, cropping, and format conversion:
228
129
 
229
130
  ```ruby
230
- image_url = imagekitio.url({
231
- path: "/default-image.jpg",
232
- url_endpoint: "https://ik.imagekit.io/your_imagekit_id/endpoint/",
233
- transformation: [{
234
- height: "300",
235
- width: "400"
236
- },{
237
- rotation: 90
238
- }],
239
- transformation_position: "query"
131
+ # URL with basic transformations
132
+ url = image_kit.helper.build_url({
133
+ src: "/path/to/image.jpg",
134
+ url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
135
+ transformation: [
136
+ {
137
+ width: 400,
138
+ height: 300,
139
+ crop: :maintain_ratio,
140
+ quality: 80,
141
+ format_: :webp
142
+ }
143
+ ]
240
144
  })
145
+ # Output: https://ik.imagekit.io/your_imagekit_id/path/to/image.jpg?tr=w-400,h-300,c-maintain_ratio,q-80,f-webp
241
146
  ```
242
- Sample Result URL -
243
- ```
244
- https://ik.imagekit.io/your_imagekit_id/endpoint/default-image.jpg?tr=h-300%2Cw-400%3Art-90
245
- ```
246
-
247
- **2. Sharpening and contrast transforms and a progressive JPG image**
248
-
249
- There are some transforms like [Sharpening](https://docs.imagekit.io/features/image-transformations/image-enhancement-and-color-manipulation)
250
- that can be added to the URL with or without any other value. To use such transforms without specifying a value, specify
251
- the value as "-" in the transformation object. Otherwise, specify the value that you want to be
252
- added to this transformation.
253
147
 
148
+ More transformation examples:
254
149
 
255
150
  ```ruby
256
- image_url = imagekitio.url({
257
- src: "https://ik.imagekit.io/your_imagekit_id/endpoint/default-image.jpg",
258
- transformation: [{
259
- format: "jpg",
260
- progressive: "true",
261
- effect_sharpen: "-",
262
- effect_contrast: "1"
263
- }]
151
+ # Image resizing and cropping
152
+ url = image_kit.helper.build_url({
153
+ src: "/product.jpg",
154
+ url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
155
+ transformation: [
156
+ {
157
+ width: 800,
158
+ height: 600,
159
+ crop: :at_max,
160
+ focus: "auto"
161
+ }
162
+ ]
264
163
  })
265
- ```
266
164
 
267
- ```
268
- //Note that because `src` parameter was used, the transformation string gets added as a query parameter `tr`
269
- https://ik.imagekit.io/your_imagekit_id/endpoint/default-image.jpg?tr=f-jpg%2Cpr-true%2Ce-sharpen%2Ce-contrast-1
270
- ```
165
+ # Image effects
166
+ url = image_kit.helper.build_url({
167
+ src: "/photo.jpg",
168
+ url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
169
+ transformation: [
170
+ {
171
+ blur: 10,
172
+ grayscale: true,
173
+ radius: 20
174
+ }
175
+ ]
176
+ })
271
177
 
272
- **3. Signed URL that expires in 300 seconds with the default URL endpoint and other query parameters**
178
+ # Format and quality optimization
179
+ url = image_kit.helper.build_url({
180
+ src: "/image.jpg",
181
+ url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
182
+ transformation: [
183
+ {
184
+ format_: :auto,
185
+ quality: 85,
186
+ progressive: true
187
+ }
188
+ ]
189
+ })
190
+ ```
273
191
 
274
- ```ruby
275
- image_url = imagekit.url({
276
- path: "/default-image",
277
- query_parameters: {
278
- "v": "123"
192
+ ### URL generation with image overlay
193
+
194
+ Add image overlays to your base image:
195
+
196
+ ```ruby
197
+ # URL with image overlay
198
+ url = image_kit.helper.build_url({
199
+ src: "/path/to/base-image.jpg",
200
+ url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
201
+ transformation: [
202
+ {
203
+ width: 500,
204
+ height: 400,
205
+ overlay: {
206
+ type: :image,
207
+ input: "/path/to/overlay-logo.png",
208
+ position: {
209
+ x: 10,
210
+ y_: 10
211
+ },
212
+ transformation: [
213
+ {
214
+ width: 100,
215
+ height: 50
216
+ }
217
+ ]
218
+ }
219
+ }
220
+ ]
221
+ })
222
+ # Output: URL with image overlay positioned at x:10, y:10
223
+ ```
224
+
225
+ ### URL generation with text overlay
226
+
227
+ Add customized text overlays:
228
+
229
+ ```ruby
230
+ # URL with text overlay
231
+ url = image_kit.helper.build_url({
232
+ src: "/path/to/base-image.jpg",
233
+ url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
234
+ transformation: [
235
+ {
236
+ width: 600,
237
+ height: 400,
238
+ overlay: {
239
+ type: :text,
240
+ text: "Sample Text Overlay",
241
+ position: {
242
+ x: 50,
243
+ y_: 50,
244
+ focus: :center
245
+ },
246
+ transformation: [
247
+ {
248
+ font_size: 40,
249
+ font_family: "Arial",
250
+ font_color: "FFFFFF",
251
+ typography: "b" # bold
252
+ }
253
+ ]
254
+ }
255
+ }
256
+ ]
257
+ })
258
+ # Output: URL with bold white Arial text overlay at center position
259
+ ```
260
+
261
+ You can combine multiple overlays for complex compositions:
262
+
263
+ ```ruby
264
+ # URL with multiple overlays (text + image)
265
+ url = image_kit.helper.build_url({
266
+ src: "/path/to/base-image.jpg",
267
+ url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
268
+ transformation: [
269
+ {
270
+ width: 800,
271
+ height: 600,
272
+ overlay: {
273
+ type: :text,
274
+ text: "Header Text",
275
+ position: { x: 20, y_: 20 },
276
+ transformation: [{ font_size: 30, font_color: "000000" }]
277
+ }
279
278
  },
280
- transformation: [{
281
- height: "300",
282
- width: "400"
283
- }],
284
- signed: True,
285
- expire_seconds: 300
279
+ {
280
+ overlay: {
281
+ type: :image,
282
+ input: "/watermark.png",
283
+ position: { focus: :bottom_right },
284
+ transformation: [{ width: 100, opacity: 70 }]
285
+ }
286
+ }
287
+ ]
286
288
  })
289
+ # Output: URL with text overlay at top-left and semi-transparent watermark at bottom-right
287
290
  ```
288
- **Sample Result URL**
289
- ```
290
- https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400/default-image.jpg?v=123&ik-t=1567358667&ik-s=f2c7cdacbe7707b71a83d49cf1c6110e3d701054
291
- ```
292
-
293
- **4. Adding overlays**
294
-
295
- ImageKit.io enables you to apply overlays to [images](https://docs.imagekit.io/features/image-transformations/overlay-using-layers) and [videos](https://docs.imagekit.io/features/video-transformation/overlay) using the raw parameter with the concept of [layers](https://docs.imagekit.io/features/image-transformations/overlay-using-layers#layers). The raw parameter facilitates incorporating transformations directly in the URL. A layer is a distinct type of transformation that allows you to define an asset to serve as an overlay, along with its positioning and additional transformations.
296
291
 
297
- **Text as overlays**
292
+ ### Signed URLs for secure delivery
298
293
 
299
- You can add any text string over a base video or image using a text layer (l-text).
300
-
301
- For example:
294
+ Generate signed URLs that expire after a specified time for secure content delivery:
302
295
 
303
296
  ```ruby
304
- image_url = imagekit.url({
305
- path: "/default-image",
306
- url_endpoint: "https://ik.imagekit.io/your_imagekit_id/endpoint/",
307
- transformation: [{
308
- height: "300",
309
- width: "400",
310
- raw: "l-text,i-Imagekit,fs-50,l-end"
311
- }],
297
+ # Generate a signed URL that expires in 1 hour (3600 seconds)
298
+ url = image_kit.helper.build_url({
299
+ src: "/private/secure-image.jpg",
300
+ url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
301
+ transformation: [
302
+ {
303
+ width: 400,
304
+ height: 300,
305
+ quality: 90
306
+ }
307
+ ],
308
+ signed: true,
309
+ expires_in: 3600 # URL expires in 1 hour
312
310
  })
311
+ # Output: URL with signature parameters (?ik-t=timestamp&ik-s=signature)
312
+
313
+ # Generate a signed URL that doesn't expire
314
+ url = image_kit.helper.build_url({
315
+ src: "/private/secure-image.jpg",
316
+ url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
317
+ signed: true
318
+ # No expires_in means the URL won't expire
319
+ })
320
+ # Output: URL with signature parameter (?ik-s=signature)
313
321
  ```
314
- **Sample Result URL**
315
- ```
316
- https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400,l-text,i-Imagekit,fs-50,l-end/default-image.jpg
317
- ```
318
-
319
- **Image as overlays**
320
322
 
321
- You can add an image over a base video or image using an image layer (l-image).
323
+ ### Chained transformations
322
324
 
323
- For example:
325
+ Apply multiple transformation steps by passing multiple transformation objects. Each transformation is applied sequentially:
324
326
 
325
327
  ```ruby
326
- image_url = imagekit.url({
327
- path: "/default-image",
328
- url_endpoint: "https://ik.imagekit.io/your_imagekit_id/endpoint/",
329
- transformation: [{
330
- height: "300",
331
- width: "400",
332
- raw: "l-image,i-default-image.jpg,w-100,b-10_CDDC39,l-end"
333
- }],
328
+ # First resize, then apply effects
329
+ url = image_kit.helper.build_url({
330
+ src: "/default-image.jpg",
331
+ url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
332
+ transformation: [
333
+ {
334
+ width: 400,
335
+ height: 300
336
+ },
337
+ {
338
+ rotation: 90,
339
+ blur: 5
340
+ }
341
+ ]
334
342
  })
335
- ```
336
- **Sample Result URL**
337
- ```
338
- https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400,l-image,i-default-image.jpg,w-100,b-10_CDDC39,l-end/default-image.jpg
343
+ # Output: https://ik.imagekit.io/your_imagekit_id/default-image.jpg?tr=w-400,h-300:rt-90,bl-5
339
344
  ```
340
345
 
341
- **Solid color blocks as overlays**
346
+ ### Using raw parameter for custom transformations
342
347
 
343
- You can add solid color blocks over a base video or image using an image layer (l-image).
344
-
345
- For example:
348
+ ImageKit frequently adds new transformation parameters that might not yet be documented in the SDK. You can use the `raw` parameter to access these features or create custom transformation strings:
346
349
 
347
350
  ```ruby
348
- image_url = imagekit.url({
349
- path: "/img/sample-video",
350
- url_endpoint: "https://ik.imagekit.io/your_imagekit_id/endpoint/",
351
- transformation: [{
352
- height: "300",
353
- width: "400",
354
- raw: "l-image,i-ik_canvas,bg-FF0000,w-300,h-100,l-end"
355
- }],
351
+ # Using raw parameter for custom transformations
352
+ url = image_kit.helper.build_url({
353
+ src: "/path/to/image.jpg",
354
+ url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
355
+ transformation: [
356
+ {
357
+ width: 400,
358
+ height: 300,
359
+ raw: "something-new"
360
+ }
361
+ ]
356
362
  })
363
+ # Output: https://ik.imagekit.io/your_imagekit_id/path/to/image.jpg?tr=w-400,h-300,something-new
357
364
  ```
358
- **Sample Result URL**
359
- ```
360
- https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400,l-image,i-ik_canvas,bg-FF0000,w-300,h-100,l-end/img/sample-video.mp4
361
- ```
362
-
363
- **5. Arithmetic expressions in transformations**
364
-
365
- ImageKit allows use of [arithmetic expressions](https://docs.imagekit.io/features/arithmetic-expressions-in-transformations) in certain dimension and position-related parameters, making media transformations more flexible and dynamic.
366
365
 
367
- For example:
366
+ You can control where transformations appear in the URL:
368
367
 
369
368
  ```ruby
370
- image_url = imagekit.url({
371
- path: "/default-image.jpg",
372
- url_endpoint: "https://ik.imagekit.io/your_imagekit_id/endpoint/",
373
- transformation: [{
374
- width: "iw_div_4",
375
- height: "ih_div_2",
376
- border: "cw_mul_0.05_yellow"
377
- }]
378
- });
379
- ```
380
-
381
- **Sample Result URL**
382
- ```
383
- https://ik.imagekit.io/your_imagekit_id/default-image.jpg?tr=w-iw_div_4,h-ih_div_2,b-cw_mul_0.05_yellow
369
+ # Add transformations to the URL path instead of query parameters
370
+ url = image_kit.helper.build_url({
371
+ src: "/default-image.jpg",
372
+ url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
373
+ transformation_position: :path,
374
+ transformation: [
375
+ {
376
+ width: 400,
377
+ height: 300
378
+ }
379
+ ]
380
+ })
381
+ # Output: https://ik.imagekit.io/your_imagekit_id/tr:w-400,h-300/default-image.jpg
384
382
  ```
385
383
 
386
- **List of transformations**
387
-
388
- The complete list of transformations supported and their usage in ImageKit can be found [here](https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations). The SDK gives a name to each transformation parameter, making the code simpler, making the code simpler, and readable.
389
-
390
- If a transformation is supported in ImageKit, but a name for it cannot be found in the table below, then use the transformation code from ImageKit docs as the name when using the `url` function.
391
-
392
- If you want to generate transformations in your application and add them to the URL as it is, use the `raw` parameter.
393
-
394
- | Supported Transformation Name | Translates to parameter |
395
- |-------------------------------|-------------------------|
396
- | height | h |
397
- | width | w |
398
- | aspect_ratio | ar |
399
- | quality | q |
400
- | crop | c |
401
- | crop_mode | cm |
402
- | x | x |
403
- | y | y |
404
- | focus | fo |
405
- | format | f |
406
- | radius | r |
407
- | background | bg |
408
- | border | b |
409
- | rotation | rt |
410
- | blur | bl |
411
- | named | n |
412
- | progressive | pr |
413
- | lossless | lo |
414
- | trim | t |
415
- | metadata | md |
416
- | color_profile | cp |
417
- | default_image | di |
418
- | dpr | dpr |
419
- | effect_sharpen | e-sharpen |
420
- | effect_usm | e-usm |
421
- | effect_contrast | e-contrast |
422
- | effect_gray | e-grayscale |
423
- | effect_shadow | e-shadow |
424
- | effect_gradient | e-gradient |
425
- | original | orig |
426
- | raw | `replaced by the parameter value` |
427
-
428
- ## File Upload
429
- This method can be used to directly upload images to your ImageKit Media Library without giving it the designation of an attribute of any database object.
430
-
431
- The SDK provides a simple interface using the `.upload()` method to upload files to the ImageKit Media library. It
432
- accepts all the parameters supported by the [ImageKit Upload API](https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload).
433
-
434
- The `upload()` method requires at least the `file` and the `file_name` parameter to upload a file and returns
435
- a callback with the `error` and `result` as arguments. You can pass other parameters supported by the
436
- ImageKit upload API using the same parameter name as specified in the upload API documentation. For example, to specify tags for a file at the time of upload, use the `tags` parameter as specified in the [documentation here](https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload).
437
-
438
- Simple usage
384
+ Add custom query parameters:
439
385
 
440
386
  ```ruby
441
- imagekitio.upload_file(
442
- file: "<url|base_64|binary>", # required
443
- file_name: "my_file_name.jpg", # required
444
- response_fields: 'isPrivateFile, tags',
445
- tags: %w[abc def],
446
- use_unique_file_name: true,
447
- transformation: {
448
- pre: 'l-text,i-Imagekit,fs-50,l-end',
449
- post: [
450
- {
451
- type: 'transformation',
452
- value: 'w-100'
453
- }
454
- ]
455
- },
456
- checks: "'request.folder' : '/'" # To run server side checks before uploading files. Notice the quotes around file.size and 1mb.
457
- is_published: true
458
- )
459
-
387
+ url = image_kit.helper.build_url({
388
+ src: "/default-image.jpg",
389
+ url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
390
+ query_parameters: {
391
+ version: "1",
392
+ cache: "max"
393
+ }
394
+ })
460
395
  ```
461
396
 
462
- If the upload is succeeded, `error` will be `None`, and the result will be the same as what is received from ImageKit's
463
- servers. If the upload fails, `error` will be the same as what is received from ImageKit's servers, and the result will
464
- be `None`.
465
-
466
- ## File Management
397
+ ## Helper Methods
467
398
 
468
- The SDK provides a simple interface for all the [media APIs mentioned here](https://docs.imagekit.io/api-reference/media-api)
469
- to manage your files. This also returns `error` and `result`. The `error` will be `None` if API succeeds.
399
+ The SDK provides several helper methods for common ImageKit operations.
470
400
 
471
- **List & Search Files**
401
+ ### Authentication parameters for client-side uploads
472
402
 
473
- Accepts an object specifying the parameters to be used to list and search files. All parameters specified
474
- in the [documentation here](https://docs.imagekit.io/api-reference/media-api/list-and-search-files#list-and-search-file-api) can be passed with the
475
- correct values to get the results.
403
+ Generate authentication parameters for secure client-side file uploads. These parameters allow you to securely upload files directly from the browser without exposing your private API key:
476
404
 
477
405
  ```ruby
478
- imagekitio.list_files(
479
- skip: 0,
480
- limit: 5
481
- )
482
- ```
483
- **Get File Details**
406
+ require "imagekitio"
484
407
 
485
- Accepts the file ID and fetches the details as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/get-file-details)
486
-
487
- ```ruby
488
- imagekitio.get_file_details(
489
- file_id: '598821f949c0a938d57563bd'
408
+ image_kit = Imagekitio::Client.new(
409
+ private_key: ENV["IMAGEKIT_PRIVATE_KEY"]
490
410
  )
491
- ```
492
411
 
493
- **Get File Metadata**
412
+ # Generate authentication parameters with default expiry (30 minutes)
413
+ auth_params = image_kit.helper.get_authentication_parameters
494
414
 
495
- Accepts the file ID and fetches the metadata as per the [API documentation here](https://docs.imagekit.io/api-reference/metadata-api/get-image-metadata-for-uploaded-media-files)
496
- ```ruby
497
- imagekit.get_file_metadata(
498
- file_id: '598821f949c0a938d57563bd'
499
- )
415
+ puts auth_params
416
+ # Output: { token: "unique-token", expire: 1234567890, signature: "signature-hash" }
500
417
  ```
501
418
 
502
- **Get File Metadata from remote url**
503
-
504
- Accepts the remote file url and fetches the metadata as per the [API documentation here](https://docs.imagekit.io/api-reference/metadata-api/get-image-metadata-from-remote-url)
419
+ Customize the token and expiration:
505
420
 
506
421
  ```ruby
507
- imagekit.get_remote_file_url_metadata(
508
- remote_file_url: "https://ik.imagekit.io/demo/tr:w-100/default-image.jpg"
422
+ # Custom token and expiry (1 hour from now)
423
+ auth_params = image_kit.helper.get_authentication_parameters(
424
+ token: "my-custom-token",
425
+ expire: Time.now.to_i + 3600
509
426
  )
427
+ # Output: { token: "my-custom-token", expire: 1234567890, signature: "generated-signature" }
510
428
  ```
511
429
 
512
- **Update File Details**
430
+ These authentication parameters can be used in client-side upload forms to securely upload files without exposing your private API key.
513
431
 
514
- Update parameters associated with the file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/update-file-details).
515
- The first argument to the `update_field_details` method is the file ID, and a second argument is an object with the
516
- parameters to be updated.
432
+ ### Responsive image attributes
517
433
 
518
- ```ruby
519
- imagekitio.update_file_details(
520
- file_id: '598821f949c0a938d57563bd',
521
- tags: ["image_tag"],
522
- custom_coordinates: "10,10,100, 100"
523
- )
524
- ```
525
-
526
-
527
- **Update publish status**
528
-
529
- If `publish` is included in the update options, no other parameters are allowed. If any are present, an error will be returned: `Your request cannot contain any other parameters when publish is present`.
434
+ Generate responsive image attributes for HTML `<img>` tags. This creates optimized `srcset` and `sizes` attributes for responsive images:
530
435
 
531
436
  ```ruby
532
- imagekitio.update_file_details(
533
- file_id: '598821f949c0a938d57563bd',
534
- publish:{
535
- isPublished: true,
536
- includeFileVersions: true
437
+ # Width-based responsive images (generates w descriptors)
438
+ attrs = image_kit.helper.get_responsive_image_attributes({
439
+ src: "/default-image.jpg",
440
+ url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
441
+ sizes: "(min-width: 768px) 50vw, 100vw",
442
+ transformation: [
443
+ {
444
+ quality: 80,
445
+ format_: :auto
537
446
  }
538
- )
539
- ```
447
+ ]
448
+ })
540
449
 
541
- **Copy File**
450
+ puts attrs.src
451
+ # Largest candidate URL
542
452
 
543
- Copy file from one path to another path using the source file path and the destination path as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-file)
453
+ puts attrs.src_set
454
+ # URL1 640w, URL2 750w, URL3 1080w, ...
544
455
 
545
- ```ruby
546
- imagekitio.copy_file(
547
- source_file_path: '/path/to/file.jpg',
548
- destination_path: '/folder/to/copy/into',
549
- include_file_versions: true #default false
550
- )
456
+ puts attrs.sizes
457
+ # (min-width: 768px) 50vw, 100vw
551
458
  ```
552
459
 
553
- **Move File**
554
-
555
- Move file from one folder to another folder using the source file path and destination path as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/move-file)
460
+ DPR-based responsive images (generates x descriptors):
556
461
 
557
462
  ```ruby
558
- imagekitio.move_file(
559
- source_file_path: '/path/to/file.jpg',
560
- destination_path: '/folder/to/move/into/'
561
- )
562
- ```
563
-
564
- **Rename File**
463
+ # When width is provided without sizes, generates 1x and 2x variants
464
+ attrs = image_kit.helper.get_responsive_image_attributes({
465
+ src: "/profile.jpg",
466
+ url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
467
+ width: 400,
468
+ transformation: [
469
+ {
470
+ quality: 85
471
+ }
472
+ ]
473
+ })
565
474
 
566
- Rename file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/rename-file)
475
+ puts attrs.src_set
476
+ # URL1 1x, URL2 2x
567
477
 
568
- ```ruby
569
- imagekitio.rename_file(
570
- file_path: '/path/to/old-file-name.jpg',
571
- new_file_name: 'new-file-name.jpg',
572
- purge_cache: true #optional
573
- )
478
+ puts attrs.width
479
+ # 400
574
480
  ```
575
481
 
576
- **Delete File**
577
-
578
- Delete a file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-file). The method accepts the file ID of the file that has to be deleted.
482
+ Custom breakpoints for device widths:
579
483
 
580
484
  ```ruby
581
- imagekitio.delete_file(
582
- file_id: '598821f949c0a938d57563bd'
583
- )
485
+ attrs = image_kit.helper.get_responsive_image_attributes({
486
+ src: "/default-image.jpg",
487
+ url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
488
+ sizes: "100vw",
489
+ device_breakpoints: [320, 640, 1024, 1920],
490
+ image_breakpoints: [16, 32, 64],
491
+ transformation: [
492
+ {
493
+ crop: :at_max
494
+ }
495
+ ]
496
+ })
584
497
  ```
585
- **File versions**
586
498
 
587
- Get all file versions as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/get-file-versions). The method accepts the file ID of the file.
499
+ The returned attributes can be directly used in your HTML:
588
500
 
589
- ```ruby
590
- imagekitio.file_versions(
591
- file_id: '598821f949c0a938d57563bd'
592
- )
501
+ ```erb
502
+ <img
503
+ src="<%= attrs.src %>"
504
+ srcset="<%= attrs.src_set %>"
505
+ sizes="<%= attrs.sizes %>"
506
+ alt="Responsive image"
507
+ />
593
508
  ```
594
- **File version details**
595
509
 
596
- Get all file version detail as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/get-file-version-details). The method accepts the file ID and version ID of the file.
510
+ Generate signed responsive image URLs:
597
511
 
598
512
  ```ruby
599
- imagekitio.file_version_detail(
600
- file_id: '598821f949c0a938d57563bd',
601
- version_id: '846321f949c0a938d57567ty'
602
- )
513
+ # Generate signed responsive image URLs
514
+ attrs = image_kit.helper.get_responsive_image_attributes({
515
+ src: "/default-image.jpg",
516
+ url_endpoint: "https://ik.imagekit.io/your_imagekit_id",
517
+ sizes: "100vw",
518
+ signed: true,
519
+ expires_in: 3600,
520
+ transformation: [
521
+ {
522
+ quality: 80
523
+ }
524
+ ]
525
+ })
603
526
  ```
604
527
 
605
- **Delete file version**
528
+ ### Handling errors
606
529
 
607
- Delete file version as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-file-version). The method accepts the file ID and version ID of the file.
530
+ When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of `Imagekitio::Errors::APIError` will be thrown:
608
531
 
609
532
  ```ruby
610
- imagekitio.delete_file_version(
611
- file_id: '598821f949c0a938d57563bd',
612
- version_id: '846321f949c0a938d57567ty'
613
- )
533
+ begin
534
+ file = image_kit.files.upload(
535
+ file: File.read("/path/to/file.jpg"),
536
+ file_name: "file-name.jpg"
537
+ )
538
+ rescue Imagekitio::Errors::APIConnectionError => e
539
+ puts("The server could not be reached")
540
+ puts(e.cause) # an underlying Exception, likely raised within `net/http`
541
+ rescue Imagekitio::Errors::RateLimitError => e
542
+ puts("A 429 status code was received; we should back off a bit.")
543
+ rescue Imagekitio::Errors::APIStatusError => e
544
+ puts("Another non-200-range status code was received")
545
+ puts(e.status)
546
+ end
614
547
  ```
615
548
 
616
- **Restore file version**
617
-
618
- Restore deleted file version as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/restore-file-version). The method accepts the file ID and version ID of the file.
549
+ Error codes are as follows:
619
550
 
620
- ```ruby
621
- imagekitio.restore_file_version(
622
- file_id: '598821f949c0a938d57563bd',
623
- version_id: '846321f949c0a938d57567ty'
624
- )
625
- ```
551
+ | Cause | Error Type |
552
+ | ---------------- | -------------------------- |
553
+ | HTTP 400 | `BadRequestError` |
554
+ | HTTP 401 | `AuthenticationError` |
555
+ | HTTP 403 | `PermissionDeniedError` |
556
+ | HTTP 404 | `NotFoundError` |
557
+ | HTTP 409 | `ConflictError` |
558
+ | HTTP 422 | `UnprocessableEntityError` |
559
+ | HTTP 429 | `RateLimitError` |
560
+ | HTTP >= 500 | `InternalServerError` |
561
+ | Other HTTP error | `APIStatusError` |
562
+ | Timeout | `APITimeoutError` |
563
+ | Network error | `APIConnectionError` |
626
564
 
627
- **Bulk File Delete by IDs**
565
+ ### Retries
628
566
 
629
- Delete a file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-files-bulk). The method accepts a list of file IDs of files that has to be
630
- deleted.
567
+ Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
631
568
 
632
- ```ruby
633
- imagekitio.delete_bulk_files(
634
- file_ids: ["598821f949c0a938d57563bd", "598821f949c0a938d57543bd"]
635
- )
636
- ```
569
+ Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, >=500 Internal errors, and timeouts will all be retried by default.
637
570
 
638
- **Purge Cache**
639
- Programmatically issue a clear cache request as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/purge-cache).
640
- Accepts the full URL of the file for which the cache has to be cleared.
571
+ You can use the `max_retries` option to configure or disable this:
641
572
 
642
573
  ```ruby
643
- imagekitio.purge_file_cache(
644
- file_url: 'https://ik.imagekit.io/demo/logo-white_SJwqB4Nfe.png'
574
+ # Configure the default for all requests:
575
+ image_kit = Imagekitio::Client.new(
576
+ max_retries: 0 # default is 2
645
577
  )
646
- ```
647
- **Purge Cache Status**
648
-
649
- Get the purge cache request status using the request ID returned when a purge cache request gets submitted as per the
650
- [API documentation here](https://docs.imagekit.io/api-reference/media-api/purge-cache-status)
651
578
 
652
- ```ruby
653
- imagekitio.purge_file_cache_status(
654
- request_id: '598821f949c0a938d57543bd'
579
+ # Or, configure per-request:
580
+ image_kit.files.upload(
581
+ file: File.read("/path/to/file.jpg"),
582
+ file_name: "file-name.jpg",
583
+ request_options: {max_retries: 5}
655
584
  )
656
585
  ```
657
586
 
658
- **Add Bulk Tags**
587
+ ### Timeouts
659
588
 
660
- Add multiple tags on multiple files using an array of file ids and an array of tags as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/add-tags-bulk)
589
+ By default, requests will time out after 60 seconds. You can use the timeout option to configure or disable this:
661
590
 
662
591
  ```ruby
663
- imagekitio.add_bulk_tags(
664
- file_ids: ['598821f949c0a938d57543bd', '598921f949c0a938d57543bd'],
665
- tags: ['custom_tags', 'image', 'favourite']
592
+ # Configure the default for all requests:
593
+ image_kit = Imagekitio::Client.new(
594
+ timeout: nil # default is 60
666
595
  )
667
- ```
668
596
 
669
- **Delete Bulk Tags**
670
-
671
- Remove multiple tags from multiple files using an array of file ids and an array of tags as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/remove-tags-bulk)
672
-
673
- ```ruby
674
- imagekitio.delete_bulk_tags(
675
- file_ids: ['598821f949c0a938d57543bd', '598921f949c0a938d57543bd'],
676
- tags: ['custom_tags', 'image']
597
+ # Or, configure per-request:
598
+ image_kit.files.upload(
599
+ file: File.read("/path/to/file.jpg"),
600
+ file_name: "file-name.jpg",
601
+ request_options: {timeout: 5}
677
602
  )
678
603
  ```
679
604
 
680
- **Delete Bulk AI Tags**
605
+ On timeout, `Imagekitio::Errors::APITimeoutError` is raised.
681
606
 
682
- Delete bulk ai tags as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/remove-aitags-bulk)
607
+ Note that requests that time out are retried by default.
683
608
 
684
- ```ruby
685
- imagekitio.delete_bulk_ai_tags(
686
- file_ids: ['598821f949c0a938d57543bd', '598921f949c0a938d57543bd'],
687
- ai_tags: ['custom_ai_tags']
688
- )
689
- ```
609
+ ## Advanced concepts
690
610
 
691
- **Create Folder**
611
+ ### BaseModel
692
612
 
693
- Create folder as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/create-folder)
613
+ All parameter and response objects inherit from `Imagekitio::Internal::Type::BaseModel`, which provides several conveniences, including:
694
614
 
695
- ```ruby
696
- imagekitio.create_folder(
697
- folder_name: 'new_folder',
698
- parent_folder_path: 'source/folder/path' #optional
699
- )
700
- ```
615
+ 1. All fields, including unknown ones, are accessible with `obj[:prop]` syntax, and can be destructured with `obj => {prop: prop}` or pattern-matching syntax.
701
616
 
617
+ 2. Structural equivalence for equality; if two API calls return the same values, comparing the responses with == will return true.
702
618
 
703
- **Copy Folder**
619
+ 3. Both instances and the classes themselves can be pretty-printed.
704
620
 
705
- Copy folder as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-folder)
621
+ 4. Helpers such as `#to_h`, `#deep_to_h`, `#to_json`, and `#to_yaml`.
706
622
 
707
- ```ruby
708
- imagekitio.copy_folder(
709
- source_folder_path: '/folder/to/copy',
710
- destination_path: '/folder/to/copy/into',
711
- include_file_versions: true #default false
712
- )
713
- ```
623
+ ### Making custom or undocumented requests
624
+
625
+ #### Undocumented properties
714
626
 
715
- **Move Folder**
627
+ You can send undocumented parameters to any endpoint, and read undocumented response properties, like so:
716
628
 
717
- Move folder as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/move-folder)
629
+ Note: the `extra_` parameters of the same name overrides the documented parameters.
718
630
 
719
631
  ```ruby
720
- imagekitio.move_folder(
721
- source_folder_path: '/folder/to/move',
722
- destination_path: '/folder/to/move/into/'
723
- )
724
- ```
632
+ response =
633
+ image_kit.files.upload(
634
+ file: File.read("/path/to/file.jpg"),
635
+ file_name: "file-name.jpg",
636
+ request_options: {
637
+ extra_query: {my_query_parameter: value},
638
+ extra_body: {my_body_parameter: value},
639
+ extra_headers: {"my-header": value}
640
+ }
641
+ )
725
642
 
726
- **Delete Folder**
643
+ puts(response[:my_undocumented_property])
644
+ ```
727
645
 
728
- Delete folder as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-folder)
646
+ #### Undocumented request params
729
647
 
730
- ```ruby
731
- imagekitio.delete_folder(
732
- folder_path: 'folder/to/delete'
733
- )
734
- ```
648
+ If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` under the `request_options:` parameter when making a request, as seen in the examples above.
735
649
 
736
- **Bulk Job Status**
650
+ #### Undocumented endpoints
737
651
 
738
- Get the bulk job status as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-move-folder-status)
652
+ To make requests to undocumented endpoints while retaining the benefit of auth, retries, and so on, you can make requests using `client.request`, like so:
739
653
 
740
654
  ```ruby
741
- imagekitio.bulk_job_status(
742
- job_id: '5e21880d5efe355febd4cccd'
655
+ response = client.request(
656
+ method: :post,
657
+ path: '/undocumented/endpoint',
658
+ query: {"dog": "woof"},
659
+ headers: {"useful-header": "interesting-value"},
660
+ body: {"hello": "world"}
743
661
  )
744
662
  ```
745
663
 
746
- **Create a custom metadata field**
747
-
748
- Create custom metadata fields as per the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/create-custom-metadata-field)
664
+ ### Concurrency & connection pooling
749
665
 
750
- ```ruby
666
+ The `Imagekitio::Client` instances are threadsafe, but are only are fork-safe when there are no in-flight HTTP requests.
751
667
 
752
- imagekitio.create_custom_metadata_field(
753
- name: 'price',
754
- label: 'price_label',
755
- schema: {
756
- 'type': 'Number',
757
- 'minValue': 100,
758
- 'maxValue': 300
759
- }
760
- )
761
- ```
668
+ Each instance of `Imagekitio::Client` has its own HTTP connection pool with a default size of 99. As such, we recommend instantiating the client once per application in most settings.
762
669
 
763
- **Get Custom Metadata Fields**
670
+ When all available connections from the pool are checked out, requests wait for a new connection to become available, with queue time counting towards the request timeout.
764
671
 
765
- Get the custom metadata fields as per the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/get-custom-metadata-field)
672
+ Unless otherwise specified, other classes in the SDK do not have locks protecting their underlying data structure.
766
673
 
767
- ```ruby
768
- imagekitio.get_custom_metadata_fields(
769
- include_deleted: true #optional
770
- )
771
- ```
674
+ ## Sorbet
772
675
 
773
- **Update Custom Metadata Fields**
676
+ This library provides comprehensive [RBI](https://sorbet.org/docs/rbi) definitions, and has no dependency on sorbet-runtime.
774
677
 
775
- Update custom metadata fields as per the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/update-custom-metadata-field)
678
+ You can provide typesafe request parameters like so:
776
679
 
777
680
  ```ruby
778
- imagekitio.update_custom_metadata_field(
779
- id: '5e21880d5efe355febd4bccd', #field_id
780
- label: 'custom-price', #Either label or schema or both should be given
781
- schema: nil
681
+ image_kit.files.upload(
682
+ file: File.read("/path/to/file.jpg"),
683
+ file_name: "file-name.jpg"
782
684
  )
783
685
  ```
784
686
 
785
- **Delete Custom Metadata Fields**
786
-
787
- Delete custom metadata fields as per the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/delete-custom-metadata-field)
687
+ Or, equivalently:
788
688
 
789
689
  ```ruby
790
- imagekitio.delete_custom_metadata_field(
791
- id: '5e21880d5efe355febd4bccd' #field_id
690
+ # Hashes work, but are not typesafe:
691
+ image_kit.files.upload(
692
+ file: File.read("/path/to/file.jpg"),
693
+ file_name: "file-name.jpg"
792
694
  )
793
- ```
794
-
795
- ## Access request-id, other response headers and HTTP status code
796
-
797
- Each media management function returns a hash with `response`, `error`, `status_code`, `headers`, `raw_body` keys with respective values.
798
695
 
799
- ```ruby
800
- upload = imagekitio.upload_file(
801
- file: file,
802
- file_name: "default.jpg",
803
- folder: '/test',
804
- response_fields: 'tags,customCoordinates,isPrivateFile,metadata',
805
- tags: %w[abc def],
806
- use_unique_file_name: false,
807
- is_private_file: true
696
+ # You can also splat a full Params class:
697
+ params = Imagekitio::FileUploadParams.new(
698
+ file: File.read("/path/to/file.jpg"),
699
+ file_name: "file-name.jpg"
808
700
  )
809
- puts upload[:status_code] # 200
810
- puts upload[:headers]
811
-
812
- # {
813
- # "access-control-allow-origin"=>["*"],
814
- # "x-ik-requestid"=>["6963194e-014f-8945-b05a-bdb0e088f1bd"],
815
- # "content-type"=>["application/json; charset=utf-8"],
816
- # "content-length"=>["611"],
817
- # "etag"=>["W/\"859-GOeZiRFGOZERjHBgRUhG0EGcODs\""],
818
- # "date"=>["Wed, 29 Jun 2022 07:04:33 GMT"],
819
- # "x-request-id"=>["6963194e-014f-8945-b05a-bdb0e088f1bd"],
820
- # "connection"=>["close"]
821
- # }
822
-
823
-
824
- puts upload[:raw_body]
825
- # "{\"fileId\":\"62bjf980rb886bd691b86760\",\"name\":\"default.jpg\",\"size\":102117,\"versionInfo\":{\"id\":\"62bjf980rb886bd691b86760\",\"name\":\"Version 1\"},\"filePath\":\"/test/default.jpg\",\"url\":\"https://ik.imagekit.io/46865sdf6sdf/test/default.jpg\",\"fileType\":\"image\",\"height\":700,\"width\":1050,\"thumbnailUrl\":\"https://ik.imagekit.io/46865sdf6sdf/tr:n-ik_ml_thumbnail/test/default.jpg\",\"tags\":[\"abc\",\"def\"],\"AITags\":null,\"isPrivateFile\":true,\"customCoordinates\":null,\"metadata\":{\"height\":700,\"width\":1050,\"size\":102117,\"format\":\"jpg\",\"hasColorProfile\":true,\"quality\":0,\"density\":72,\"hasTransparency\":false,\"exif\":{},\"pHash\":\"90249d9b1fc74367\"}}"
701
+ image_kit.files.upload(**params)
826
702
  ```
827
703
 
828
- ## Utility functions
829
-
830
- We have included the following commonly used utility functions in this package.
831
-
832
- **Authentication parameter generation**
833
-
834
- If you are looking to implement client-side file upload, you will need a `token`, `expiry` timestamp, and a valid `signature` for that upload. The SDK provides a simple method that you can use in your code to generate these authentication parameters for you.
835
-
836
- _Note: The Private API Key should never be exposed in any client-side code. You must always generate these authentication parameters on the server-side_
837
-
838
- `authentication_parameters = imagekit.get_authentication_parameters(token, expire)`
704
+ ### Enums
839
705
 
840
- Returns
706
+ Since this library does not depend on `sorbet-runtime`, it cannot provide [`T::Enum`](https://sorbet.org/docs/tenum) instances. Instead, we provide "tagged symbols" instead, which is always a primitive at runtime:
841
707
 
842
708
  ```ruby
843
- {
844
- "token": "unique_token",
845
- "expire": "valid_expiry_timestamp",
846
- "signature": "generated_signature"
847
- }
848
- ```
849
-
850
- Both the `token` and `expire` parameters are optional. If not specified, the SDK uses the uuid to generate a random token and also generates a valid expiry timestamp internally. The value of the `token` and `expire` used to generate the signature is always returned in the response, no matter if they are provided as an input to this method or not.
851
-
852
- **Distance calculation between two pHash values**
853
-
854
- Perceptual hashing allows you to construct a hash value that uniquely identifies an input image based on the contents
855
- of an image. [imagekit.io metadata API](https://docs.imagekit.io/api-reference/metadata-api) returns the pHash
856
- value of an image in the response. You can use this value to find a duplicate near the duplicate(similar) image by calculating
857
- the distance between the two images.
858
-
859
-
860
- This SDK exposes the `phash_distance` function to calculate the distance between two pHash values. It accepts two pHash hexadecimal
861
- strings and returns a numeric value indicative of the level of difference between the two images.
709
+ # :all
710
+ puts(Imagekitio::AssetListParams::FileType::ALL)
862
711
 
863
- ```ruby
864
- def calculate_distance():
865
- # fetch metadata of two uploaded image files
866
- ...
867
- # extract pHash strings from both: say 'first_hash' and 'second_hash.'
868
- ...
869
- # calculate the distance between them:
870
-
871
- distance = imagekitio.phash_distance(first_hash, second_hash)
872
- return distance
712
+ # Revealed type: `T.all(Imagekitio::AssetListParams::FileType, Symbol)`
713
+ T.reveal_type(Imagekitio::AssetListParams::FileType::ALL)
873
714
  ```
874
715
 
875
- **Distance calculation examples**
716
+ Enum parameters have a "relaxed" type, so you can either pass in enum constants or their literal value:
876
717
 
877
718
  ```ruby
878
- imagekitio.phash_distance('f06830ca9f1e3e90', 'f06830ca9f1e3e90')
879
- # output: 0 (ame image)
880
-
881
- imagekitio.phash_distance('2d5ad3936d2e015b', '2d6ed293db36a4fb')
882
- # output: 17 (similar images)
719
+ # Using the enum constants preserves the tagged type information:
720
+ image_kit.assets.list(
721
+ file_type: Imagekitio::AssetListParams::FileType::ALL,
722
+ #
723
+ )
883
724
 
884
- imagekitio.phash_distance('a4a65595ac94518b', '7838873e791f8400')
885
- # output: 37 (dissimilar images)
725
+ # Literal values are also permissible:
726
+ image_kit.assets.list(
727
+ file_type: :all,
728
+ # …
729
+ )
886
730
  ```
887
731
 
888
- ## Sample Application
889
- There are three sample apps:
890
-
891
- * Rails application using Carrierwave
892
- * Rails application using ActiveStorage
893
- * Plain ruby application
894
-
895
- Please see the sample applications in [here](https://github.com/imagekit-samples/quickstart).
732
+ ## Versioning
896
733
 
897
- ## Upgrade to 2.x
734
+ This package follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions. As the library is in initial development and has a major version of `0`, APIs may change at any time.
898
735
 
899
- If you are upgrading to 2.x from version 1.x, make the following changes in your application:
736
+ This package considers improvements to the (non-runtime) `*.rbi` and `*.rbs` type definitions to be non-breaking changes.
900
737
 
901
- - Remove config from environment file to initializer file as described [here](#Initialization).
902
- - Include `ImageKitIo::CarrierWave` in uploader class(for Carrierwave).
903
- - Remove `storage :imagekit_store` config from uploader.
904
- - Rename class `ImageKit::ImageKitClient` to `ImageKitIo::Client`
905
- - Rename class `ImageKitIo::ImageKitRequest` to `ImageKitIo::Request`
738
+ ## Requirements
906
739
 
907
- ## Support
908
- For any feedback or to report any issues or general implementation support, please reach out to [support@imagekit.io](mailto:support@imagekit.io)
740
+ Ruby 3.2.0 or higher.
909
741
 
910
- ## Links
911
- - [Documentation](https://docs.imagekit.io)
912
- - [Main website](https://imagekit.io)
742
+ ## Contributing
913
743
 
914
- ## License
915
- Released under the MIT license.
744
+ See [the contributing documentation](https://github.com/imagekit-developer/imagekit-ruby/tree/master/CONTRIBUTING.md).