Class: Cloudinary::Api

Inherits:
Object show all
Defined in:
lib/cloudinary/api.rb

Defined Under Namespace

Classes: AlreadyExists, AuthorizationRequired, BadRequest, Error, GeneralError, NotAllowed, NotFound, RateLimited, Response

Class Method Summary collapse

Class Method Details

.create_transformation(name, definition, options = {}) ⇒ Object



148
149
150
# File 'lib/cloudinary/api.rb', line 148

def self.create_transformation(name, definition, options={})
  call_api(:post, "transformations/#{name}", {:transformation=>transformation_string(definition)}, options)
end

.create_upload_preset(options = {}) ⇒ Object



170
171
172
173
# File 'lib/cloudinary/api.rb', line 170

def self.create_upload_preset(options={})
  params = Cloudinary::Uploader.build_upload_params(options)
  call_api(:post, "upload_presets", params.merge(only(options, :name, :unsigned, :disallow_public_id)), options)
end

.delete_all_resources(options = {}) ⇒ Object



103
104
105
106
107
108
# File 'lib/cloudinary/api.rb', line 103

def self.delete_all_resources(options={})
  resource_type = options[:resource_type] || "image"
  type = options[:type] || "upload"    
  uri = "resources/#{resource_type}/#{type}"
  call_api(:delete, uri, {:all=>true}.merge(only(options, :keep_original, :next_cursor, :invalidate)), options)      
end

.delete_derived_resources(derived_resource_ids, options = {}) ⇒ Object



116
117
118
119
# File 'lib/cloudinary/api.rb', line 116

def self.delete_derived_resources(derived_resource_ids, options={})
  uri = "derived_resources"
  call_api(:delete, uri, {:derived_resource_ids=>derived_resource_ids}, options)      
end

.delete_resources(public_ids, options = {}) ⇒ Object



89
90
91
92
93
94
# File 'lib/cloudinary/api.rb', line 89

def self.delete_resources(public_ids, options={})
  resource_type = options[:resource_type] || "image"
  type = options[:type] || "upload"    
  uri = "resources/#{resource_type}/#{type}"
  call_api(:delete, uri, {:public_ids=>public_ids}.merge(only(options, :keep_original, :invalidate)), options)      
end

.delete_resources_by_prefix(prefix, options = {}) ⇒ Object



96
97
98
99
100
101
# File 'lib/cloudinary/api.rb', line 96

def self.delete_resources_by_prefix(prefix, options={})
  resource_type = options[:resource_type] || "image"
  type = options[:type] || "upload"    
  uri = "resources/#{resource_type}/#{type}"
  call_api(:delete, uri, {:prefix=>prefix}.merge(only(options, :keep_original, :next_cursor, :invalidate)), options)      
end

.delete_resources_by_tag(tag, options = {}) ⇒ Object



110
111
112
113
114
# File 'lib/cloudinary/api.rb', line 110

def self.delete_resources_by_tag(tag, options={})
  resource_type = options[:resource_type] || "image"
  uri = "resources/#{resource_type}/tags/#{tag}"
  call_api(:delete, uri, only(options, :keep_original, :next_cursor, :invalidate), options)    
end

.delete_transformation(transformation, options = {}) ⇒ Object



135
136
137
# File 'lib/cloudinary/api.rb', line 135

def self.delete_transformation(transformation, options={})
  call_api(:delete, "transformations/#{transformation_string(transformation)}", {}, options)    
end

.delete_upload_preset(name, options = {}) ⇒ Object



161
162
163
# File 'lib/cloudinary/api.rb', line 161

def self.delete_upload_preset(name, options={})
  call_api(:delete, "upload_presets/#{name}", {}, options)    
end

.ping(options = {}) ⇒ Object



22
23
24
# File 'lib/cloudinary/api.rb', line 22

def self.ping(options={})
  call_api(:get, "ping", {}, options)
end

.resource(public_id, options = {}) ⇒ Object



61
62
63
64
65
66
# File 'lib/cloudinary/api.rb', line 61

def self.resource(public_id, options={})
  resource_type = options[:resource_type] || "image"
  type = options[:type] || "upload"
  uri = "resources/#{resource_type}/#{type}/#{public_id}"
  call_api(:get, uri, only(options, :colors, :exif, :faces, :image_metadata, :pages, :phash, :coordinates, :max_results), options)      
end

.resource_types(options = {}) ⇒ Object



30
31
32
# File 'lib/cloudinary/api.rb', line 30

def self.resource_types(options={})
  call_api(:get, "resources", {}, options)
end

.resources(options = {}) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/cloudinary/api.rb', line 34

def self.resources(options={})
  resource_type = options[:resource_type] || "image"
  type = options[:type]
  uri = "resources/#{resource_type}"
  uri += "/#{type}" if !type.blank?
  call_api(:get, uri, only(options, :next_cursor, :max_results, :prefix, :tags, :context, :moderations, :direction, :start_at), options)    
end

.resources_by_ids(public_ids, options = {}) ⇒ Object



54
55
56
57
58
59
# File 'lib/cloudinary/api.rb', line 54

