imagekitio 1.0.10 → 2.1.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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +292 -82
  3. data/Rakefile +1 -1
  4. data/lib/active_storage/active_storage.rb +2 -0
  5. data/lib/active_storage/service/ik_file.rb +111 -0
  6. data/lib/active_storage/service/image_kit_io_service.rb +188 -0
  7. data/lib/carrierwave/carrierwave.rb +79 -0
  8. data/lib/carrierwave/storage/ik_file.rb +8 -7
  9. data/lib/carrierwave/storage/imagekit_store.rb +54 -51
  10. data/lib/carrierwave/support/uri_filename.rb +9 -7
  11. data/lib/imagekitio/api_service/bulk.rb +58 -0
  12. data/lib/imagekitio/api_service/custom_metadata_field.rb +52 -0
  13. data/lib/imagekitio/api_service/file.rb +175 -0
  14. data/lib/imagekitio/api_service/folder.rb +49 -0
  15. data/lib/imagekitio/base.rb +12 -0
  16. data/lib/imagekitio/client.rb +186 -0
  17. data/lib/imagekitio/configurable.rb +43 -0
  18. data/lib/imagekitio/constant.rb +36 -0
  19. data/lib/imagekitio/constants/default.rb +22 -0
  20. data/lib/imagekitio/constants/error.rb +69 -0
  21. data/lib/imagekitio/constants/file.rb +11 -0
  22. data/lib/imagekitio/constants/supported_transformation.rb +64 -0
  23. data/lib/imagekitio/constants/url.rb +14 -0
  24. data/lib/imagekitio/errors.rb +4 -0
  25. data/lib/imagekitio/railtie.rb +1 -1
  26. data/lib/imagekitio/request.rb +91 -0
  27. data/lib/imagekitio/sdk/version.rb +5 -0
  28. data/lib/imagekitio/url.rb +241 -0
  29. data/lib/imagekitio/utils/calculation.rb +44 -0
  30. data/lib/imagekitio/utils/formatter.rb +48 -0
  31. data/lib/imagekitio/utils/option_validator.rb +36 -0
  32. data/lib/imagekitio.rb +10 -83
  33. metadata +55 -15
  34. data/lib/imagekit/constants/defaults.rb +0 -20
  35. data/lib/imagekit/constants/errors.rb +0 -77
  36. data/lib/imagekit/constants/file.rb +0 -5
  37. data/lib/imagekit/constants/supported_transformation.rb +0 -57
  38. data/lib/imagekit/constants/url.rb +0 -9
  39. data/lib/imagekit/file.rb +0 -133
  40. data/lib/imagekit/imagekit.rb +0 -117
  41. data/lib/imagekit/resource.rb +0 -56
  42. data/lib/imagekit/sdk/version.rb +0 -5
  43. data/lib/imagekit/url.rb +0 -237
  44. data/lib/imagekit/utils/calculation.rb +0 -36
  45. data/lib/imagekit/utils/formatter.rb +0 -29
