imagekitio 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +99 -95
- data/lib/imagekit/constants/errors.rb +6 -0
- data/lib/imagekit/constants/supported_transformation.rb +15 -2
- data/lib/imagekit/file.rb +1 -1
- data/lib/imagekit/imagekit.rb +13 -4
- data/lib/imagekit/resource.rb +6 -5
- data/lib/imagekit/sdk/version.rb +1 -1
- data/lib/imagekit/url.rb +17 -9
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2ada5ea48fb054f2a85d6214f4b03dbc7454a9d26ecf191cf99e287efdfeb3e
|
4
|
+
data.tar.gz: de18de012eefa66ff87a516365539fd6e18107c8b8a1fb2a568fe8b482260daa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78879b32ca25f69f90cc778808221dedbaffc72a87291a90cee34efe599fe1bf4aa49770eea0d05ab2be0cc9dc264fed88b427812a26a68dca52732474cbb635
|
7
|
+
data.tar.gz: d9f6c4119a13aa6ae75dee32ea3ae88fa96a4320dc128dcdabb2323706bda0f324aaf5cc801d0f5a89f6656b6fad3872c892a23545abc8cad92a183288790ed2
|
data/README.md
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
-
|
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
|
-
|
9
|
-
|
10
|
-
ImageKit is a complete image optimization and transformation solution that comes with and
|
11
|
-
[image CDN](https://imagekit.io/features/imagekit-infrastructure) and media storage. It can be integrated with your
|
12
|
-
existing infrastructure - storage like AWS s3, web servers, your CDN, and custom domain names, allowing you to deliver
|
13
|
-
optimize images in minutes with minimal code changes.
|
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/).
|
14
12
|
|
15
13
|
Table of contents -
|
16
14
|
* [Installation](#Installation)
|
@@ -24,19 +22,12 @@ Table of contents -
|
|
24
22
|
* [Links](#Links)
|
25
23
|
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
If you want to create new rails application, then use this command
|
30
|
-
|
31
|
-
```bash
|
32
|
-
# New application with default Sqlite3 database
|
33
|
-
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.
|
34
27
|
|
35
|
-
|
36
|
-
rails new <your_application_name> -d <database_name>
|
37
|
-
```
|
28
|
+
## Installation
|
38
29
|
|
39
|
-
Add
|
30
|
+
Add `imagekitio` dependency to your application's Gemfile:
|
40
31
|
|
41
32
|
```ruby
|
42
33
|
gem 'imagekitio'
|
@@ -46,7 +37,8 @@ And then execute:
|
|
46
37
|
```
|
47
38
|
$ bundle install
|
48
39
|
```
|
49
|
-
|
40
|
+
|
41
|
+
Or install it yourself:
|
50
42
|
```
|
51
43
|
$ gem install imagekitio
|
52
44
|
```
|
@@ -63,20 +55,21 @@ config.imagekit={
|
|
63
55
|
}
|
64
56
|
```
|
65
57
|
|
66
|
-
You
|
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
|
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={
|
@@ -87,14 +80,14 @@ def options
|
|
87
80
|
}
|
88
81
|
end
|
89
82
|
|
90
|
-
# If you want to set upload dir then you can use following method or you can also use options method.
|
91
|
-
# This method
|
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
|
92
85
|
def store_dir
|
93
86
|
"your_directory/"
|
94
87
|
end
|
95
88
|
```
|
96
89
|
|
97
|
-
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.
|
98
91
|
|
99
92
|
```ruby
|
100
93
|
class Employee < ApplicationRecord
|
@@ -107,7 +100,7 @@ Get image url:
|
|
107
100
|
```ruby
|
108
101
|
# If @employee is an object of your model that has data.
|
109
102
|
|
110
|
-
# To get original image url use
|
103
|
+
# To get the original image url, use
|
111
104
|
@employee.avatar.url
|
112
105
|
|
113
106
|
# And to get transformed url use
|
@@ -117,8 +110,9 @@ Get image url:
|
|
117
110
|
|
118
111
|
## Usage
|
119
112
|
|
120
|
-
You can use this Ruby SDK for
|
121
|
-
|
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.
|
122
116
|
|
123
117
|
## URL generation
|
124
118
|
|
@@ -145,8 +139,8 @@ https://ik.imagekit.io/your_imagekit_id/endpoint/tr:h-300,w-400/default-image.jp
|
|
145
139
|
```
|
146
140
|
|
147
141
|
**2.Using full image URL**
|
148
|
-
This method allows you to add transformation parameters to
|
149
|
-
using
|
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
|
150
144
|
database.
|
151
145
|
|
152
146
|
|
@@ -172,9 +166,9 @@ The `.url()` method accepts the following parameters
|
|
172
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. |
|
173
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. |
|
174
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. |
|
175
|
-
| 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
|
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. |
|
176
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. |
|
177
|
-
| 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
|
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. |
|
178
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. |
|
179
173
|
|
180
174
|
|
@@ -248,56 +242,71 @@ https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400/default-image.jpg?v=123&i
|
|
248
242
|
**List of transformations**
|
249
243
|
|
250
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).
|
251
|
-
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.
|
252
246
|
If a transformation is supported in ImageKit, but a name for it cannot be found in the table below, then use the
|
253
|
-
transformation code from ImageKit docs as the name when using
|
247
|
+
transformation code from ImageKit docs as the name when using the `url` function.
|
254
248
|
|
255
249
|
| Supported Transformation Name | Translates to parameter |
|
256
|
-
|
257
|
-
| height
|
258
|
-
| width
|
259
|
-
|
|
260
|
-
| quality
|
261
|
-
| crop
|
262
|
-
|
|
263
|
-
| x
|
264
|
-
| y
|
265
|
-
| focus
|
266
|
-
| format
|
267
|
-
| radius
|
268
|
-
| background
|
269
|
-
| border
|
270
|
-
| rotation
|
271
|
-
| blur
|
272
|
-
| named
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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 |
|
299
307
|
|
300
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.
|
301
310
|
|
302
311
|
The SDK provides a simple interface using the `.upload()` method to upload files to the ImageKit Media library. It
|
303
312
|
accepts all the parameters supported by the [ImageKit Upload API](https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload).
|
@@ -324,7 +333,7 @@ be `None`.
|
|
324
333
|
## File Management
|
325
334
|
|
326
335
|
The SDK provides a simple interface for all the [media APIs mentioned here](https://docs.imagekit.io/api-reference/media-api)
|
327
|
-
to manage your files. This also returns `error` and `result
|
336
|
+
to manage your files. This also returns `error` and `result`. The `error` will be `None` if API succeeds.
|
328
337
|
|
329
338
|
**1. List & Search Files**
|
330
339
|
|
@@ -357,7 +366,7 @@ imagekit.get_remote_file_url_metadata(remote_file_url)
|
|
357
366
|
|
358
367
|
**4. Update File Details**
|
359
368
|
Update parameters associated with the file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/update-file-details).
|
360
|
-
The first argument to the `update_field_details` method is the file ID and
|
369
|
+
The first argument to the `update_field_details` method is the file ID, and a second argument is an object with the
|
361
370
|
parameters to be updated.
|
362
371
|
|
363
372
|
```ruby
|
@@ -375,7 +384,7 @@ imagekitio.delete_file(file_id)
|
|
375
384
|
```
|
376
385
|
|
377
386
|
**6. Bulk File Delete by IDs**
|
378
|
-
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
|
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
|
379
388
|
deleted.
|
380
389
|
|
381
390
|
```ruby
|
@@ -404,9 +413,7 @@ We have included the following commonly used utility functions in this package.
|
|
404
413
|
|
405
414
|
**Authentication parameter generation**
|
406
415
|
|
407
|
-
In case you are looking to implement client-side file upload, you are going to need a token
|
408
|
-
, and a valid signature for that upload. The SDK provides a simple method that you can use in your code to generate these
|
409
|
-
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.
|
410
417
|
|
411
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_
|
412
419
|
|
@@ -422,26 +429,24 @@ Returns
|
|
422
429
|
}
|
423
430
|
```
|
424
431
|
|
425
|
-
Both the `token` and `expire` parameters are optional. If not specified, the SDK uses the uuid to generate a random
|
426
|
-
token and also generates a valid expiry timestamp internally. The value of the token and expire used to generate the
|
427
|
-
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.
|
428
433
|
|
429
434
|
**Distance calculation between two pHash values**
|
430
435
|
|
431
436
|
Perceptual hashing allows you to construct a hash value that uniquely identifies an input image based on the contents
|
432
437
|
of an image. [imagekit.io metadata API](https://docs.imagekit.io/api-reference/metadata-api) returns the pHash
|
433
|
-
value of an image in the response. You can use this value to find a duplicate
|
438
|
+
value of an image in the response. You can use this value to find a duplicate near the duplicate(similar) image by calculating
|
434
439
|
the distance between the two images.
|
435
440
|
|
436
441
|
|
437
|
-
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
|
438
443
|
strings and returns a numeric value indicative of the level of difference between the two images.
|
439
444
|
|
440
445
|
```ruby
|
441
446
|
def calculate_distance():
|
442
447
|
# fetch metadata of two uploaded image files
|
443
448
|
...
|
444
|
-
# extract pHash strings from both: say 'first_hash' and 'second_hash'
|
449
|
+
# extract pHash strings from both: say 'first_hash' and 'second_hash.'
|
445
450
|
...
|
446
451
|
# calculate the distance between them:
|
447
452
|
|
@@ -467,8 +472,8 @@ There are two sample apps:
|
|
467
472
|
* [Rails application using Carrierwave](#Instructions-for-rails-application)
|
468
473
|
* [Plain ruby application](#Instructions-for-ruby-application)
|
469
474
|
|
470
|
-
### Instructions for rails application
|
471
|
-
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.
|
472
477
|
|
473
478
|
**1. Clone git repository**
|
474
479
|
```bash
|
@@ -490,7 +495,7 @@ config.imagekit={
|
|
490
495
|
```ruby
|
491
496
|
bundle install
|
492
497
|
```
|
493
|
-
This sample project
|
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`.
|
494
499
|
|
495
500
|
**5. Migrate the database**
|
496
501
|
```ruby
|
@@ -518,5 +523,4 @@ For any feedback or to report any issues or general implementation support, plea
|
|
518
523
|
- [Main website](https://imagekit.io)
|
519
524
|
|
520
525
|
## License
|
521
|
-
Released under the MIT license.
|
522
|
-
|
526
|
+
Released under the MIT license.
|
@@ -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': "
|
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",
|
data/lib/imagekit/file.rb
CHANGED
data/lib/imagekit/imagekit.rb
CHANGED
@@ -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
|
data/lib/imagekit/resource.rb
CHANGED
@@ -38,11 +38,12 @@ class ImageKitRequest
|
|
38
38
|
headers: headers,
|
39
39
|
payload: payload).execute
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
if (resp.code >= 200) && (resp.code < 204)
|
42
|
+
if (resp.headers[:content_type] == "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
|
data/lib/imagekit/sdk/version.rb
CHANGED
data/lib/imagekit/url.rb
CHANGED
@@ -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
|
@@ -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
|
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
|
+
version: 1.0.7
|
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-
|
11
|
+
date: 2020-10-26 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.
|
120
|
+
rubygems_version: 3.1.2
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: Automate image optimization on rails platforms.
|