class ImageKit::ImageKitClient

ImageKit class holds each method will be used by user

Attributes

file[R]

Public Class Methods

new(private_key, public_key, url_endpoint, transformation_pos = nil, options = nil) click to toggle source
# File lib/imagekit/imagekit.rb, line 18
def initialize(private_key, public_key, url_endpoint, transformation_pos = nil, options = nil)

  unless(private_key.is_a?(String) && private_key.to_s.strip.length != 0)
    raise ArgumentError, MISSING_PRIVATE_KEY
  end
  unless(public_key.is_a?(String) && public_key.to_s.strip.length != 0)
    raise ArgumentError, MISSING_PUBLIC_KEY
  end
  unless(url_endpoint.is_a?(String) && url_endpoint.to_s.strip.length != 0)
    raise ArgumentError, MISSING_URL_ENDPOINT
  end

  @private_key = private_key
  @public_key = public_key
  @url_endpoint = url_endpoint
  @transformation_position = transformation_pos
  @options = options

  @ik_req = ImageKitRequest.new(private_key, public_key, url_endpoint)
  @file = ImageKitFile.new(@ik_req)
  @url_obj = Url.new(@ik_req)

end

Public Instance Methods

bulk_file_delete(file_ids) click to toggle source
# File lib/imagekit/imagekit.rb, line 77
def bulk_file_delete(file_ids)
  # Delete file in bulks by list of file id
  @file.batch_delete(file_ids)
end
delete_file(file_id) click to toggle source
# File lib/imagekit/imagekit.rb, line 72
def delete_file(file_id)
  # Delete a file by file-id
  @file.delete(file_id)
end
get_authentication_parameters(token = nil, expire = nil) click to toggle source
# File lib/imagekit/imagekit.rb, line 112
def get_authentication_parameters(token = nil, expire = nil)
  # Get Authentication params
  get_authenticated_params(token, expire, @ik_req.private_key)
end
get_file_details(file_identifier) click to toggle source
# File lib/imagekit/imagekit.rb, line 62
def get_file_details(file_identifier)
  # Get file detail by file-id or file_url
  @file.details(file_identifier)
end
get_file_metadata(file_id) click to toggle source
# File lib/imagekit/imagekit.rb, line 82
def get_file_metadata(file_id)
  # Get metadata of a file by file-id
  @file.get_metadata(file_id)
end
get_remote_file_url_metadata(remote_file_url = "") click to toggle source
# File lib/imagekit/imagekit.rb, line 96
def get_remote_file_url_metadata(remote_file_url = "")
  @file.get_metadata_from_remote_url(remote_file_url)
end
list_files(options) click to toggle source
# File lib/imagekit/imagekit.rb, line 57
def list_files(options)
  # list all files
  @file.list(options)
end
phash_distance(first, second) click to toggle source

Get metadata from remote_file_url param remote_file_url: url string of remote file

# File lib/imagekit/imagekit.rb, line 103
def phash_distance(first, second)
  # Get hamming distance between two phash(image hash) to check
  # similarity between images
  if first.to_s.strip == "" || second.to_s.strip == ""
    raise ArgumentError, Error::MISSING_PHASH_VALUE
  end
  hamming_distance(first, second)
end
purge_file_cache(file_url) click to toggle source
# File lib/imagekit/imagekit.rb, line 87
def purge_file_cache(file_url)
  # Purge cache from ImageKit server by file_url
  @file.purge_cache(file_url)
end
purge_file_cache_status(request_id) click to toggle source
# File lib/imagekit/imagekit.rb, line 92
def purge_file_cache_status(request_id)
  @file.purge_cache_status(request_id.to_s)
end
set_ik_request(ik_req) click to toggle source
# File lib/imagekit/imagekit.rb, line 42
def set_ik_request(ik_req)
  # setter for imagekit request mainly will be used for
  # test
  @ik_req = ik_req
end
update_file_details(file_id, options) click to toggle source
# File lib/imagekit/imagekit.rb, line 67
def update_file_details(file_id, options)
  # update file details by file id and other options payload
  @file.update_details(file_id, options)
end
upload_file(file = nil, file_name = nil, options = nil) click to toggle source
# File lib/imagekit/imagekit.rb, line 52
def upload_file(file = nil, file_name = nil, options = nil)
  # upload file to imagekit server
  @file.upload(file, file_name, options)
end
url(options) click to toggle source
# File lib/imagekit/imagekit.rb, line 48
def url(options)
  @url_obj.generate_url(options)
end