@@ -0,0 +1,175 @@
1
+ # frozen_string_literal: true
2
+ require_relative '../constant'
3
+ require_relative '../utils/option_validator'
4
+ require 'net/http/post/multipart'
5
+
6
+ module ImageKitIo
7
+ module ApiService
8
+ class File
9
+ include Utils::OptionValidator
10
+ include Constantable
11
+
12
+ # This File class holds file related operations like
13
+ # upload, list etc
14
+ def initialize(req_obj)
15
+ @req_obj = req_obj
16
+ end
17
+
18
+ # uploads files with required arguments, supports bot url and binary
19
+ # Options types:
20
+ # - `extensions` should be array of hash
21
+ # eg: option['extension'] = [
22
+ # { 'name' => 'remove-bg', 'options' => { 'add_shadow' => 'true' } },
23
+ # { 'name' => 'google-auto-tagging', 'minConfidence' => 80 }
24
+ # ]
25
+ # - `custom_metadata` should be hash
26
+ # eg: option['custom_metadata'] = {
27
+ # "SKU": "VS882HJ2JD",
28
+ # "price": 599.99,
29
+ # "brand": "H&M",
30
+ # "discount": 30
31
+ # }
32
+ def upload(file: nil, file_name: nil, **options)
33
+ raise ArgumentError, constants.MISSING_UPLOAD_FILE_PARAMETER unless file
34
+ raise ArgumentError, constants.MISSING_UPLOAD_FILE_PARAMETER unless file_name
35
+
36
+ content_type = options.delete(:content_type) || ''
37
+ options = format_to_json(options, :extensions, Array)
38
+ options = format_to_json(options, :custom_metadata, Hash)
39
+ options = validate_upload_options(options || {})
40
+ if options.is_a?(FalseClass)
41
+ raise ArgumentError, "Invalid Upload option"
42
+ else
43
+ headers = @req_obj.create_headers
44
+ payload = {
45
+ multipart: true,
46
+ file: file.is_a?(String) ? file : ::UploadIO.new(file, content_type, file_name),
47
+ fileName: file_name
48
+ }
49
+ payload.merge!(options)
50
+ url = "#{constants.BASE_URL}#{constants.UPLOAD}"
51
+ @req_obj.request("post", url, headers, payload)
52
+ end
53
+ end
54
+
55
+ def update_details(file_id: nil, **options)
56
+ unless options.fetch(:tags, []).is_a?(Array)
57
+ raise ArgumentError, constants.UPDATE_DATA_TAGS_INVALID
58
+ end
59
+ unless options.fetch(:custom_coordinates, "").is_a?(String)
60
+ raise ArgumentError, constants.UPDATE_DATA_COORDS_INVALID
61
+ end
62
+ url = "#{constants.BASE_URL}/#{file_id}/details/"
63
+ headers = @req_obj.create_headers
64
+ payload = request_formatter(options || {})
65
+ @req_obj.request("patch", url, headers, payload.to_json)
66
+ end
67
+
68
+ def list(**options)
69
+ # returns list of files on ImageKitIo Server
70
+ # :options dictionary of options
71
+ formatted_options = request_formatter(options || {})
72
+ raise KeyError(constants.LIST_FILES_INPUT_MISSING) unless formatted_options.is_a?(Hash)
73
+ url = constants.BASE_URL
74
+ headers = @req_obj.create_headers.update({params: formatted_options})
75
+ @req_obj.request("get", url, headers, formatted_options)
76
+ end
77
+
78
+ def details(file_identifier: nil)
79
+ # Get detail of file by file_identifier
80
+ if file_identifier == "" || file_identifier.nil?
81
+ raise ArgumentError, "file_identifier is required"
82
+ end
83
+ url = "#{constants.BASE_URL}/#{file_identifier}/details/"
84
+ headers = @req_obj.create_headers
85
+ @req_obj.request("get", url, headers)
86
+ end
87
+
88
+ def get_metadata(file_id: nil)
89
+ # Get metadata of a file by file_id
90
+ if file_id == "" || file_id.nil?
91
+ raise ArgumentError, "file_id is required"
92
+ end
93
+ url = "#{constants.BASE_URL}/#{file_id}/metadata"
94
+ @req_obj.request("get", url, @req_obj.create_headers)
95
+ end
96
+
97
+ def delete(file_id: nil)
98
+ # Delete a file_id by file_id
99
+ if file_id == "" || file_id.nil?
100
+ raise ArgumentError, "file_id is required"
101
+ end
102
+ url = "#{constants.BASE_URL}/#{file_id}"
103
+ headers = @req_obj.create_headers
104
+ @req_obj.request("delete", url, headers)
105
+ end
106
+
107
+ def purge_cache(file_url: nil)
108
+ # purges cache from server by file_url
109
+ if file_url == "" || file_url.nil?
110
+ raise ArgumentError, "file_url is required"
111
+ end
112
+ url = "#{constants.BASE_URL}/purge"
113
+ payload = {'url': file_url}
114
+ @req_obj.request("post", url, @req_obj.create_headers, payload)
115
+ end
116
+
117
+ def purge_cache_status(request_id: nil)
118
+ # This function is to get cache_status
119
+ if request_id == "" || request_id.nil?
120
+ raise ArgumentError, "remote_file_url is required"
121
+ end
122
+ url = "#{constants.BASE_URL}/purge/#{request_id}"
123
+ @req_obj.request("get", url, @req_obj.create_headers)
124
+ end
125
+
126
+ def get_metadata_from_remote_url(remote_file_url: nil)
127
+ if remote_file_url == "" || remote_file_url.nil?
128
+ raise ArgumentError, "remote_file_url is required"
129
+ end
130
+ url = "#{constants.REMOTE_METADATA_FULL_URL}?url=#{remote_file_url}"
131
+ @req_obj.request("get", url, @req_obj.create_headers)
132
+ end
133
+
134
+ def stream_file(remote_file_url: nil, &block)
135
+ if remote_file_url == '' || remote_file_url.nil?
136
+ raise ArgumentError, 'remote_file_url is required'
137
+ end
138
+ @req_obj.request_stream('get', remote_file_url, headers: @req_obj.create_headers, &block)
139
+ end
140
+
141
+ def copy(source_file_path: nil, destination_path: nil)
142
+ if source_file_path == '' || source_file_path.nil? || destination_path == '' || destination_path.nil?
143
+ raise ArgumentError, 'parameters required'
144
+ end
145
+ url = "#{constants.BASE_URL}/copy"
146
+ payload = { 'sourceFilePath': source_file_path, 'destinationPath': destination_path }
147
+ @req_obj.request('post', url, @req_obj.create_headers, payload)
148
+ end
149
+
150
+ def move(source_file_path: nil, destination_path: nil)
151
+ if source_file_path == '' || source_file_path.nil? || destination_path == '' || destination_path.nil?
152
+ raise ArgumentError, 'parameters required'
153
+ end
154
+ url = "#{constants.BASE_URL}/move"
155
+ payload = { 'sourceFilePath': source_file_path, 'destinationPath': destination_path }
156
+ @req_obj.request('post', url, @req_obj.create_headers, payload)
157
+ end
158
+
159
+ def rename(file_path: nil, new_file_name: nil, **options)
160
+ if file_path == '' || file_path.nil? || new_file_name == '' || new_file_name.nil?
161
+ raise ArgumentError, 'parameters required'
162
+ end
163
+ url = "#{constants.BASE_URL}/rename"
164
+ payload = { 'filePath': file_path, 'newFileName': new_file_name }.merge(request_formatter(options)).to_json
165
+ @req_obj.request('put', url, @req_obj.create_headers, payload)
166
+ end
167
+
168
+
169
+ private
170
+ def image_format?(type)
171
+ %(image/jpeg image/bmp image/apng image/avif image/gif image/ief image/svg+xml image/tiff image/x-icon image/rgb image/webp).include?(type)
172
+ end
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,49 @@
1
+ require_relative '../constant'
2
+
3
+ module ImageKitIo
4
+ module ApiService
5
+ class Folder
6
+ include Constantable
7
+
8
+ def initialize(req_obj)
9
+ @req_obj = req_obj
10
+ end
11
+
12
+ def create(folder_name: nil, parent_folder_path: nil)
13
+ if folder_name == '' || folder_name.nil?
14
+ raise ArgumentError, 'folder_name is required'
15
+ end
16
+ url = "#{constants.API_BASE_URL}/folder"
17
+ payload = { 'folderName': folder_name, 'parentFolderPath': parent_folder_path }.to_json
18
+ @req_obj.request('post', url, @req_obj.create_headers, payload)
19
+ end
20
+
21
+ def delete(folder_path: nil)
22
+ if folder_path == '' || folder_path.nil?
23
+ raise ArgumentError, 'folder_path is required'
24
+ end
25
+ url = "#{constants.API_BASE_URL}/folder"
26
+ payload = { 'folderPath': folder_path }
27
+ @req_obj.request('delete', url, @req_obj.create_headers, payload)
28
+ end
29
+
30
+ def copy(source_folder_path: nil, destination_path: nil)
31
+ if source_folder_path == '' || source_folder_path.nil? || destination_path == '' || destination_path.nil?
32
+ raise ArgumentError, 'Parameters required'
33
+ end
34
+ url = "#{constants.BULK_BASE_URL}/copyFolder"
35
+ payload = { 'sourceFolderPath': source_folder_path, 'destinationPath': destination_path }
36
+ @req_obj.request('post', url, @req_obj.create_headers, payload)
37
+ end
38
+
39
+ def move(source_folder_path: nil, destination_path: nil)
40
+ if source_folder_path == '' || source_folder_path.nil? || destination_path == '' || destination_path.nil?
41
+ raise ArgumentError, 'Parameters required'
42
+ end
43
+ url = "#{constants.BULK_BASE_URL}/moveFolder"
44
+ payload = { 'sourceFolderPath': source_folder_path, 'destinationPath': destination_path }
45
+ @req_obj.request('post', url, @req_obj.create_headers, payload)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,12 @@
1
+ require_relative './configurable'
2
+
3
+ module ImageKitIo
4
+ include ImageKitIo::Configurable
5
+
6
+ class << self
7
+ def client
8
+ ik_config = config
9
+ @client ||= ImageKitIo::Client.new(ik_config.private_key, ik_config.public_key, ik_config.url_endpoint)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,186 @@
1
+ # frozen_string_literal: true
2
+
3
+ $VERBOSE = nil
4
+
5
+ require_relative "./request"
6
+ require_relative "./url"
7
+ require_relative "./utils/calculation"
8
+ require_relative './constant'
9
+ require_relative './configurable'
10
+ require_relative './api_service/custom_metadata_field'
11
+ require_relative './api_service/folder'
12
+ require_relative './api_service/file'
13
+ require_relative './api_service/bulk'
14
+
15
+ module ImageKitIo
16
+ # ImageKitIo class holds each method will be used by user
17
+ class Client
18
+ include Utils::Calculation
19
+ include Constantable
20
+
21
+ attr_reader :file_service, :custom_metadata_field_service, :folder_service, :bulk_service
22
+
23
+ def initialize(private_key, public_key, url_endpoint, transformation_pos = nil, options = nil)
24
+ unless(private_key.is_a?(String) && private_key.to_s.strip.length != 0)
25
+ raise ArgumentError, constants.MISSING_PRIVATE_KEY
26
+ end
27
+ unless(public_key.is_a?(String) && public_key.to_s.strip.length != 0)
28
+ raise ArgumentError, constants.MISSING_PUBLIC_KEY
29
+ end
30
+ unless(url_endpoint.is_a?(String) && url_endpoint.to_s.strip.length != 0)
31
+ raise ArgumentError, constants.MISSING_URL_ENDPOINT
32
+ end
33
+
34
+ @private_key = private_key
35
+ @public_key = public_key
36
+ @url_endpoint = url_endpoint
37
+ @transformation_position = transformation_pos
38
+ @options = options
39
+
40
+ @ik_req = Request.new(private_key, public_key, url_endpoint)
41
+ @url_obj = Url.new(@ik_req)
42
+ @file_service = ApiService::File.new(@ik_req)
43
+ @custom_metadata_field_service = ApiService::CustomMetadataField.new(@ik_req)
44
+ @folder_service = ApiService::Folder.new(@ik_req)
45
+ @bulk_service = ApiService::Bulk.new(@ik_req)
46
+ end
47
+
48
+ def set_ik_request(ik_req)
49
+ # setter for imagekit request mainly will be used for
50
+ # test
51
+ @ik_req = ik_req
52
+ end
53
+
54
+ def url(options = {})
55
+ @url_obj.generate_url(options)
56
+ end
57
+
58
+ def upload_file(file: nil, file_name: nil, **options)
59
+ # upload file to imagekit server
60
+ @file_service.upload(file: file, file_name: file_name, **options)
61
+ end
62
+
63
+ def list_files(options = {})
64
+ # list all files
65
+ @file_service.list(**options)
66
+ end
67
+
68
+ def get_file_details(file_id: nil)
69
+ # Get file detail by file-id or file_url
70
+ @file_service.details(file_identifier: file_id)
71
+ end
72
+
73
+ def update_file_details(file_id: nil, **options)
74
+ # update file details by file id and other options payload
75
+ @file_service.update_details(file_id: file_id, **options)
76
+ end
77
+
78
+ def delete_file(file_id: nil)
79
+ # Delete a file by file-id
80
+ @file_service.delete(file_id: file_id)
81
+ end
82
+
83
+ def get_file_metadata(file_id: nil)
84
+ # Get metadata of a file by file-id
85
+ @file_service.get_metadata(file_id: file_id)
86
+ end
87
+
88
+ def purge_file_cache(file_url: nil)
89
+ # Purge cache from ImageKitIo server by file_url
90
+ @file_service.purge_cache(file_url: file_url)
91
+ end
92
+
93
+ def purge_file_cache_status(request_id: nil)
94
+ @file_service.purge_cache_status(request_id: request_id.to_s)
95
+ end
96
+
97
+ # Get metadata from remote_file_url
98
+ # param remote_file_url: url string of remote file
99
+ def get_remote_file_url_metadata(remote_file_url: "")
100
+ @file_service.get_metadata_from_remote_url(remote_file_url: remote_file_url)
101
+ end
102
+
103
+ def stream_file(file_url: nil, &block)
104
+ @file_service.stream_file(remote_file_url: file_url, &block)
105
+ end
106
+
107
+ def copy_file(source_file_path: nil, destination_path: nil)
108
+ @file_service.copy(source_file_path: source_file_path, destination_path: destination_path)
109
+ end
110
+
111
+ def move_file(source_file_path: nil, destination_path: nil)
112
+ @file_service.move(source_file_path: source_file_path, destination_path: destination_path)
113
+ end
114
+
115
+ def rename_file(file_path: nil, new_file_name: nil, **options)
116
+ @file_service.rename(file_path: file_path, new_file_name: new_file_name, **options)
117
+ end
118
+
119
+ def add_bulk_tags(file_ids: [], tags: [])
120
+ @bulk_service.add_tags(file_ids: file_ids, tags: tags)
121
+ end
122
+
123
+ def delete_bulk_files(file_ids: [])
124
+ # Delete file in bulks by list of file id
125
+ @bulk_service.remove_files(file_ids: file_ids)
126
+ end
127
+
128
+ def delete_bulk_tags(file_ids: [], tags: [])
129
+ @bulk_service.remove_tags(file_ids: file_ids, tags: tags)
130
+ end
131
+
132
+ def delete_bulk_ai_tags(file_ids: [], ai_tags: [])
133
+ @bulk_service.remove_ai_tags(file_ids: file_ids, ai_tags: ai_tags)
134
+ end
135
+
136
+ def bulk_job_status(job_id: nil)
137
+ @bulk_service.job_status(job_id: job_id)
138
+ end
139
+
140
+ def create_folder(folder_name: nil, parent_folder_path: "/")
141
+ @folder_service.create(folder_name: folder_name, parent_folder_path: parent_folder_path)
142
+ end
143
+
144
+ def delete_folder(folder_path: nil)
145
+ @folder_service.delete(folder_path: folder_path)
146
+ end
147
+
148
+ def copy_folder(source_folder_path: nil, destination_path: nil)
149
+ @folder_service.copy(source_folder_path: source_folder_path, destination_path: destination_path)
150
+ end
151
+
152
+ def move_folder(source_folder_path: nil, destination_path: nil)
153
+ @folder_service.move(source_folder_path: source_folder_path, destination_path: destination_path)
154
+ end
155
+
156
+ def create_custom_metadata_field(name: nil, label: nil, schema: {})
157
+ @custom_metadata_field_service.create(name: name, label: label, schema: schema)
158
+ end
159
+
160
+ def get_custom_metadata_fields(options = {})
161
+ @custom_metadata_field_service.list(**options)
162
+ end
163
+
164
+ def update_custom_metadata_field(id: nil, label: nil, schema: nil)
165
+ @custom_metadata_field_service.update(id: id, label: label, schema: schema)
166
+ end
167
+
168
+ def delete_custom_metadata_field(id: nil)
169
+ @custom_metadata_field_service.delete(id: id)
170
+ end
171
+
172
+ def phash_distance(first, second)
173
+ # Get hamming distance between two phash(image hash) to check
174
+ # similarity between images
175
+ if first.to_s.strip == "" || second.to_s.strip == ""
176
+ raise ArgumentError, constants.MISSING_PHASH_VALUE
177
+ end
178
+ hamming_distance(first, second)
179
+ end
180
+
181
+ def get_authentication_parameters(token = nil, expire = nil)
182
+ # Get Authentication params
183
+ get_authenticated_params(token, expire, @ik_req.private_key)
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,43 @@
1
+ module ImageKitIo
2
+ module Configurable
3
+ def self.included(klass)
4
+ klass.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ def config
9
+ @config ||= Configuration.new
10
+ end
11
+
12
+ def configure
13
+ yield config
14
+ initialize_service
15
+ end
16
+
17
+ def initialize_service
18
+ if config.service == :carrierwave
19
+ require_relative '../carrierwave/carrierwave'
20
+ elsif config.service == :active_storage
21
+ require_relative '../active_storage/active_storage'
22
+ end
23
+ end
24
+
25
+ def constants
26
+ config.constants
27
+ end
28
+ end
29
+
30
+ class Configuration
31
+ AVAILABLE_SERVICE = [:carrierwave, :active_storage]
32
+ attr_accessor :public_key, :private_key, :url_endpoint, :service
33
+
34
+ def service
35
+ @service&.to_sym || :carrierwave
36
+ end
37
+
38
+ def constants
39
+ @constants ||= ImageKitIo::Constant
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,36 @@
1
+ require_relative './constants/default'
2
+ require_relative './constants/error'
3
+ require_relative './constants/file'
4
+ require_relative './constants/supported_transformation'
5
+ require_relative './constants/url'
6
+ require_relative './configurable'
7
+
8
+ module ImageKitIo
9
+ module Constantable
10
+ def self.included(base)
11
+ def constants
12
+ ImageKitIo.constants
13
+ end
14
+ end
15
+ end
16
+ class Constant
17
+ include Constants::Default
18
+ include Constants::Error
19
+ include Constants::File
20
+ include Constants::SupportedTransformation
21
+ include Constants::URL
22
+
23
+ class << self
24
+ def method_missing(symbol, *args)
25
+ method_name = symbol.to_s.gsub('=', '')
26
+ if self.const_defined? method_name
27
+ return self.const_get(method_name) if args.empty?
28
+
29
+ self.const_set(method_name, args.first)
30
+ else
31
+ super
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Enum for defaults
4
+ module ImageKitIo
5
+ module Constants
6
+ module Default
7
+ TRANSFORMATION_POSITION = "path"
8
+ QUERY_TRANSFORMATION_POSITION = "query"
9
+ VALID_TRANSFORMATION_POSITION = [TRANSFORMATION_POSITION,
10
+ QUERY_TRANSFORMATION_POSITION,].freeze
11
+ DEFAULT_TIMESTAMP = "9999999999"
12
+ TRANSFORMATION_PARAMETER = "tr"
13
+ CHAIN_TRANSFORM_DELIMITER = ":"
14
+ TRANSFORM_DELIMITER = ","
15
+ TRANSFORM_KEY_VALUE_DELIMITER = "-"
16
+
17
+ SIGNATURE_PARAMETER = "ik-s"
18
+ TIMESTAMP_PARAMETER = "ik-t"
19
+ TIMESTAMP = "9999999999"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,69 @@
1
+ module ImageKitIo
2
+ module Constants
3
+ module Error
4
+ MANDATORY_INIT_MISSING = {
5
+ 'message': "Missing public_key or private_key or url_endpoint during ImageKitIo initialization",
6
+ help: "",
7
+ }
8
+ INVALID_TRANSFORMATION_POS = {'message': "Invalid transformationPosition parameter",
9
+ help: "",}
10
+ INVALID_URL_GENERATION_PARAM = {'message': "Invalid url parameter", help: ""}
11
+ INVALID_TRANSFORMATION_OPTIONS = {
12
+ 'message': "Invalid transformation parameter options",
13
+ help: "",
14
+ }
15
+ CACHE_PURGE_URL_MISSING = {'message': "Missing URL parameter for this request",
16
+ help: "",}
17
+ CACHE_PURGE_STATUS_ID_MISSING = {'message': "Missing Request ID parameter for this request",
18
+ help: "",}
19
+ FILE_ID_MISSING = {'message': "Missing File ID parameter for this request",
20
+ help: "",}
21
+ UPDATE_DATA_MISSING = {'message': "Missing file update data for this request",
22
+ help: "",}
23
+
24
+ UPDATE_DATA_TAGS_INVALID = {'message': "Invalid tags parameter for this request",
25
+ help: "tags should be passed as null or an array like ['tag1', 'tag2']",}.freeze
26
+
27
+ UPDATE_DATA_COORDS_INVALID =
28
+ {'message': "Invalid custom_coordinates parameter for this request",
29
+ help: "custom_coordinates should be passed as null or a string like 'x,y,width,height'",}
30
+
31
+ LIST_FILES_INPUT_MISSING = {
32
+ 'message': "Missing options for list files",
33
+ help: "If you do not want to pass any parameter for listing, pass an empty object",
34
+ }
35
+ MISSING_FILE_URL = {'message': "Missing file_url for purge_cache", help: ""}
36
+ MISSING_UPLOAD_DATA = {'message': "Missing data for upload", help: ""}
37
+ MISSING_UPLOAD_FILE_PARAMETER = {
38
+ 'message': "Missing file parameter for upload",
39
+ help: "",
40
+ }
41
+ MISSING_UPLOAD_FILENAME_PARAM = {
42
+ 'message': "Missing fileName parameter for upload",
43
+ help: "",
44
+ }
45
+
46
+ INVALID_PHASH_VALUE =
47
+ {
48
+ 'message': "Invalid pHash value",
49
+ help: "Both pHash strings must be valid hexadecimal numbers",
50
+ }
51
+
52
+ MISSING_PHASH_VALUE = {
53
+ 'message': "Missing pHash value",
54
+ help: "Please pass two pHash values",
55
+ }
56
+ UNEQUAL_STRING_LENGTH = {
57
+ '': "Unequal pHash string length",
58
+ help: "For distance calculation, the two pHash strings must have equal length",
59
+ }
60
+
61
+ MISSING_PRIVATE_KEY = "ImageKitIo private key missing"
62
+
63
+ MISSING_PUBLIC_KEY = "ImageKitIo public key missing"
64
+
65
+ MISSING_URL_ENDPOINT = "ImageKitIo URL Endpoint missing. Default URL Endpoint: https://ik.imagekit.io/<YOUR_IMAGEKIT_ID>/"
66
+
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,11 @@
1
+ module ImageKitIo
2
+ module Constants
3
+ module File
4
+ VALID_FILE_OPTIONS = %w[path fileType tags includeFolder name limit skip]
5
+
6
+ VALID_FILE_DETAIL_OPTIONS = ["fileID"]
7
+
8
+ VALID_UPLOAD_OPTIONS = %w[file file_name use_unique_file_name tags folder is_private_file custom_coordinates response_fields extensions webhook_url overwrite_file overwrite_AI_tags overwrite_custom_metadata custom_metadata mime overwrite_tags content_type ]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,64 @@
1
+ module ImageKitIo
2
+ module Constants
3
+ module SupportedTransformation
4
+ SUPPORTED_TRANS = {
5
+ 'height': "h",
6
+ 'width': "w",
7
+ 'aspect_ratio': "ar",
8
+ 'quality': "q",
9
+ 'crop': "c",
10
+ 'crop_mode': "cm",
11
+ 'x': "x",
12
+ 'y': "y",
13
+ 'focus': "fo",
14
+ 'format': "f",
15
+ 'radius': "r",
16
+ 'background': "bg",
17
+ 'border': "b",
18
+ 'rotation': "rt",
19
+ 'blur': "bl",
20
+ 'named': "n",
21
+ 'overlay_image': "oi",
22
+ 'overlay_image_trim': "oit",
23
+ 'overlay_image_cropping': "oic",
24
+ 'overlay_image_quality': "oiq",
25
+ 'overlay_image_DPR': "oidpr",
26
+ 'overlay_image_border': "oib",
27
+ 'overlay_image_background': "oibg",
28
+ 'overlay_image_aspect_ratio': "oiar",
29
+ 'overlay_x': "ox",
30
+ 'overlay_y': "oy",
31
+ 'overlay_focus': "ofo",
32
+ 'overlay_height': "oh",
33
+ 'overlay_width': "ow",
34
+ 'overlay_text': "ot",
35
+ 'overlay_text_font_size': "ots",
36
+ 'overlay_text_font_family': "otf",
37
+ 'overlay_text_encoded': "ote",
38
+ 'overlay_text_color': "otc",
39
+ 'overlay_text_width': "otw",
40
+ 'overlay_text_background': "otbg",
41
+ 'overlay_text_padding': "otp",
42
+ 'overlay_text_inner_alignment': "otia",
43
+ 'overlay_text_transparency': "oa",
44
+ 'overlay_alpha': "oa",
45
+ 'overlay_radius': "or",
46
+ 'overlay_text_typography': "ott",
47
+ 'overlay_background': "obg",
48
+ 'progressive': "pr",
49
+ 'lossless': "lo",
50
+ 'trim': "t",
51
+ 'metadata': "md",
52
+ 'color_profile': "cp",
53
+ 'default_image': "di",
54
+ 'dpr': "dpr",
55
+ 'effect_sharpen': "e-sharpen",
56
+ 'effect_usm': "e-usm",
57
+ 'effect_contrast': "e-contrast",
58
+ 'effect_gray': "e-grayscale",
59
+ 'original': "orig",
60
+ 'raw': 'raw',
61
+ }
62
+ end
63
+ end
64
+ end