imagekitio 1.0.4 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 924d22974f5d592ea0f933077b74a4d37b133be8cd9b450d8b1182adeaa3e58d
4
- data.tar.gz: 1da1eab20f6424f07c018b6374eefe786dac87b7913e46b27b37b244316ddeed
3
+ metadata.gz: 8f4c1378d734792764be12a017096faf02b19b25ffd17e71967b83a11a4d9b43
4
+ data.tar.gz: c2e57147a07ee8372fbbc9ef6f4a65d5d06cda3378a06fc3671902bec470e366
5
5
  SHA512:
6
- metadata.gz: b62b075781bec1c3eae66f5b8090091b42dccf8239a5a81472c78b0a50713bf5d8e573d19671df9de37f2cab5cf190db04b6b5eb7d87fbf1f167e4f72c328821
7
- data.tar.gz: a897fb5d01d78e5162125ebfb751f441a113a6b3f1a9950384e740965cd4cb9201e2644231f275ee55dd89ae74d619b51fb456fe76722017df89e3f545c9611b
6
+ metadata.gz: 75fbd6009d4875bf9e56ebad657898d69e96aa88835972649477cfc3c4aaff98c1dcb1ec41d9026ce5d2626ce7a83913e5e590fb30c504e6f741b65e974c463a
7
+ data.tar.gz: 111fdba2d869e92b4e01bc58184b189b4120e2ecbec444b326157ed638e28e4078d0fd831fe5a5efb56cd4ecf403dd6c8c259556bdc58d627e94662905608c67
data/README.md CHANGED
@@ -1,23 +1,33 @@
1
- # Imagekit
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
2
4
 