def self.resources_by_ids(public_ids, options={})
  resource_type = options[:resource_type] || "image"
  type = options[:type] || "upload"
  uri = "resources/#{resource_type}/#{type}"
  call_api(:get, uri, only(options, :tags, :context, :moderations).merge(:public_ids => public_ids), options)
end

.resources_by_moderation(kind, status, options = {}) ⇒ Object



48
49
50
51
52
# File 'lib/cloudinary/api.rb', line 48

def self.resources_by_moderation(kind, status, options={})
  resource_type = options[:resource_type] || "image"
  uri = "resources/#{resource_type}/moderations/#{kind}/#{status}"
  call_api(:get, uri, only(options, :next_cursor, :max_results, :tags, :context, :moderations, :direction), options)    
end

.resources_by_tag(tag, options = {}) ⇒ Object



42
43
44
45
46
# File 'lib/cloudinary/api.rb', line 42

def self.resources_by_tag(tag, options={})
  resource_type = options[:resource_type] || "image"
  uri = "resources/#{resource_type}/tags/#{tag}"
  call_api(:get, uri, only(options, :next_cursor, :max_results, :tags, :context, :moderations, :direction), options)    
end

.root_folders(options = {}) ⇒ Object



175
176
177
# File 'lib/cloudinary/api.rb', line 175

def self.root_folders(options={})
  call_api(:get, "folders", {}, options)
end

.subfolders(of_folder_path, options = {}) ⇒ Object



179
180
181
# File 'lib/cloudinary/api.rb', line 179

def self.subfolders(of_folder_path, options={})
  call_api(:get, "folders/#{of_folder_path}", {}, options)
end

.tags(options = {}) ⇒ Object



121
122
123
124
125
# File 'lib/cloudinary/api.rb', line 121

def self.tags(options={})
  resource_type = options[:resource_type] || "image"
  uri = "tags/#{resource_type}"
  call_api(:get, uri, only(options, :next_cursor, :max_results, :prefix), options)    
end

.transformation(transformation, options = {}) ⇒ Object



131
132
133
# File 'lib/cloudinary/api.rb', line 131

def self.transformation(transformation, options={})
  call_api(:get, "transformations/#{transformation_string(transformation)}", only(options, :max_results), options)    
end

.transformations(options = {}) ⇒ Object



127
128
129
# File 'lib/cloudinary/api.rb', line 127

def self.transformations(options={})
  call_api(:get, "transformations", only(options, :next_cursor, :max_results), options)    
end

.update(public_id, options = {}) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/cloudinary/api.rb', line 68

def self.update(public_id, options={})
  resource_type = options[:resource_type] || "image"
  type = options[:type] || "upload"
  uri = "resources/#{resource_type}/#{type}/#{public_id}"
  update_options = {
    :tags => options[:tags] && Cloudinary::Utils.build_array(options[:tags]).join(","),
    :context => Cloudinary::Utils.encode_hash(options[:context]),
    :face_coordinates => Cloudinary::Utils.encode_double_array(options[:face_coordinates]),
    :custom_coordinates => Cloudinary::Utils.encode_double_array(options[:custom_coordinates]),
    :moderation_status => options[:moderation_status],
    :raw_convert => options[:raw_convert],
    :ocr => options[:ocr],
    :categorization => options[:categorization],
    :detection => options[:detection],
    :similarity_search => options[:similarity_search],
    :background_removal => options[:background_removal],
    :auto_tagging => options[:auto_tagging] && options[:auto_tagging].to_f
  }
  call_api(:post, uri, update_options, options)
end

.update_transformation(transformation, updates, options = {}) ⇒ Object

updates - supports:

"allowed_for_strict" boolean
"unsafe_update" transformation params - updates a named transformation parameters without regenerating existing images


142
143
144
145
146
# File 'lib/cloudinary/api.rb', line 142

def self.update_transformation(transformation, updates, options={})
  params = only(updates, :allowed_for_strict)
  params[:unsafe_update] = transformation_string(updates[:unsafe_update]) if updates[:unsafe_update]
  call_api(:put, "transformations/#{transformation_string(transformation)}", params, options)
end

.update_upload_preset(name, options = {}) ⇒ Object



165
166
167
168
# File 'lib/cloudinary/api.rb', line 165

def self.update_upload_preset(name, options={})
  params = Cloudinary::Uploader.build_upload_params(options)
  call_api(:put, "upload_presets/#{name}", params.merge(only(options, :unsigned, :disallow_public_id)), options)
end

.upload_preset(name, options = {}) ⇒ Object



157
158
159
# File 'lib/cloudinary/api.rb', line 157

def self.upload_preset(name, options={})
  call_api(:get, "upload_presets/#{name}", only(options, :max_results), options)
end

.upload_presets(options = {}) ⇒ Object

upload presets



153
154
155
# File 'lib/cloudinary/api.rb', line 153

def self.upload_presets(options={})
  call_api(:get, "upload_presets", only(options, :next_cursor, :max_results), options)    
end

.usage(options = {}) ⇒ Object



26
27
28
# File 'lib/cloudinary/api.rb', line 26

def self.usage(options={})
  call_api(:get, "usage", {}, options)
end