imagekitio 1.0.10 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +292 -82
  3. data/Rakefile +1 -1
  4. data/lib/active_storage/active_storage.rb +2 -0
  5. data/lib/active_storage/service/ik_file.rb +111 -0
  6. data/lib/active_storage/service/image_kit_io_service.rb +185 -0
  7. data/lib/carrierwave/carrierwave.rb +79 -0
  8. data/lib/carrierwave/storage/ik_file.rb +8 -7
  9. data/lib/carrierwave/storage/imagekit_store.rb +54 -51
  10. data/lib/carrierwave/support/uri_filename.rb +9 -7
  11. data/lib/imagekitio/api_service/bulk.rb +58 -0
  12. data/lib/imagekitio/api_service/custom_metadata_field.rb +52 -0
  13. data/lib/imagekitio/api_service/file.rb +162 -0
  14. data/lib/imagekitio/api_service/folder.rb +49 -0
  15. data/lib/imagekitio/base.rb +12 -0
  16. data/lib/imagekitio/client.rb +186 -0
  17. data/lib/imagekitio/configurable.rb +43 -0
  18. data/lib/imagekitio/constant.rb +36 -0
  19. data/lib/imagekitio/constants/default.rb +22 -0
  20. data/lib/imagekitio/constants/error.rb +69 -0
  21. data/lib/imagekitio/constants/file.rb +11 -0
  22. data/lib/imagekitio/constants/supported_transformation.rb +64 -0
  23. data/lib/imagekitio/constants/url.rb +14 -0
  24. data/lib/imagekitio/errors.rb +4 -0
  25. data/lib/imagekitio/railtie.rb +1 -1
  26. data/lib/imagekitio/request.rb +79 -0
  27. data/lib/imagekitio/sdk/version.rb +5 -0
  28. data/lib/imagekitio/url.rb +241 -0
  29. data/lib/imagekitio/utils/calculation.rb +44 -0
  30. data/lib/imagekitio/utils/formatter.rb +48 -0
  31. data/lib/imagekitio/utils/option_validator.rb +36 -0
  32. data/lib/imagekitio.rb +10 -83
  33. metadata +41 -15
  34. data/lib/imagekit/constants/defaults.rb +0 -20
  35. data/lib/imagekit/constants/errors.rb +0 -77
  36. data/lib/imagekit/constants/file.rb +0 -5
  37. data/lib/imagekit/constants/supported_transformation.rb +0 -57
  38. data/lib/imagekit/constants/url.rb +0 -9
  39. data/lib/imagekit/file.rb +0 -133
  40. data/lib/imagekit/imagekit.rb +0 -117
  41. data/lib/imagekit/resource.rb +0 -56
  42. data/lib/imagekit/sdk/version.rb +0 -5
  43. data/lib/imagekit/url.rb +0 -237
  44. data/lib/imagekit/utils/calculation.rb +0 -36
  45. data/lib/imagekit/utils/formatter.rb +0 -29
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87a2428b4fd13858eb5789ebb281e06c9c26ee27b9d005f13eccde8766cae28a
4
- data.tar.gz: ba2dff578f285e9fc847e4cdcb941a4a0764387280122ff7e391b7b66de38b97
3
+ metadata.gz: f16b0137caabb312f3f4dea41a5558075f6ee24032b733fd4ce986807f695fbf
4
+ data.tar.gz: 50bc622d4cd9042275cbb1c21920fb371f28ba046fcbd76b74099b288a74227a
5
5
  SHA512:
