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
30
31
32
33
34
35
36
37
38
39
40
# 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

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



77
78
79
80
# 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) ⇒ Object



72
73
74
75
# 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) ⇒ Object



112
113
114
115
# 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) ⇒ Object



62
63
64
65
# 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) ⇒ Object



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

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

#get_remote_file_url_metadata(remote_file_url = "") ⇒ Object



96
97
98
# File 'lib/imagekit/imagekit.rb', line 96

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

#list_files(options) ⇒ Object



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

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



103
104
105
106
107
108
109
110
# 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) ⇒ Object



87
88
89
90
# 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) ⇒ Object



92
93
94
# 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) ⇒ Object



42
43
44
45
46
# 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) ⇒ Object



67
68
69
70
# 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) ⇒ Object



52
53
54
55
# 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) ⇒ Object



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

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