imagekitio 1.0.10 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +292 -82
- data/Rakefile +1 -1
- data/lib/active_storage/active_storage.rb +2 -0
- data/lib/active_storage/service/ik_file.rb +111 -0
- data/lib/active_storage/service/image_kit_io_service.rb +185 -0
- data/lib/carrierwave/carrierwave.rb +79 -0
- data/lib/carrierwave/storage/ik_file.rb +8 -7
- data/lib/carrierwave/storage/imagekit_store.rb +54 -51
- data/lib/carrierwave/support/uri_filename.rb +9 -7
- data/lib/imagekitio/api_service/bulk.rb +58 -0
- data/lib/imagekitio/api_service/custom_metadata_field.rb +52 -0
- data/lib/imagekitio/api_service/file.rb +162 -0
- data/lib/imagekitio/api_service/folder.rb +49 -0
- data/lib/imagekitio/base.rb +12 -0
- data/lib/imagekitio/client.rb +186 -0
- data/lib/imagekitio/configurable.rb +43 -0
- data/lib/imagekitio/constant.rb +36 -0
- data/lib/imagekitio/constants/default.rb +22 -0
- data/lib/imagekitio/constants/error.rb +69 -0
- data/lib/imagekitio/constants/file.rb +11 -0
- data/lib/imagekitio/constants/supported_transformation.rb +64 -0
- data/lib/imagekitio/constants/url.rb +14 -0
- data/lib/imagekitio/errors.rb +4 -0
- data/lib/imagekitio/railtie.rb +1 -1
- data/lib/imagekitio/request.rb +79 -0
- data/lib/imagekitio/sdk/version.rb +5 -0
- data/lib/imagekitio/url.rb +241 -0
- data/lib/imagekitio/utils/calculation.rb +44 -0
- data/lib/imagekitio/utils/formatter.rb +48 -0
- data/lib/imagekitio/utils/option_validator.rb +36 -0
- data/lib/imagekitio.rb +10 -83
- metadata +41 -15
- data/lib/imagekit/constants/defaults.rb +0 -20
- data/lib/imagekit/constants/errors.rb +0 -77
- data/lib/imagekit/constants/file.rb +0 -5
- data/lib/imagekit/constants/supported_transformation.rb +0 -57
- data/lib/imagekit/constants/url.rb +0 -9
- data/lib/imagekit/file.rb +0 -133
- data/lib/imagekit/imagekit.rb +0 -117
- data/lib/imagekit/resource.rb +0 -56
- data/lib/imagekit/sdk/version.rb +0 -5
- data/lib/imagekit/url.rb +0 -237
- data/lib/imagekit/utils/calculation.rb +0 -36
- data/lib/imagekit/utils/formatter.rb +0 -29
@@ -1,77 +0,0 @@
|
|
1
|
-
MANDATORY_INIT_MISSING = {
|
2
|
-
'message': "Missing public_key or private_key or url_endpoint during ImageKit initialization",
|
3
|
-
help: "",
|
4
|
-
}
|
5
|
-
INVALID_TRANSFORMATION_POS = {'message': "Invalid transformationPosition parameter",
|
6
|
-
help: "",}
|
7
|
-
INVALID_URL_GENERATION_PARAM = {'message': "Invalid url parameter", help: ""}
|
8
|
-
INVALID_TRANSFORMATION_OPTIONS = {
|
9
|
-
'message': "Invalid transformation parameter options",
|
10
|
-
help: "",
|
11
|
-
}
|
12
|
-
CACHE_PURGE_URL_MISSING = {'message': "Missing URL parameter for this request",
|
13
|
-
help: "",}
|
14
|
-
CACHE_PURGE_STATUS_ID_MISSING = {'message': "Missing Request ID parameter for this request",
|
15
|
-
help: "",}
|
16
|
-
FILE_ID_MISSING = {'message': "Missing File ID parameter for this request",
|
17
|
-
help: "",}
|
18
|
-
UPDATE_DATA_MISSING = {'message': "Missing file update data for this request",
|
19
|
-
help: "",}
|
20
|
-
|
21
|
-
UPDATE_DATA_TAGS_INVALID = {'message': "Invalid tags parameter for this request",
|
22
|
-
help: "tags should be passed as null or an array like ['tag1', 'tag2']",}.freeze
|
23
|
-
|
24
|
-
UPDATE_DATA_COORDS_INVALID =
|
25
|
-
{'message': "Invalid custom_coordinates parameter for this request",
|
26
|
-
help: "custom_coordinates should be passed as null or a string like 'x,y,width,height'",}
|
27
|
-
|
28
|
-
LIST_FILES_INPUT_MISSING = {
|
29
|
-
'message': "Missing options for list files",
|
30
|
-
help: "If you do not want to pass any parameter for listing, pass an empty object",
|
31
|
-
}
|
32
|
-
MISSING_FILE_URL = {'message': "Missing file_url for purge_cache", help: ""}
|
33
|
-
MISSING_UPLOAD_DATA = {'message': "Missing data for upload", help: ""}
|
34
|
-
MISSING_UPLOAD_FILE_PARAMETER = {
|
35
|
-
'message': "Missing file parameter for upload",
|
36
|
-
help: "",
|
37
|
-
}
|
38
|
-
MISSING_UPLOAD_FILENAME_PARAM = {
|
39
|
-
'message': "Missing fileName parameter for upload",
|
40
|
-
help: "",
|
41
|
-
}
|
42
|
-
|
43
|
-
INVALID_PHASH_VALUE =
|
44
|
-
{
|
45
|
-
'message': "Invalid pHash value",
|
46
|
-
help: "Both pHash strings must be valid hexadecimal numbers",
|
47
|
-
}
|
48
|
-
|
49
|
-
MISSING_PHASH_VALUE = {
|
50
|
-
'message': "Missing pHash value",
|
51
|
-
help: "Please pass two pHash values",
|
52
|
-
}
|
53
|
-
UNEQUAL_STRING_LENGTH = {
|
54
|
-
'': "Unequal pHash string length",
|
55
|
-
help: "For distance calculation, the two pHash strings must have equal length",
|
56
|
-
}
|
57
|
-
|
58
|
-
MISSING_UPLOAD_FILE_PARAMETER = {'message': "Missing file parameter for upload",
|
59
|
-
'help': "",}
|
60
|
-
MISSING_UPLOAD_FILENAME_PARAM = {
|
61
|
-
'message': "Missing fileName parameter for upload",
|
62
|
-
'help': "",
|
63
|
-
}
|
64
|
-
|
65
|
-
INVALID_PHASH_VALUE = {'message': "Invalid pHash value",
|
66
|
-
'help': "Both pHash strings must be valid hexadecimal numbers",}
|
67
|
-
|
68
|
-
MISSING_PHASH_VALUE = {'message': "Missing pHash value",
|
69
|
-
'help': "Please pass two pHash values",}
|
70
|
-
UNEQUAL_STRING_LENGTH = {'message': "Unequal pHash string length",
|
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>/"
|
@@ -1,57 +0,0 @@
|
|
1
|
-
SUPPORTED_TRANS = {
|
2
|
-
'height': "h",
|
3
|
-
'width': "w",
|
4
|
-
'aspect_ratio': "ar",
|
5
|
-
'quality': "q",
|
6
|
-
'crop': "c",
|
7
|
-
'crop_mode': "cm",
|
8
|
-
'x': "x",
|
9
|
-
'y': "y",
|
10
|
-
'focus': "fo",
|
11
|
-
'format': "f",
|
12
|
-
'radius': "r",
|
13
|
-
'background': "bg",
|
14
|
-
'border': "b",
|
15
|
-
'rotation': "rt",
|
16
|
-
'blur': "bl",
|
17
|
-
'named': "n",
|
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",
|
26
|
-
'overlay_x': "ox",
|
27
|
-
'overlay_y': "oy",
|
28
|
-
'overlay_focus': "ofo",
|
29
|
-
'overlay_height': "oh",
|
30
|
-
'overlay_width': "ow",
|
31
|
-
'overlay_text': "ot",
|
32
|
-
'overlay_text_font_size': "ots",
|
33
|
-
'overlay_text_font_family': "otf",
|
34
|
-
'overlay_text_encoded': "ote",
|
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",
|
41
|
-
'overlay_alpha': "oa",
|
42
|
-
'overlay_radius': "or",
|
43
|
-
'overlay_text_typography': "ott",
|
44
|
-
'overlay_background': "obg",
|
45
|
-
'progressive': "pr",
|
46
|
-
'lossless': "lo",
|
47
|
-
'trim': "t",
|
48
|
-
'metadata': "md",
|
49
|
-
'color_profile': "cp",
|
50
|
-
'default_image': "di",
|
51
|
-
'dpr': "dpr",
|
52
|
-
'effect_sharpen': "e-sharpen",
|
53
|
-
'effect_usm': "e-usm",
|
54
|
-
'effect_contrast': "e-contrast",
|
55
|
-
'effect_gray': "e-grayscale",
|
56
|
-
'original': "orig",
|
57
|
-
}
|
data/lib/imagekit/file.rb
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "./constants/errors"
|
4
|
-
require_relative "./constants/file"
|
5
|
-
require_relative "./constants/url"
|
6
|
-
|
7
|
-
require_relative "./utils/formatter"
|
8
|
-
|
9
|
-
class ImageKitFile
|
10
|
-
# This File class holds file related operations like
|
11
|
-
# upload, list etc
|
12
|
-
def initialize(req_obj)
|
13
|
-
@req_obj = req_obj
|
14
|
-
end
|
15
|
-
|
16
|
-
def upload(file, file_name, options)
|
17
|
-
# uploads files with required arguments
|
18
|
-
# supports bot url and binary
|
19
|
-
raise ArgumentError, MISSING_UPLOAD_FILE_PARAMETER unless file
|
20
|
-
raise ArgumentError, MISSING_UPLOAD_FILE_PARAMETER unless file_name
|
21
|
-
options = validate_upload_options(options || {})
|
22
|
-
if options.is_a?(FalseClass)
|
23
|
-
raise ArgumentError, "Invalid Upload option"
|
24
|
-
else
|
25
|
-
headers = @req_obj.create_headers
|
26
|
-
payload = {multipart: true, file: file, fileName: file_name}.merge(options)
|
27
|
-
|
28
|
-
url = "#{URL::BASE_URL}#{URL::UPLOAD}"
|
29
|
-
@req_obj.request("post", url, headers, payload)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def update_details(file_id, options)
|
34
|
-
# Update file detail by file_id and options
|
35
|
-
|
36
|
-
unless (options.key? :tags) || (options.key? :custom_coordinates)
|
37
|
-
raise ArgumentError, UPDATE_DATA_MISSING
|
38
|
-
end
|
39
|
-
unless options.fetch(:tags, []).is_a?(Array)
|
40
|
-
raise ArgumentError, UPDATE_DATA_TAGS_INVALID
|
41
|
-
end
|
42
|
-
unless options.fetch(:custom_coordinates, "").is_a?(String)
|
43
|
-
raise ArgumentError, UPDATE_DATA_COORDS_INVALID
|
44
|
-
end
|
45
|
-
url = "#{URL::BASE_URL}/#{file_id}/details/"
|
46
|
-
headers = @req_obj.create_headers
|
47
|
-
payload = request_formatter(options)
|
48
|
-
@req_obj.request("patch", url, headers, payload.to_json)
|
49
|
-
end
|
50
|
-
|
51
|
-
def list(options)
|
52
|
-
# returns list of files on ImageKit Server
|
53
|
-
# :options dictionary of options
|
54
|
-
formatted_options = request_formatter(options)
|
55
|
-
raise KeyError(LIST_FILES_INPUT_MISSING) unless formatted_options.is_a?(Hash)
|
56
|
-
url = URL::BASE_URL
|
57
|
-
headers = @req_obj.create_headers.update({params: options})
|
58
|
-
@req_obj.request("get", url, headers, options)
|
59
|
-
end
|
60
|
-
|
61
|
-
def details(file_identifier)
|
62
|
-
# Get detail of file by file_identifier
|
63
|
-
url = "#{URL::BASE_URL}/#{file_identifier}/details/"
|
64
|
-
headers = @req_obj.create_headers
|
65
|
-
@req_obj.request("get", url, headers)
|
66
|
-
end
|
67
|
-
|
68
|
-
def get_metadata(file_id)
|
69
|
-
# Get metadata of a file by file_id
|
70
|
-
url = "#{URL::BASE_URL}/#{file_id}/metadata"
|
71
|
-
@req_obj.request("get", url, @req_obj.create_headers)
|
72
|
-
end
|
73
|
-
|
74
|
-
def delete(file_id)
|
75
|
-
# Delete a file_id by file_id
|
76
|
-
url = "#{URL::BASE_URL}/#{file_id}"
|
77
|
-
headers = @req_obj.create_headers
|
78
|
-
@req_obj.request("delete", url, headers)
|
79
|
-
end
|
80
|
-
|
81
|
-
def batch_delete(file_ids)
|
82
|
-
url = "#{URL::BASE_URL}#{URL::BULK_FILE_DELETE}"
|
83
|
-
payload = {'fileIds': file_ids}
|
84
|
-
@req_obj.request("post", url, @req_obj.create_headers, payload.to_json)
|
85
|
-
end
|
86
|
-
|
87
|
-
def purge_cache(file_url)
|
88
|
-
|
89
|
-
# purges cache from server by file_url
|
90
|
-
|
91
|
-
url = "#{URL::BASE_URL}/purge"
|
92
|
-
payload = {'url': file_url}
|
93
|
-
@req_obj.request("post", url, @req_obj.create_headers, payload)
|
94
|
-
end
|
95
|
-
|
96
|
-
def purge_cache_status(request_id)
|
97
|
-
# This function is to get cache_status
|
98
|
-
url = "#{URL::BASE_URL}/purge/#{request_id}"
|
99
|
-
@req_obj.request("get", url, @req_obj.create_headers)
|
100
|
-
end
|
101
|
-
|
102
|
-
def get_metadata_from_remote_url(remote_file_url)
|
103
|
-
if remote_file_url == ""
|
104
|
-
raise ArgumentError, "remote_file_url is required"
|
105
|
-
end
|
106
|
-
url = "#{URL::REMOTE_METADATA_FULL_URL}?url=#{remote_file_url}"
|
107
|
-
@req_obj.request("get", url, @req_obj.create_headers)
|
108
|
-
end
|
109
|
-
|
110
|
-
def validate_upload_options(options)
|
111
|
-
|
112
|
-
# Validates upload value, checks if params are valid,
|
113
|
-
# changes snake to camel case which is supported by
|
114
|
-
# ImageKit server
|
115
|
-
|
116
|
-
|
117
|
-
response_list = []
|
118
|
-
options.each do |key, val|
|
119
|
-
if VALID_UPLOAD_OPTIONS.include?(key.to_s)
|
120
|
-
if val.is_a?(Array)
|
121
|
-
val = val.join(",")
|
122
|
-
end
|
123
|
-
if val.is_a?(TrueClass) || val.is_a?(FalseClass)
|
124
|
-
val = val.to_s
|
125
|
-
end
|
126
|
-
options[key] = val
|
127
|
-
else
|
128
|
-
return false
|
129
|
-
end
|
130
|
-
end
|
131
|
-
request_formatter(options)
|
132
|
-
end
|
133
|
-
end
|
data/lib/imagekit/imagekit.rb
DELETED
@@ -1,117 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
$VERBOSE = nil
|
4
|
-
|
5
|
-
require_relative "./resource"
|
6
|
-
require_relative "./file"
|
7
|
-
require_relative "./url"
|
8
|
-
require_relative "./utils/calculation"
|
9
|
-
|
10
|
-
module ImageKit
|
11
|
-
class Error < StandardError
|
12
|
-
end
|
13
|
-
|
14
|
-
# ImageKit class holds each method will be used by user
|
15
|
-
class ImageKitClient
|
16
|
-
attr_reader :file
|
17
|
-
|
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
|
-
|
30
|
-
@private_key = private_key
|
31
|
-
@public_key = public_key
|
32
|
-
@url_endpoint = url_endpoint
|
33
|
-
@transformation_position = transformation_pos
|
34
|
-
@options = options
|
35
|
-
|
36
|
-
@ik_req = ImageKitRequest.new(private_key, public_key, url_endpoint)
|
37
|
-
@file = ImageKitFile.new(@ik_req)
|
38
|
-
@url_obj = Url.new(@ik_req)
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
def set_ik_request(ik_req)
|
43
|
-
# setter for imagekit request mainly will be used for
|
44
|
-
# test
|
45
|
-
@ik_req = ik_req
|
46
|
-
end
|
47
|
-
|
48
|
-
def url(options)
|
49
|
-
@url_obj.generate_url(options)
|
50
|
-
end
|
51
|
-
|
52
|
-
def upload_file(file = nil, file_name = nil, options = nil)
|
53
|
-
# upload file to imagekit server
|
54
|
-
@file.upload(file, file_name, options)
|
55
|
-
end
|
56
|
-
|
57
|
-
def list_files(options)
|
58
|
-
# list all files
|
59
|
-
@file.list(options)
|
60
|
-
end
|
61
|
-
|
62
|
-
def get_file_details(file_identifier)
|
63
|
-
# Get file detail by file-id or file_url
|
64
|
-
@file.details(file_identifier)
|
65
|
-
end
|
66
|
-
|
67
|
-
def update_file_details(file_id, options)
|
68
|
-
# update file details by file id and other options payload
|
69
|
-
@file.update_details(file_id, options)
|
70
|
-
end
|
71
|
-
|
72
|
-
def delete_file(file_id)
|
73
|
-
# Delete a file by file-id
|
74
|
-
@file.delete(file_id)
|
75
|
-
end
|
76
|
-
|
77
|
-
def bulk_file_delete(file_ids)
|
78
|
-
# Delete file in bulks by list of file id
|
79
|
-
@file.batch_delete(file_ids)
|
80
|
-
end
|
81
|
-
|
82
|
-
def get_file_metadata(file_id)
|
83
|
-
# Get metadata of a file by file-id
|
84
|
-
@file.get_metadata(file_id)
|
85
|
-
end
|
86
|
-
|
87
|
-
def purge_file_cache(file_url)
|
88
|
-
# Purge cache from ImageKit server by file_url
|
89
|
-
@file.purge_cache(file_url)
|
90
|
-
end
|
91
|
-
|
92
|
-
def purge_file_cache_status(request_id)
|
93
|
-
@file.purge_cache_status(request_id.to_s)
|
94
|
-
end
|
95
|
-
|
96
|
-
def get_remote_file_url_metadata(remote_file_url = "")
|
97
|
-
@file.get_metadata_from_remote_url(remote_file_url)
|
98
|
-
end
|
99
|
-
|
100
|
-
# Get metadata from remote_file_url
|
101
|
-
# param remote_file_url: url string of remote file
|
102
|
-
|
103
|
-
def phash_distance(first, second)
|
104
|
-
# Get hamming distance between two phash(image hash) to check
|
105
|
-
# similarity between images
|
106
|
-
if first.to_s.strip == "" || second.to_s.strip == ""
|
107
|
-
raise ArgumentError, Error::MISSING_PHASH_VALUE
|
108
|
-
end
|
109
|
-
hamming_distance(first, second)
|
110
|
-
end
|
111
|
-
|
112
|
-
def get_authentication_parameters(token = nil, expire = nil)
|
113
|
-
# Get Authentication params
|
114
|
-
get_authenticated_params(token, expire, @ik_req.private_key)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
data/lib/imagekit/resource.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "base64"
|
4
|
-
require "rest-client"
|
5
|
-
require "json"
|
6
|
-
require_relative "./constants/defaults"
|
7
|
-
|
8
|
-
# ImageKitRequest requests and sends data from server
|
9
|
-
class ImageKitRequest
|
10
|
-
attr_reader :private_key, :public_key, :url_endpoint, :transformation_position, :options
|
11
|
-
|
12
|
-
def initialize(private_key, public_key, url_endpoint, transformation_position = nil, options = nil)
|
13
|
-
@private_key = private_key
|
14
|
-
@public_key = public_key
|
15
|
-
@url_endpoint = url_endpoint
|
16
|
-
@transformation_position = transformation_position || Default::TRANSFORMATION_POSITION
|
17
|
-
@options = options || {}
|
18
|
-
end
|
19
|
-
|
20
|
-
# creates required headers
|
21
|
-
def create_headers
|
22
|
-
headers = {'Accept-Encoding': "application/json", 'Content-Type': "application/json"}
|
23
|
-
headers.update(auth_headers)
|
24
|
-
end
|
25
|
-
|
26
|
-
def auth_headers
|
27
|
-
encoded_private_key = Base64.strict_encode64(@private_key+":")
|
28
|
-
{Authorization: "Basic #{encoded_private_key}"}
|
29
|
-
end
|
30
|
-
|
31
|
-
# request method communicates with server
|
32
|
-
def request(method, url, headers = nil, payload = nil)
|
33
|
-
headers ||= create_headers
|
34
|
-
response = {response: nil, error: nil}
|
35
|
-
begin
|
36
|
-
resp = RestClient::Request.new(method: method,
|
37
|
-
url: url,
|
38
|
-
headers: headers,
|
39
|
-
payload: payload).execute
|
40
|
-
|
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
|
47
|
-
elsif resp.code == 204
|
48
|
-
response[:response] = {'success': true}
|
49
|
-
end
|
50
|
-
|
51
|
-
rescue RestClient::ExceptionWithResponse => err
|
52
|
-
err.http_code == 404 ? response[:error] = {'message': err.response.to_s} : JSON.parse(err.response)
|
53
|
-
end
|
54
|
-
response
|
55
|
-
end
|
56
|
-
end
|