6
- metadata.gz: b2b9203c579831c6c127a480100f16ee88b90aab79d5a6e2f0a50dbf2d5908fcbcabdbbeb8adff2d8f99aedf5ca0cdcbbee76c4989a81cb64d1b717827c5cfd9
7
- data.tar.gz: 79641251a3cb02c69d999b8c3cc3237e59748abca67f3ba00807d8e2ef938fe52bc743e00bdec3191515b350d33f7e35bdc94bba593453f52a2448d3cf8fd64e
6
+ metadata.gz: e73e581e5709d7ac0de28d6ca9276fea1931b47a1e88595a67fcdb51ee654deed3e6b3aac208198432385c5e2f64c3ea765f366033dd678017fc9fda73d80933
7
+ data.tar.gz: 0aad82e39f813c480edfeffaf10401bf90aa935b09cc313ddd48a05dc4f51b666074d1e28033398255a807ed40a0f2ac4d42d4b9bfa3571cdc2e706b70f0a846
data/README.md CHANGED
@@ -13,11 +13,14 @@ ImageKit gem for Ruby on Rails that allows you to use real-time [image resizing]
13
13
  Table of contents -
14
14
  * [Installation](#Installation)
15
15
  * [Initialization](#Initialization)
16
+ - [CarrierWave](#Carrierwave-config)
17
+ - [ActiveStorage](#ActiveStorage-config)
16
18
  * [URL Generation](#URL-generation)
17
19
  * [File Upload](#File-Upload)
18
20
  * [File Management](#File-Management)
19
21
  * [Utility Functions](#Utility-functions)
20
22
  * [Sample applications](#Sample-Application)
23
+ * [Upgrade to 2.0.0](#Upgrade)
21
24
  * [Support](#Support)
22
25
  * [Links](#Links)
23
26
 
@@ -45,17 +48,21 @@ $ gem install imagekitio
45
48
 
46
49
  ## Initialization
47
50
 
48
- Add this configuration to `config/environments/development.rb` and `config/environments/production.rb`
49
-
51
+ Create a new file `config/initializers/imagekitio.rb` then add the configuration.
50
52
  ```ruby
51
- config.imagekit={
52
- private_key: "<your-private-key>",
53
- public_key: "<your-public-key>",
54
- url_endpoint: "<endpoint-url>"
55
- }
53
+ ImageKitIo.configure do |config|
54
+ if Rails.env.development?
55
+ config.public_key = 'your_public_api_key'
56
+ config.private_key = 'your_private_api_key'
57
+ config.url_endpoint = 'https://ik.imagekit.io/your_imagekit_id/'
58
+ end
59
+ config.service = :carrierwave
60
+ #config.service = :active_storage
61
+ #config.constants.MISSING_PRIVATE_KEY = 'custom error message'
62
+ end
56
63
  ```
57
-
58
- You can create a carrierwave uploader in order to attach pictures to your database objects as their attributes. To upload images without designating them as database attributes, skip to [this section](https://github.com/imagekit-developer/imagekit-ruby#file-upload).
64
+ #### CarrierWave
65
+ 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).
59
66
 
60
67
  ```bash
61
68
  rails g uploader <Uploading_attribute_name>
@@ -66,8 +73,8 @@ rails g uploader Avatar
66
73
 
67
74
  After that, you need to edit your generated uploader and make the following changes:
68
75
  ```ruby
69
- # Set store as imagekit_store
70
- storage :imagekit_store
76
+ # include this module inside the top of the uploader class
77
+ include ImageKitIo::CarrierWave
71
78
 
72
79
  # If you want to add uploading options, then create this method inside the uploader file as an example
73
80
 
@@ -103,14 +110,52 @@ Get image url:
103
110
  # To get the original image url, use
104
111
  @employee.avatar.url
105
112
 
113
+ # To get the file metadata
114
+ @employee.avatar.metadata
115
+
116
+
106
117
  # And to get transformed url use
107
118
  # options is a transformation options
108
119
  @employee.avatar.url_with(options)
109
120
  ```
110
121
 
122
+ #### ActiveStorage
123
+
124
+ 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:
125
+
126
+ ```ruby
127
+ class Employee < ApplicationRecord
128
+ has_one_attached :avatar
129
+ end
130
+ ```
131
+
132
+ Get image url:
133
+ ```ruby
134
+ # If @employee is an object of your model that has data.
135
+
136
+ # To get the original image url, use
137
+ @employee.avatar.url
138
+ ```
139
+
140
+ Now, let's configure active_storage as a service for the imagekitio.
141
+
142
+ First add `:active_storage` in initializer file.
143
+
144
+ ```ruby
145
+ config.service = :active_storage
146
+ ```
147
+
148
+ Then add the imagekitio service in the `storage.yml` file:
149
+
150
+ ```ruby
151
+ imagekitio:
152
+ service: ImageKitIo
153
+ ```
154
+
155
+
111
156
  ## Usage
112
157
 
113
- You can use this Ruby SDK for three different kinds of methods - URL generation, file upload, and file management.
158
+ You can use this Ruby SDK for three different methods - URL generation, file upload, and file management.
114
159
 
115
160
  The usage of the SDK has been explained below.
116
161
 
@@ -126,21 +171,21 @@ about paths with different kinds of origins.
126
171
 
127
172
 
128
173
  ```ruby
174
+ imagekitio = ImageKitIo.client
129
175
  image_url = imagekitio.url({
130
176
  path: "/default-image.jpg",
131
177
  url_endpoint: "https://ik.imagekit.io/your_imagekit_id/endpoint/",
132
- transformation: [{height: "300", width: "400"}]
178
+ transformation: [{height: "300", width: "400", raw: "ar-4-3,q-40"}]
133
179
  })
134
180
  ```
135
181
 
136
182
  The result in a URL like
137
183
  ```
138
- https://ik.imagekit.io/your_imagekit_id/endpoint/tr:h-300,w-400/default-image.jpg
184
+ https://ik.imagekit.io/your_imagekit_id/endpoint/tr:h-300,w-400,ar-4-3,q-40/default-image.jpg
139
185
  ```
140
186
 
141
187
  **2.Using full image URL**
142
- This method allows you to add transformation parameters to an existing, complete URL that is already mapped to ImageKit
143
- using `src` parameter. This method should be used if you have the complete image URL mapped to ImageKit stored in your
188
+ This method allows you to add transformation parameters to an existing, complete URL already mapped to ImageKit using the `src` parameter. This method should be used if you have the complete image URL mapped to ImageKit stored in your
144
189
  database.
145
190
 
146
191
 
@@ -167,7 +212,7 @@ The `.url()` method accepts the following parameters
167
212
  | 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. |
168
213
  | 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. |
169
214
  | 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. |
170
- | 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 parameter to your URLs. |
215
+ | 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. |
171
216
  | 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. |
172
217
  | 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. |
173
218
 
@@ -243,8 +288,10 @@ https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400/default-image.jpg?v=123&i
243
288
 
244
289
  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).
245
290
  The SDK gives a name to each transformation parameter, making the code simpler, making the code simpler, and readable.
246
- If a transformation is supported in ImageKit, but a name for it cannot be found in the table below, then use the
247
- transformation code from ImageKit docs as the name when using the `url` function.
291
+
292
+ 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.
293
+
294
+ If you want to generate transformations in your application and add them to the URL as it is, use the `raw` parameter.
248
295
 
249
296
  | Supported Transformation Name | Translates to parameter |
250
297
  |-------------------------------|-------------------------|
@@ -304,6 +351,7 @@ transformation code from ImageKit docs as the name when using the `url` function
304
351
  | effectContrast | e-contrast |
305
352
  | effectGray | e-grayscale |
306
353
  | original | orig |
354
+ | raw | `replaced by the parameter value` |
307
355
 
308
356
  ## File Upload
309
357
  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.
@@ -319,9 +367,11 @@ Simple usage
319
367
 
320
368
  ```ruby
321
369
  imagekitio.upload_file(
322
- file = "<url|base_64|binary>", # required
323
- file_name= "my_file_name.jpg", # required
324
- options= {response_fields: 'isPrivateFile, tags', tags: %w[abc def], use_unique_file_name: true,}
370
+ file: "<url|base_64|binary>", # required
371
+ file_name: "my_file_name.jpg", # required
372
+ response_fields: 'isPrivateFile, tags',
373
+ tags: %w[abc def],
374
+ use_unique_file_name: true
325
375
  )
326
376
 
327
377
  ```
@@ -342,26 +392,35 @@ in the [documentation here](https://docs.imagekit.io/api-reference/media-api/lis
342
392
  correct values to get the results.
343
393
 
344
394
  ```ruby
345
- imagekitio.list_files({skip: 0, limit: 5})
395
+ imagekitio.list_files(
396
+ skip: 0,
397
+ limit: 5
398
+ )
346
399
  ```
347
400
  **2. Get File Details**
348
401
  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)
349
402
 
350
403
  ```ruby
351
- imagekitio.get_file_details(file_id)
404
+ imagekitio.get_file_details(
405
+ file_id: '598821f949c0a938d57563bd'
406
+ )
352
407
  ```
353
408
 
354
409
  **3. Get File Metadata**
355
410
  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)
356
411
  ```ruby
357
- imagekit.get_file_metadata(file_id)
412
+ imagekit.get_file_metadata(
413
+ file_id: '598821f949c0a938d57563bd'
414
+ )
358
415
  ```
359
416
 
360
417
  **3. Get File Metadata from remote url**
361
418
  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)
362
419
 
363
420
  ```ruby
364
- imagekit.get_remote_file_url_metadata(remote_file_url)
421
+ imagekit.get_remote_file_url_metadata(
422
+ remote_file_url: "https://ik.imagekit.io/demo/tr:w-100/default-image.jpg"
423
+ )
365
424
  ```
366
425
 
367
426
  **4. Update File Details**
@@ -370,50 +429,230 @@ The first argument to the `update_field_details` method is the file ID, and a se
370
429
  parameters to be updated.
371
430
 
372
431
  ```ruby
373
- imagekitio.update_file_details(file_id, {
432
+ imagekitio.update_file_details(
433
+ file_id: '598821f949c0a938d57563bd',
374
434
  tags: ["image_tag"],
375
435
  custom_coordinates: "10,10,100, 100"
376
- })
436
+ )
377
437
  ```
378
438
 
379
- **6. Delete file**
439
+ **5. Copy File**
440
+
441
+ 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)
442
+
443
+ ```ruby
444
+ imagekitio.copy_file(
445
+ source_file_path: '/path/to/file.jpg',
446
+ destination_path: '/folder/to/copy/into'
447
+ )
448
+ ```
449
+
450
+ **6. Move File**
451
+
452
+ 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)
453
+
454
+ ```ruby
455
+ imagekitio.move_file(
456
+ source_file_path: '/path/to/file.jpg',
457
+ destination_path: '/folder/to/move/into/'
458
+ )
459
+ ```
460
+
461
+ **7. Rename File**
462
+
463
+ Rename file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/rename-file)
464
+
465
+ ```ruby
466
+ imagekitio.rename_file(
467
+ file_path: '/path/to/old-file-name.jpg',
468
+ new_file_name: 'new-file-name.jpg',
469
+ purge_cache: true #optional
470
+ )
471
+ ```
472
+
473
+ **8. Delete file**
380
474
  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.
381
475
 
382
476
  ```ruby
383
- imagekitio.delete_file(file_id)
477
+ imagekitio.delete_file(
478
+ file_id: '598821f949c0a938d57563bd'
479
+ )
384
480
  ```
385
481
 
386
- **6. Bulk File Delete by IDs**
482
+ **9. Bulk File Delete by IDs**
387
483
  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
388
484
  deleted.
389
485
 
390
486
  ```ruby
391
- imagekitio.bulk_file_delete(["file_id1", "file_id2"])
487
+ imagekitio.delete_bulk_files(
488
+ file_ids: ["598821f949c0a938d57563bd", "598821f949c0a938d57543bd"]
489
+ )
392
490
  ```
393
491
 
394
- **6. Purge Cache**
395
- Programmatically issue a cache clear request as pet the [API documentation here](https://docs.imagekit.io/api-reference/media-api/purge-cache).
492
+ **10. Purge Cache**
493
+ Programmatically issue a clear cache request as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/purge-cache).
396
494
  Accepts the full URL of the file for which the cache has to be cleared.
397
495
 
398
496
  ```ruby
399
- imagekitio.purge_file_cache(full_url)
497
+ imagekitio.purge_file_cache(
498
+ file_url: 'https://ik.imagekit.io/demo/logo-white_SJwqB4Nfe.png'
499
+ )
400
500
  ```
401
- **7. Purge Cache Status**
501
+ **11. Purge Cache Status**
402
502
 
403
- Get the purge cache request status using the request ID returned when a purge cache request gets submitted as pet the
503
+ Get the purge cache request status using the request ID returned when a purge cache request gets submitted as per the
404
504
  [API documentation here](https://docs.imagekit.io/api-reference/media-api/purge-cache-status)
405
505
 
406
506
  ```ruby
407
- imagekitio.get_purge_file_cache_status(cache_request_id)
507
+ imagekitio.purge_file_cache_status(
508
+ request_id: '598821f949c0a938d57543bd'
509
+ )
510
+ ```
511
+
512
+ **12. Add Bulk Tags**
513
+
514
+ 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)
515
+
516
+ ```ruby
517
+ imagekitio.add_bulk_tags(
518
+ file_ids: ['598821f949c0a938d57543bd', '598921f949c0a938d57543bd'],
519
+ tags: ['custom_tags', 'image', 'favourite']
520
+ )
521
+ ```
522
+
523
+ **13. Delete Bulk Tags**
524
+
525
+ 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)
526
+
527
+ ```ruby
528
+ imagekitio.delete_bulk_tags(
529
+ file_ids: ['598821f949c0a938d57543bd', '598921f949c0a938d57543bd'],
530
+ tags: ['custom_tags', 'image']
531
+ )
532
+ ```
533
+
534
+ **14. Delete Bulk Ai Tags**
535
+
536
+ Delete bulk ai tags as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/remove-aitags-bulk)
537
+
538
+ ```ruby
539
+ imagekitio.delete_bulk_ai_tags(
540
+ file_ids: ['598821f949c0a938d57543bd', '598921f949c0a938d57543bd'],
541
+ ai_tags: ['custom_ai_tags']
542
+ )
543
+ ```
544
+
545
+ **15. Create Folder**
546
+
547
+ Create folder as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/create-folder)
548
+
549
+ ```ruby
550
+ imagekitio.create_folder(
551
+ folder_name: 'new_folder',
552
+ parent_folder_path: 'source/folder/path' #optional
553
+ )
554
+ ```
555
+
556
+
557
+ **16. Copy Folder**
558
+
559
+ Copy folder as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-folder)
560
+
561
+ ```ruby
562
+ imagekitio.copy_folder(
563
+ source_folder_path: '/folder/to/copy',
564
+ destination_path: '/folder/to/copy/into'
565
+ )
566
+ ```
567
+
568
+ **17. Move Folder**
569
+
570
+ Move folder as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/move-folder)
571
+
572
+ ```ruby
573
+ imagekitio.move_folder(
574
+ source_folder_path: '/folder/to/move',
575
+ destination_path: '/folder/to/move/into/'
576
+ )
577
+ ```
578
+
579
+ **18. Delete Folder**
580
+
581
+ Delete folder as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/delete-folder)
582
+
583
+ ```ruby
584
+ imagekitio.delete_folder(
585
+ folder_path: 'folder/to/delete'
586
+ )
408
587
  ```
409
588
 
589
+ **19. Bulk Job Status**
590
+
591
+ Get the bulk job status as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/copy-move-folder-status)
592
+
593
+ ```ruby
594
+ imagekitio.bulk_job_status(
595
+ job_id: '5e21880d5efe355febd4cccd'
596
+ )
597
+ ```
598
+
599
+ **20. Create Custom Metadata Fields**
600
+
601
+ Create custom metadata fields as per the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/create-custom-metadata-field)
602
+
603
+ ```ruby
604
+
605
+ imagekitio.create_custom_metadata_field(
606
+ name: 'price',
607
+ label: 'price_label',
608
+ schema: {
609
+ 'type': 'Number',
610
+ 'minValue': 100,
611
+ 'maxValue': 300
612
+ }
613
+ )
614
+ ```
615
+
616
+ **21. Get Custom Metadata Fields**
617
+
618
+ 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)
619
+
620
+ ```ruby
621
+ imagekitio.get_custom_metadata_fields(
622
+ include_deleted: true #optional
623
+ )
624
+ ```
625
+
626
+ **22. Update Custom Metadata Fields**
627
+
628
+ Update custom metadata fields as per the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/update-custom-metadata-field)
629
+
630
+ ```ruby
631
+ imagekitio.update_custom_metadata_field(
632
+ id: '5e21880d5efe355febd4bccd', #field_id
633
+ label: 'custom-price', #Either label or schema or both should be given
634
+ schema: nil
635
+ )
636
+ ```
637
+
638
+ **23. Delete Custom Metadata Fields**
639
+
640
+ Delete custom metadata fields as per the [API documentation here](https://docs.imagekit.io/api-reference/custom-metadata-fields-api/delete-custom-metadata-field)
641
+
642
+ ```ruby
643
+ imagekitio.delete_custom_metadata_field(
644
+ id: '5e21880d5efe355febd4bccd' #field_id
645
+ )
646
+ ```
647
+
648
+
410
649
  ## Utility functions
411
650
 
412
651
  We have included the following commonly used utility functions in this package.
413
652
 
414
653
  **Authentication parameter generation**
415
654
 
416
- In case you are looking to implement client-side file upload, you are going to 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.
655
+ 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.
417
656
 
418
657
  _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_
419
658
 
@@ -439,7 +678,7 @@ value of an image in the response. You can use this value to find a duplicate ne
439
678
  the distance between the two images.
440
679
 
441
680
 
442
- This SDK exposes the `phash_distance` function to calculate the distance between two pHash value. It accepts two pHash hexadecimal
681
+ This SDK exposes the `phash_distance` function to calculate the distance between two pHash values. It accepts two pHash hexadecimal
443
682
  strings and returns a numeric value indicative of the level of difference between the two images.
444
683
 
445
684
  ```ruby
@@ -468,52 +707,23 @@ imagekitio.phash_distance('a4a65595ac94518b', '7838873e791f8400')
468
707
  ```
469
708
 
470
709
  ## Sample Application
471
- There are two sample apps:
472
- * [Rails application using Carrierwave](#Instructions-for-rails-application)
473
- * [Plain ruby application](#Instructions-for-ruby-application)
710
+ There are three sample apps:
474
711
 
475
- ### Instructions for a rails application
476
- This is under [samples/rails_app](https://github.com/imagekit-developer/imagekit-ruby/blob/master/samples/rails_app) directory. Follow the instructions below to set up a rails application.
712
+ * Rails application using Carrierwave
713
+ * Rails application using ActiveStorage
714
+ * Plain ruby application
477
715
 
478
- **1. Clone git repository**
479
- ```bash
480
- git clone `https://github.com/imagekit-developer/imagekit-gem
481
- ```
482
- **2. Go to sample project directory**
483
- ```bash
484
- cd sample/rails_app
485
- ```
486
- **3. Write imagekit configuration in `config/environments/development.rb`**
487
- ```ruby
488
- config.imagekit={
489
- private_key: "<your-private-key>",
490
- public_key: "<your-public-key>",
491
- url_endpoint: "<endpoint-url>"
492
- }
493
- ```
494
- **4. Install dependency**
495
- ```ruby
496
- bundle install
497
- ```
498
- This sample project is using the Sqlite3 database. If you are getting `sqlite3` gem installation error, then install sqlite3 first, then again run `bundle install`.
716
+ Please see the sample applications in [here](https://github.com/imagekit-samples/quickstart).
499
717
 
500
- **5. Migrate the database**
501
- ```ruby
502
- bundle exec rake db:migrate
503
- ```
718
+ ## Upgrade to 2.0.0
504
719
 
505
- **6. Run your application**
506
- ```ruby
507
- rails s
508
- ```
509
- It will run on your default rails port [3000].
510
- Sample Application URL: http://localhost:3000/posts/
720
+ If you are upgrading to 2.0.0 from version 1.x, make the following changes in your application:
511
721
 
512
- ### Instructions for ruby application
513
- Run following command under [samples/ruby_app](https://github.com/imagekit-developer/imagekit-ruby/blob/master/samples/ruby_app) directory
514
- ```ruby
515
- ruby app.rb
516
- ```
722
+ - Remove config from environment file to initializer file as described [here](#Initialization).
723
+ - Include `ImageKitIo::CarrierWave` in uploader class(for Carrierwave).
724
+ - Remove `storage :imagekit_store` config from uploader.
725
+ - Rename class `ImageKit::ImageKitClient` to `ImageKitIo::Client`
726
+ - Rename class `ImageKitIo::ImageKitRequest` to `ImageKitIo::Request`
517
727
 
518
728
  ## Support
519
729
  For any feedback or to report any issues or general implementation support, please reach out to [support@imagekit.io](mailto:support@imagekit.io)
@@ -523,4 +733,4 @@ For any feedback or to report any issues or general implementation support, plea
523
733
  - [Main website](https://imagekit.io)
524
734
 
525
735
  ## License
526
- Released under the MIT license.
736
+ Released under the MIT license.
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ require 'rdoc/task'
8
8
 
9
9
  RDoc::Task.new(:rdoc) do |rdoc|
10
10
  rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'Imagekit::Sdk'
11
+ rdoc.title = 'ImageKitIo::Sdk'
12
12
  rdoc.options << '--line-numbers'
13
13
  rdoc.rdoc_files.include('README.md')
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
@@ -0,0 +1,2 @@
1
+ require_relative './service/ik_file'
2
+ require_relative './service/image_kit_io_service'
@@ -0,0 +1,111 @@
1
+ module ImageKiIo
2
+ module ActiveStorage
3
+ class IKFile
4
+ attr_accessor :identifier
5
+
6
+ def initialize(identifier)
7
+ @identifier = identifier
8
+ @imagekit = ImageKitIo.client
9
+ end
10
+
11
+ def url
12
+ identifier['url']
13
+ end
14
+
15
+ def delete
16
+ begin
17
+ @imagekit.delete_file(file_id: file_id)
18
+ rescue
19
+ file_id
20
+ end
21
+ end
22
+
23
+ def file_type
24
+ identifier['fileType']
25
+ end
26
+
27
+ def thumbnail_url
28
+ identifier['thumbnail']
29
+ end
30
+
31
+ def filename
32
+ identifier['name']
33
+ end
34
+
35
+ def size
36
+ identifier['size']
37
+ end
38
+
39
+ def path
40
+ identifier['filePath']
41
+ end
42
+
43
+ def height
44
+ identifier['height']
45
+ end
46
+
47
+ def width
48
+ identifier['width']
49
+ end
50
+
51
+ def file_id
52
+ identifier['fileId']
53
+ end
54
+
55
+ def exist?
56
+ details = @imagekit.get_file_details(file_id: file_id)
57
+ return false if details[:error].present?
58
+
59
+ true
60
+ end
61
+
62
+ def type
63
+ identifier['type']
64
+ end
65
+
66
+ def tags
67
+ identifier['tags']
68
+ end
69
+
70
+ def ai_tags
71
+ identifier['AITags']
72
+ end
73
+
74
+ def is_private?
75
+ identifier['isPrivateFile']
76
+ end
77
+
78
+ def custom_coordinates
79
+ identifier['customCoordinates']
80
+ end
81
+
82
+ def mime
83
+ identifier['mime']
84
+ end
85
+
86
+ def alpha?
87
+ identifier['hasAlpha']
88
+ end
89
+
90
+ def custom_metadata
91
+ identifier['customMetadata']
92
+ end
93
+
94
+ def embedded_metadata
95
+ identifier['embeddedMetadata']
96
+ end
97
+
98
+ def created_at
99
+ identifier['createdAt']
100
+ end
101
+
102
+ def updated_at
103
+ identifier['updatedAt']
104
+ end
105
+
106
+ def extension_status
107
+ identifier['extensionStatus']
108
+ end
109
+ end
110
+ end
111
+ end