3
5
  [![Ruby Test](https://github.com/imagekit-developer/imagekit-ruby/workflows/Ruby%20Test/badge.svg)](https://github.com/imagekit-developer/imagekit-ruby)
4
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)
5
8
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
9
  [![Twitter Follow](https://img.shields.io/twitter/follow/imagekitio?label=Follow&style=social)](https://twitter.com/ImagekitIo)
7
10
 
8
- ## Installation
11
+ ImageKit gem for Ruby on Rails that allows you to use real-time [image resizing](https://docs.imagekit.io/features/image-transformations), [optimization](https://docs.imagekit.io/features/image-optimization), and [file uploading](https://docs.imagekit.io/api-reference/upload-file-api/).
12
+
13
+ Table of contents -
14
+ * [Installation](#Installation)
15
+ * [Initialization](#Initialization)
16
+ * [URL Generation](#URL-generation)
17
+ * [File Upload](#File-Upload)
18
+ * [File Management](#File-Management)
19
+ * [Utility Functions](#Utility-functions)
20
+ * [Sample applications](#Sample-Application)
21
+ * [Support](#Support)
22
+ * [Links](#Links)
9
23
 
10
- If you want to create new rails application, then use this command
11
24
 
12
- ```bash
13
- # New application with default Sqlite3 database
14
- rails new <your_application_name>
25
+ # Quick start guide
26
+ Get started with [official quick start guide](https://docs.imagekit.io/getting-started/quickstart-guides/ruby-on-rails) for integrating ImageKit in Ruby on Rails.
15
27
 
16
- # New application with specific database
17
- rails new <your_application_name> -d <database_name>
18
- ```
28
+ ## Installation
19
29
 
20
- Add this dependency to your application's Gemfile:
30
+ Add `imagekitio` dependency to your application's Gemfile:
21
31
 
22
32
  ```ruby
23
33
  gem 'imagekitio'
@@ -27,29 +37,11 @@ And then execute:
27
37
  ```
28
38
  $ bundle install
29
39
  ```
30
- Or install it yourself as:
40
+
41
+ Or install it yourself:
31
42
  ```
32
43
  $ gem install imagekitio
33
44
  ```
34
- ## Usage
35
-
36
- Rails SDK for [ImageKit](https://imagekit.io/) that implements the new APIs and interface for performing different file operations.
37
-
38
- ImageKit is a complete image optimization and transformation solution that comes with and
39
- [image CDN](https://imagekit.io/features/imagekit-infrastructure) and media storage. It can be integrated with your
40
- existing infrastructure - storage like AWS s3, web servers, your CDN, and custom domain names, allowing you to deliver
41
- optimize images in minutes with minimal code changes.
42
-
43
- Table of contents -
44
- * [Installation](#Installation)
45
- * [Initialization](#Initialization)
46
- * [URL Generation](#URL-generation)
47
- * [File Upload](#File-Upload)
48
- * [File Management](#File-Management)
49
- * [Utility Functions](#Utility-functions)
50
- * [Support](#Support)
51
- * [Links](#Links)
52
-
53
45
 
54
46
  ## Initialization
55
47
 
@@ -63,45 +55,52 @@ config.imagekit={
63
55
  }
64
56
  ```
65
57
 
66
- You need to create an uploader to manage file. To create an uploader, use this command inside the project directory.
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).
59
+
67
60
  ```bash
68
61
  rails g uploader <Uploading_attribute_name>
69
- # For example if you want to create uploader for Avatar attribute then use
62
+ # For example, if you want to create an uploader for Avatar attribute, then use
70
63
  rails g uploader Avatar
71
64
  # Generated uploader's path will be app/uploaders/avatar_uploader.rb
72
65
  ```
73
66
 
74
- After that you need to edit your generated uploader and do the following changes:
67
+ After that, you need to edit your generated uploader and make the following changes:
75
68
  ```ruby
76
69
  # Set store as imagekit_store
77
70
  storage :imagekit_store
78
71
 
79
- # If you want to add uploading options then create this method inside uploader file as an example
72
+ # If you want to add uploading options, then create this method inside the uploader file as an example
80
73
 
81
74
  def options
82
75
  options={
83
76
  response_fields: 'isPrivateFile, tags',
84
77
  tags: %w[abc def],
85
- use_unique_file_name: false
78
+ use_unique_file_name: false,
79
+ folder: "your_directory/"
86
80
  }
87
81
  end
82
+
83
+ # If you want to set upload dir, then you can use the following method, or you can also use the options method.
84
+ # This method should return a string
85
+ def store_dir
86
+ "your_directory/"
87
+ end
88
88
  ```
89
89
 
90
- Then you need to modify your model. for example- if your model name is employee then do these changes
90
+ Then you need to modify your model. for example- if your model name is employee, then do these changes.
91
91
 
92
92
  ```ruby
93
93
  class Employee < ApplicationRecord
94
94
  attr_accessor :avatar
95
95
  mount_uploader :avatar, AvatarUploader
96
96
  end
97
-
98
97
  ```
99
98
 
100
99
  Get image url:
101
100
  ```ruby
102
101
  # If @employee is an object of your model that has data.
103
102
 
104
- # To get original image url use
103
+ # To get the original image url, use
105
104
  @employee.avatar.url
106
105
 
107
106
  # And to get transformed url use
@@ -111,8 +110,9 @@ Get image url:
111
110
 
112
111
  ## Usage
113
112
 
114
- You can use this Ruby SDK for 3 different kinds of methods - URL generation, file upload, and file management.
115
- The usage of the SDK has been explained below
113
+ You can use this Ruby SDK for three different kinds of methods - URL generation, file upload, and file management.
114
+
115
+ The usage of the SDK has been explained below.
116
116
 
117
117
  ## URL generation
118
118
 
@@ -139,8 +139,8 @@ https://ik.imagekit.io/your_imagekit_id/endpoint/tr:h-300,w-400/default-image.jp
139
139
  ```
140
140
 
141
141
  **2.Using full image URL**
142
- This method allows you to add transformation parameters to and 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
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
144
144
  database.
145
145
 
146
146
 
@@ -166,9 +166,9 @@ The `.url()` method accepts the following parameters
166
166
  | 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. |
167
167
  | 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
168
  | 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
- | 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. |
169
+ | 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
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. |
171
- | 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. |
171
+ | 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
172
  | 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
173
 
174
174
 
@@ -242,56 +242,71 @@ https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400/default-image.jpg?v=123&i
242
242
  **List of transformations**
243
243
 
244
244
  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
- The SDK gives a name to each transformation parameter, making the code simpler, making the code simpler and readable.
245
+ The SDK gives a name to each transformation parameter, making the code simpler, making the code simpler, and readable.
246
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 in the `url` function.
247
+ transformation code from ImageKit docs as the name when using the `url` function.
248
248
 
249
249
  | Supported Transformation Name | Translates to parameter |
250
- | ----------------------------- | ----------------------- |
251
- | height | h |
252
- | width | w |
253
- | aspect_ratio | ar |
254
- | quality | q |
255
- | crop | c |
256
- | crop_mode | cm |
257
- | x | x |
258
- | y | y |
259
- | focus | fo |
260
- | format | f |
261
- | radius | r |
262
- | background | bg |
263
- | border | bo |
264
- | rotation | rt |
265
- | blur | bl |
266
- | named | n |
267
- | overlay_image | oi |
268
- | overlay_x | ox |
269
- | overlay_y | oy |
270
- | overlay_focus | ofo |
271
- | overlay_height | oh |
272
- | overlay_width | ow |
273
- | overlay_text | ot |
274
- | overlay_text_font_size | ots |
275
- | overlay_text_font_family | otf |
276
- | overlay_text_color | otc |
277
- | overlay_alpha | oa |
278
- | overlay_text_typography | ott |
279
- | overlay_background | obg |
280
- | overlay_image_trim | oit |
281
- | progressive | pr |
282
- | lossless | lo |
283
- | trim | t |
284
- | metadata | md |
285
- | color_profile | cp |
286
- | default_image | di |
287
- | dpr | dpr |
288
- | effect_sharpen | e-sharpen |
289
- | effect_usm | e-usm |
290
- | effect_contrast | e-contrast |
291
- | effect_gray | e-grayscale |
292
- | original | orig |
250
+ |-------------------------------|-------------------------|
251
+ | height | h |
252
+ | width | w |
253
+ | aspectRatio | ar |
254
+ | quality | q |
255
+ | crop | c |
256
+ | cropMode | cm |
257
+ | x | x |
258
+ | y | y |
259
+ | focus | fo |
260
+ | format | f |
261
+ | radius | r |
262
+ | background | bg |
263
+ | border | b |
264
+ | rotation | rt |
265
+ | blur | bl |
266
+ | named | n |
267
+ | overlayX | ox |
268
+ | overlayY | oy |
269
+ | overlayFocus | ofo |
270
+ | overlayHeight | oh |
271
+ | overlayWidth | ow |
272
+ | overlayImage | oi |
273
+ | overlayImageTrim | oit |
274
+ | overlayImageAspectRatio | oiar |
275
+ | overlayImageBackground | oibg |
276
+ | overlayImageBorder | oib |
277
+ | overlayImageDPR | oidpr |
278
+ | overlayImageQuality | oiq |
279
+ | overlayImageCropping | oic |
280
+ | overlayImageTrim | oit |
281
+ | overlayText | ot |
282
+ | overlayTextFontSize | ots |
283
+ | overlayTextFontFamily | otf |
284
+ | overlayTextColor | otc |
285
+ | overlayTextTransparency | oa |
286
+ | overlayAlpha | oa |
287
+ | overlayTextTypography | ott |
288
+ | overlayBackground | obg |
289
+ | overlayTextEncoded | ote |
290
+ | overlayTextWidth | otw |
291
+ | overlayTextBackground | otbg |
292
+ | overlayTextPadding | otp |
293
+ | overlayTextInnerAlignment | otia |
294
+ | overlayRadius | or |
295
+ | progressive | pr |
296
+ | lossless | lo |
297
+ | trim | t |
298
+ | metadata | md |
299
+ | colorProfile | cp |
300
+ | defaultImage | di |
301
+ | dpr | dpr |
302
+ | effectSharpen | e-sharpen |
303
+ | effectUSM | e-usm |
304
+ | effectContrast | e-contrast |
305
+ | effectGray | e-grayscale |
306
+ | original | orig |
293
307
 
294
308
  ## File Upload
309
+ 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.
295
310
 
296
311
  The SDK provides a simple interface using the `.upload()` method to upload files to the ImageKit Media library. It
297
312
  accepts all the parameters supported by the [ImageKit Upload API](https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload).
@@ -318,7 +333,7 @@ be `None`.
318
333
  ## File Management
319
334
 
320
335
  The SDK provides a simple interface for all the [media APIs mentioned here](https://docs.imagekit.io/api-reference/media-api)
321
- to manage your files. This also returns `error` and `result`, error will be `None` if API succeeds.
336
+ to manage your files. This also returns `error` and `result`. The `error` will be `None` if API succeeds.
322
337
 
323
338
  **1. List & Search Files**
324
339
 
@@ -351,7 +366,7 @@ imagekit.get_remote_file_url_metadata(remote_file_url)
351
366
 
352
367
  **4. Update File Details**
353
368
  Update parameters associated with the file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/update-file-details).
354
- The first argument to the `update_field_details` method is the file ID and the second argument is an object with the
369
+ The first argument to the `update_field_details` method is the file ID, and a second argument is an object with the
355
370
  parameters to be updated.
356
371
 
357
372
  ```ruby
@@ -369,7 +384,7 @@ imagekitio.delete_file(file_id)
369
384
  ```
370
385
 
371
386
  **6. Bulk File Delete by IDs**
372
- 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
387
+ 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
373
388
  deleted.
374
389
 
375
390
  ```ruby
@@ -398,9 +413,7 @@ We have included the following commonly used utility functions in this package.
398
413
 
399
414
  **Authentication parameter generation**
400
415
 
401
- In case you are looking to implement client-side file upload, you are going to need a token, expiry timestamp
402
- , and a valid signature for that upload. The SDK provides a simple method that you can use in your code to generate these
403
- authentication parameters for you.
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.
404
417
 
405
418
  _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_
406
419
 
@@ -416,26 +429,24 @@ Returns
416
429
  }
417
430
  ```
418
431
 
419
- Both the `token` and `expire` parameters are optional. If not specified, the SDK uses the uuid to generate a random
420
- token and also generates a valid expiry timestamp internally. The value of the token and expire used to generate the
421
- signature are always returned in the response, no matter if they are provided as an input to this method or not.
432
+ 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.
422
433
 
423
434
  **Distance calculation between two pHash values**
424
435
 
425
436
  Perceptual hashing allows you to construct a hash value that uniquely identifies an input image based on the contents
426
437
  of an image. [imagekit.io metadata API](https://docs.imagekit.io/api-reference/metadata-api) returns the pHash
427
- value of an image in the response. You can use this value to find a duplicate, near the duplicate(similar) image by calculating
438
+ value of an image in the response. You can use this value to find a duplicate near the duplicate(similar) image by calculating
428
439
  the distance between the two images.
429
440
 
430
441
 
431
- This SDK exposes phash_distance function to calculate the distance between two pHash value. It accepts two pHash hexadecimal
442
+ This SDK exposes the `phash_distance` function to calculate the distance between two pHash value. It accepts two pHash hexadecimal
432
443
  strings and returns a numeric value indicative of the level of difference between the two images.
433
444
 
434
445
  ```ruby
435
446
  def calculate_distance():
436
447
  # fetch metadata of two uploaded image files
437
448
  ...
438
- # extract pHash strings from both: say 'first_hash' and 'second_hash'
449
+ # extract pHash strings from both: say 'first_hash' and 'second_hash.'
439
450
  ...
440
451
  # calculate the distance between them:
441
452
 
@@ -456,13 +467,13 @@ imagekitio.phash_distance('a4a65595ac94518b', '7838873e791f8400')
456
467
  # output: 37 (dissimilar images)
457
468
  ```
458
469
 
459
- ## Sample Code Instruction
470
+ ## Sample Application
460
471
  There are two sample apps:
461
472
  * [Rails application using Carrierwave](#Instructions-for-rails-application)
462
473
  * [Plain ruby application](#Instructions-for-ruby-application)
463
474
 
464
- ### Instructions for rails application
465
- 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 rails application.
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.
466
477
 
467
478
  **1. Clone git repository**
468
479
  ```bash
@@ -484,13 +495,12 @@ config.imagekit={
484
495
  ```ruby
485
496
  bundle install
486
497
  ```
487
- This sample project are using Sqlite3 database. If you are getting `sqlite3` gem installation error then install sqlite3 first then again run `bundle install`.
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`.
488
499
 
489
500
  **5. Migrate the database**
490
501
  ```ruby
491
502
  bundle exec rake db:migrate
492
503
  ```
493
- This sample project is using Sqlite3 database. If you are getting `sqlite3` gem installation error, then install sqlite3 first then again run `bundle install`.
494
504
 
495
505
  **6. Run your application**
496
506
  ```ruby
@@ -513,5 +523,4 @@ For any feedback or to report any issues or general implementation support, plea
513
523
  - [Main website](https://imagekit.io)
514
524
 
515
525
  ## License
516
- Released under the MIT license.
517
-
526
+ Released under the MIT license.
@@ -33,9 +33,6 @@ module CarrierWave
33
33
 
34
34
  def retrieve_from_cache!(identifier)
35
35
  CarrierWave::SanitizedFile.new(::File.expand_path(uploader.cache_path(identifier), uploader.root))
36
- resp=@client.get(identifier)
37
- # binding.pry
38
- IKFile.new(resp)
39
36
  end
40
37
 
41
38
  def delete_dir!(path)
@@ -69,3 +69,9 @@ MISSING_PHASH_VALUE = {'message': "Missing pHash value",
69
69
  'help': "Please pass two pHash values",}
70
70
  UNEQUAL_STRING_LENGTH = {'message': "Unequal pHash string length",
71
71
  'help': "For distance calculation, the two pHash strings must have equal length",}
72
+
73
+ MISSING_PRIVATE_KEY = "ImageKit private key missing"
74
+
75
+ MISSING_PUBLIC_KEY = "ImageKit public key missing"
76
+
77
+ MISSING_URL_ENDPOINT = "ImageKit URL Endpoint missing. Default URL Endpoint: https://ik.imagekit.io/<YOUR_IMAGEKIT_ID>/"
@@ -11,11 +11,18 @@ SUPPORTED_TRANS = {
11
11
  'format': "f",
12
12
  'radius': "r",
13
13
  'background': "bg",
14
- 'border': "bo",
14
+ 'border': "b",
15
15
  'rotation': "rt",
16
16
  'blur': "bl",
17
17
  'named': "n",
18
18
  'overlay_image': "oi",
19
+ 'overlay_image_trim': "oit",
20
+ 'overlay_image_cropping': "oic",
21
+ 'overlay_image_quality': "oiq",
22
+ 'overlay_image_DPR': "oidpr",
23
+ 'overlay_image_border': "oib",
24
+ 'overlay_image_background': "oibg",
25
+ 'overlay_image_aspect_ratio': "oiar",
19
26
  'overlay_x': "ox",
20
27
  'overlay_y': "oy",
21
28
  'overlay_focus': "ofo",
@@ -24,11 +31,17 @@ SUPPORTED_TRANS = {
24
31
  'overlay_text': "ot",
25
32
  'overlay_text_font_size': "ots",
26
33
  'overlay_text_font_family': "otf",
34
+ 'overlay_text_encoded': "ote",
27
35
  'overlay_text_color': "otc",
36
+ 'overlay_text_width': "otw",
37
+ 'overlay_text_background': "otbg",
38
+ 'overlay_text_padding': "otp",
39
+ 'overlay_text_inner_alignment': "otia",
40
+ 'overlay_text_transparency': "oa",
28
41
  'overlay_alpha': "oa",
42
+ 'overlay_radius': "or",
29
43
  'overlay_text_typography': "ott",
30
44
  'overlay_background': "obg",
31
- 'overlay_image_trim': "oit",
32
45
  'progressive': "pr",
33
46
  'lossless': "lo",
34
47
  'trim': "t",
@@ -130,4 +130,4 @@ class ImageKitFile
130
130
  end
131
131
  request_formatter(options)
132
132
  end
133
- end
133
+ end
@@ -16,6 +16,17 @@ module ImageKit
16
16
  attr_reader :file
17
17
 
18
18
  def initialize(private_key, public_key, url_endpoint, transformation_pos = nil, options = nil)
19
+
20
+ unless(private_key.is_a?(String) && private_key.to_s.strip.length != 0)
21
+ raise ArgumentError, MISSING_PRIVATE_KEY
22
+ end
23
+ unless(public_key.is_a?(String) && public_key.to_s.strip.length != 0)
24
+ raise ArgumentError, MISSING_PUBLIC_KEY
25
+ end
26
+ unless(url_endpoint.is_a?(String) && url_endpoint.to_s.strip.length != 0)
27
+ raise ArgumentError, MISSING_URL_ENDPOINT
28
+ end
29
+
19
30
  @private_key = private_key
20
31
  @public_key = public_key
21
32
  @url_endpoint = url_endpoint
@@ -92,8 +103,7 @@ module ImageKit
92
103
  def phash_distance(first, second)
93
104
  # Get hamming distance between two phash(image hash) to check
94
105
  # similarity between images
95
-
96
- unless first && second
106
+ if first.to_s.strip == "" || second.to_s.strip == ""
97
107
  raise ArgumentError, Error::MISSING_PHASH_VALUE
98
108
  end
99
109
  hamming_distance(first, second)
@@ -104,5 +114,4 @@ module ImageKit
104
114
  get_authenticated_params(token, expire, @ik_req.private_key)
105
115
  end
106
116
  end
107
- end
108
-
117
+ end
@@ -38,11 +38,12 @@ class ImageKitRequest
38
38
  headers: headers,
39
39
  payload: payload).execute
40
40
 
41
-
42
- if resp.code == 404
43
- raise RestClient::ExceptionWithResponse
44
- elsif (resp.code >= 200) && (resp.code < 204)
45
- response[:response] = JSON.parse(resp.body.to_s)
41
+ if (resp.code >= 200) && (resp.code < 204)
42
+ if (resp.headers[:content_type].include? "application/json")
43
+ response[:response] = JSON.parse(resp.body.to_s)
44
+ else
45
+ raise =RestClient::ExceptionWithResponse
46
+ end
46
47
  elsif resp.code == 204
47
48
  response[:response] = {'success': true}
48
49
  end
@@ -1,5 +1,5 @@
1
1
  module Imagekit
2
2
  module Sdk
3
- VERSION = '1.0.4'
3
+ VERSION = '1.0.9'
4
4
  end
5
5
  end
@@ -70,8 +70,6 @@ class Url
70
70
  parts=part.split("=")
71
71
  if parts.length==2
72
72
  query_params[parts[0]]=parts[1]
73
- else
74
- query_params[parts[0]]=""
75
73
  end
76
74
  end
77
75
  end
@@ -80,7 +78,7 @@ class Url
80
78
  end
81
79
  transformation_str = transformation_to_str(options[:transformation]).chomp("/")
82
80
 
83
- if transformation_str
81
+ unless transformation_str.nil? || transformation_str.strip.empty?
84
82
  if (transformation_position == Default::QUERY_TRANSFORMATION_POSITION) || src_param_used_for_url == true
85
83
  result_url_hash[:query] = "#{Default::TRANSFORMATION_PARAMETER}=#{transformation_str}"
86
84
  query_params[:tr]=transformation_str
@@ -94,25 +92,30 @@ class Url
94
92
  result_url_hash[:path] = result_url_hash[:path].chomp("/")
95
93
  result_url_hash[:scheme] ||= "https"
96
94
 
95
+ query_param_arr = []
96
+ query_param_arr.push("ik-sdk-version=ruby-"+Imagekit::Sdk::VERSION)
97
+ query_params.each do |key, value|
98
+ if value.to_s == ""
99
+ query_param_arr.push(key.to_s)
100
+ else
101
+ query_param_arr.push(key.to_s + "=" + value.to_s)
102
+ end
103
+ end
104
+
105
+ query_param_str = query_param_arr.join("&")
106
+ result_url_hash[:query] = query_param_str
97
107
 
98
108
  # Signature String and Timestamp
99
109
  # We can do this only for URLs that are created using urlEndpoint and path parameter
100
110
  # because we need to know the endpoint to be able to remove it from the URL to create a signature
101
111
  # for the remaining. With the src parameter, we would not know the "pattern" in the URL
102
- query_param_arr = []
103
- query_param_arr.push("ik-sdk-version=ruby-"+Imagekit::Sdk::VERSION)
104
112
  if options[:signed] && !(options[:src])
105
113
  intermediate_url = result_url_hash.fetch(:scheme, "") + "://" + result_url_hash.fetch(:host, "") + result_url_hash.fetch(:path, "")
106
114
  if result_url_hash[:query]!=nil && result_url_hash[:query]!=""
107
115
  intermediate_url += result_url_hash.fetch(:query, "")
108
116
  end
109
117
  end
110
- query_params.each do |key, value|
111
- query_param_arr.push(key.to_s + "=" + value.to_s)
112
- end
113
118
 
114
- query_param_str = query_param_arr.join("&")
115
- result_url_hash[:query] = query_param_str
116
119
  url=hash_to_url(result_url_hash)
117
120
  if options[:signed]
118
121
  private_key = options[:private_key]
@@ -149,6 +152,11 @@ class Url
149
152
  transform_key = SUPPORTED_TRANS.fetch(key, nil)
150
153
  transform_key ||= key
151
154
 
155
+ if transform_key == "oi" || transform_key == "di"
156
+ transformation[i][key][0] = "" if transformation[i][key][0] == "/"
157
+ transformation[i][key] = transformation[i][key].gsub("/", "@@")
158
+ end
159
+
152
160
  if transformation[i][key] == "-"
153
161
  parsed_transform_step.push(transform_key)
154
162
  else
@@ -29,10 +29,20 @@ module CarrierWave
29
29
  if options!=nil
30
30
  @options=options
31
31
  end
32
+ folder=nil
33
+ begin
34
+ folder=store_dir
35
+ rescue
36
+ end
37
+
38
+ if folder!=nil
39
+ @options[:folder]=folder
40
+ end
41
+
32
42
  if self.file!=nil
33
43
  base64=Base64.encode64(::File.open(self.file.file, "rb").read)
34
44
  resp=@imagekit.upload_file(open(self.file.file,'rb'),self.file.filename,@options)
35
- ::File.delete(self.file.file)
45
+ # ::File.delete(self.file.file)
36
46
  res=resp[:response].to_json
37
47
  if res!="null"
38
48
  res
@@ -65,8 +75,12 @@ module CarrierWave
65
75
  def options
66
76
  options={}
67
77
  end
78
+
79
+ def store_dir
80
+ store_dir=nil
81
+ end
68
82
  end
69
83
 
70
84
  end
71
85
 
72
- end
86
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imagekitio
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - ImageKit.io team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-22 00:00:00.000000000 Z
11
+ date: 2021-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
@@ -34,40 +34,40 @@ dependencies:
34
34
  name: rest-client
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ">="
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: '2.1'
40
- - - "~>"
40
+ - - ">="
41
41
  - !ruby/object:Gem::Version
42
42
  version: '2.1'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ">="
47
+ - - "~>"
48
48
  - !ruby/object:Gem::Version
49
49
  version: '2.1'
50
- - - "~>"
50
+ - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: '2.1'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: rails
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - ">="
57
+ - - "~>"
58
58
  - !ruby/object:Gem::Version
59
59
  version: 5.2.0
60
- - - "~>"
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: 5.2.0
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ">="
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: 5.2.0
70
- - - "~>"
70
+ - - ">="
71
71
  - !ruby/object:Gem::Version
72
72
  version: 5.2.0
73
73
  description: Automate image optimization on rails platforms.
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubygems_version: 3.0.3
120
+ rubygems_version: 3.1.4
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Automate image optimization on rails platforms.