Skip to content

Commit dd73893

Browse files
committed
code coverage badge
1 parent a9543de commit dd73893

File tree

1 file changed

+41
-52
lines changed

1 file changed

+41
-52
lines changed

README.md

Lines changed: 41 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
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
24

35
[![Ruby Test](https://github.com/imagekit-developer/imagekit-ruby/workflows/Ruby%20Test/badge.svg)](https://github.com/imagekit-developer/imagekit-ruby)
46
[![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)
58
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
69
[![Twitter Follow](https://img.shields.io/twitter/follow/imagekitio?label=Follow&style=social)](https://twitter.com/ImagekitIo)
710

8-
Rails SDK for [ImageKit](https://imagekit.io/) that implements the new APIs and interface for performing different file operations.
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/).
1412

1513
Table of contents -
1614
* [Installation](#Installation)
@@ -24,19 +22,12 @@ Table of contents -
2422
* [Links](#Links)
2523

2624

27-
## Installation
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.
3427

35-
# New application with specific database
36-
rails new <your_application_name> -d <database_name>
37-
```
28+
## Installation
3829

39-
Add this dependency to your application's Gemfile:
30+
Add `imagekitio` dependency to your application's Gemfile:
4031

4132
```ruby
4233
gem 'imagekitio'
@@ -46,7 +37,8 @@ And then execute:
4637
```
4738
$ bundle install
4839
```
49-
Or install it yourself as:
40+
41+
Or install it yourself:
5042
```
5143
$ gem install imagekitio
5244
```
@@ -64,19 +56,20 @@ config.imagekit={
6456
```
6557

6658
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+
6760
```bash
6861
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
7063
rails g uploader Avatar
7164
# Generated uploader's path will be app/uploaders/avatar_uploader.rb
7265
```
7366

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:
7568
```ruby
7669
# Set store as imagekit_store
7770
storage :imagekit_store
7871

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
8073

8174
def options
8275
options={
@@ -87,14 +80,14 @@ def options
8780
}
8881
end
8982

90-
# If you want to set upload dir then you can use following method or you can also use options method.
91-
# This method shuld return string
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
9285
def store_dir
9386
"your_directory/"
9487
end
9588
```
9689

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.
9891

9992
```ruby
10093
class Employee < ApplicationRecord
@@ -107,7 +100,7 @@ Get image url:
107100
```ruby
108101
# If @employee is an object of your model that has data.
109102

110-
# To get original image url use
103+
# To get the original image url, use
111104
@employee.avatar.url
112105

113106
# And to get transformed url use
@@ -117,8 +110,9 @@ Get image url:
117110

118111
## Usage
119112

120-
You can use this Ruby SDK for 3 different kinds of methods - URL generation, file upload, and file management.
121-
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.
122116

123117
## URL generation
124118

@@ -145,8 +139,8 @@ https://ik.imagekit.io/your_imagekit_id/endpoint/tr:h-300,w-400/default-image.jp
145139
```
146140

147141
**2.Using full image URL**
148-
This method allows you to add transformation parameters to and existing, complete URL that is already mapped to ImageKit
149-
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
150144
database.
151145

152146

@@ -172,9 +166,9 @@ The `.url()` method accepts the following parameters
172166
| 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. |
173167
| 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. |
174168
| 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` 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. |
176170
| 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, 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. |
178172
| 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. |
179173

180174

@@ -248,9 +242,9 @@ https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400/default-image.jpg?v=123&i
248242
**List of transformations**
249243

250244
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.
252246
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 in the `url` function.
247+
transformation code from ImageKit docs as the name when using the `url` function.
254248

255249
| Supported Transformation Name | Translates to parameter |
256250
|-------------------------------|-------------------------|
@@ -312,7 +306,7 @@ transformation code from ImageKit docs as the name when using in the `url` funct
312306
| original | orig |
313307

314308
## File Upload
315-
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.
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.
316310

317311
The SDK provides a simple interface using the `.upload()` method to upload files to the ImageKit Media library. It
318312
accepts all the parameters supported by the [ImageKit Upload API](https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload).
@@ -339,7 +333,7 @@ be `None`.
339333
## File Management
340334

341335
The SDK provides a simple interface for all the [media APIs mentioned here](https://docs.imagekit.io/api-reference/media-api)
342-
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.
343337

344338
**1. List & Search Files**
345339

@@ -372,7 +366,7 @@ imagekit.get_remote_file_url_metadata(remote_file_url)
372366

373367
**4. Update File Details**
374368
Update parameters associated with the file as per the [API documentation here](https://docs.imagekit.io/api-reference/media-api/update-file-details).
375-
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
376370
parameters to be updated.
377371

378372
```ruby
@@ -390,7 +384,7 @@ imagekitio.delete_file(file_id)
390384
```
391385

392386
**6. Bulk File Delete by IDs**
393-
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
394388
deleted.
395389

396390
```ruby
@@ -419,9 +413,7 @@ We have included the following commonly used utility functions in this package.
419413

420414
**Authentication parameter generation**
421415

422-
In case you are looking to implement client-side file upload, you are going to need a token, expiry timestamp
423-
, and a valid signature for that upload. The SDK provides a simple method that you can use in your code to generate these
424-
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.
425417

426418
_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_
427419

@@ -437,26 +429,24 @@ Returns
437429
}
438430
```
439431

440-
Both the `token` and `expire` parameters are optional. If not specified, the SDK uses the uuid to generate a random
441-
token and also generates a valid expiry timestamp internally. The value of the token and expire used to generate the
442-
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.
443433

444434
**Distance calculation between two pHash values**
445435

446436
Perceptual hashing allows you to construct a hash value that uniquely identifies an input image based on the contents
447437
of an image. [imagekit.io metadata API](https://docs.imagekit.io/api-reference/metadata-api) returns the pHash
448-
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
449439
the distance between the two images.
450440

451441

452-
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
453443
strings and returns a numeric value indicative of the level of difference between the two images.
454444

455445
```ruby
456446
def calculate_distance():
457447
# fetch metadata of two uploaded image files
458448
...
459-
# extract pHash strings from both: say 'first_hash' and 'second_hash'
449+
# extract pHash strings from both: say 'first_hash' and 'second_hash.'
460450
...
461451
# calculate the distance between them:
462452

@@ -482,8 +472,8 @@ There are two sample apps:
482472
* [Rails application using Carrierwave](#Instructions-for-rails-application)
483473
* [Plain ruby application](#Instructions-for-ruby-application)
484474

485-
### Instructions for rails application
486-
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.
487477

488478
**1. Clone git repository**
489479
```bash
@@ -505,7 +495,7 @@ config.imagekit={
505495
```ruby
506496
bundle install
507497
```
508-
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`.
509499

510500
**5. Migrate the database**
511501
```ruby
@@ -533,5 +523,4 @@ For any feedback or to report any issues or general implementation support, plea
533523
- [Main website](https://imagekit.io)
534524

535525
## License
536-
Released under the MIT license.
537-
526+
Released under the MIT license.

0 commit comments

Comments
 (0)