Class: ImageKit::ImageKitClient

Inherits:
Object
  • Object
show all
Defined in:
lib/imagekit/imagekit.rb

Overview

ImageKit class holds each method will be used by user

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(private_key, public_key, url_endpoint, transformation_pos = nil, options = nil) ⇒ ImageKitClient

Returns a new instance of ImageKitClient.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/imagekit/imagekit.rb', line 18

def initialize(private_key, public_key, url_endpoint, transformation_pos = nil, options = nil)
  @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

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



16
17
18
# File 'lib/imagekit/imagekit.rb', line 16

def file
  @file
end

Instance Method Details

#bulk_file_delete(file_ids) ⇒ Object



66
67
68
69
# File 'lib/imagekit/imagekit.rb', line 66

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) ⇒ Object



61
62
63
64
# File 'lib/imagekit/imagekit.rb', line 61

def delete_file(file_id)
  # Delete a file by file-id
  @file.delete(file_id)
end

#get_authentication_parameters(token = nil, expire = nil) ⇒ Object



102
103
104
105
# File 'lib/imagekit/imagekit.rb', line 102

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) ⇒ Object



51
52
53
54
# File 'lib/imagekit/imagekit.rb', line 51

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) ⇒ Object



71
72
73
74
# File 'lib/imagekit/imagekit.rb', line 71

def (file_id)
  # Get metadata of a file by file-id
  @file.(file_id)
end

#get_remote_file_url_metadata(remote_file_url = "") ⇒ Object



85
86
87
# File 'lib/imagekit/imagekit.rb', line 85

def (remote_file_url = "")
  @file.(remote_file_url)
end

#list_files(options) ⇒ Object



46
47
48
49
# File 'lib/imagekit/imagekit.rb', line 46

def list_files(options)
  # list all files
  @file.list(options)
end

#phash_distance(first, second) ⇒ Object

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



92
93
94
95
96
97
98
99
100
# File 'lib/imagekit/imagekit.rb', line 92

def phash_distance(first, second)
  # Get hamming distance between two phash(image hash) to check
  # similarity between images

  unless first && second
    raise ArgumentError, Error::MISSING_PHASH_VALUE
  end
  hamming_distance(first, second)
end

#purge_file_cache(file_url) ⇒ Object



76
77
78
79
# File 'lib/imagekit/imagekit.rb', line 76

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) ⇒ Object



81
82
83
# File 'lib/imagekit/imagekit.rb', line 81

def purge_file_cache_status(request_id)
  @file.purge_cache_status(request_id.to_s)
end

#set_ik_request(ik_req) ⇒ Object



31
32
33
34
35
# File 'lib/imagekit/imagekit.rb', line 31

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) ⇒ Object



56
57
58
59
# File 'lib/imagekit/imagekit.rb', line 56

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) ⇒ Object



41
42
43
44
# File 'lib/imagekit/imagekit.rb', line 41

def upload_file(file = nil, file_name = nil, options = nil)
  # upload file to imagekit server
  @file.upload(file, file_name, options)
end

#url(options) ⇒ Object



37
38
39
# File 'lib/imagekit/imagekit.rb', line 37

def url(options)
  @url_obj.generate_url(options)
end