cloudinary 1.0.70 → 1.0.71

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ = Version 1.0.71 - 2014-04-15
2
+ * Upload preset support.
3
+ * Unsigned upload support.
4
+ * phash upload parameter support.
5
+ * Resource listing by start_at support.
6
+ * Updating to jQuery plugin v1.0.14.
7
+
1
8
  = Version 1.0.70 - 2014-03-25
2
9
  * Support upload_large without public_id.
3
10
  * Remove public_id from method parameters.
@@ -36,7 +36,7 @@ class Cloudinary::Api
36
36
  type = options[:type]
37
37
  uri = "resources/#{resource_type}"
38
38
  uri += "/#{type}" if !type.blank?
39
- call_api(:get, uri, only(options, :next_cursor, :max_results, :prefix, :tags, :context, :moderations, :direction), options)
39
+ call_api(:get, uri, only(options, :next_cursor, :max_results, :prefix, :tags, :context, :moderations, :direction, :start_at), options)
40
40
  end
41
41
 
42
42
  def self.resources_by_tag(tag, options={})
@@ -147,6 +147,29 @@ class Cloudinary::Api
147
147
  call_api(:post, "transformations/#{name}", {:transformation=>transformation_string(definition)}, options)
148
148
  end
149
149
 
150
+ # upload presets
151
+ def self.upload_presets(options={})
152
+ call_api(:get, "upload_presets", only(options, :next_cursor, :max_results), options)
153
+ end
154
+
155
+ def self.upload_preset(name, options={})
156
+ call_api(:get, "upload_presets/#{name}", only(options, :max_results), options)
157
+ end
158
+
159
+ def self.delete_upload_preset(name, options={})
160
+ call_api(:delete, "upload_presets/#{name}", {}, options)
161
+ end
162
+
163
+ def self.update_upload_preset(name, options={})
164
+ params = Cloudinary::Uploader.build_upload_params(options)
165
+ call_api(:put, "upload_presets/#{name}", params.merge(only(options, :unsigned, :disallow_public_id)), options)
166
+ end
167
+
168
+ def self.create_upload_preset(options={})
169
+ params = Cloudinary::Uploader.build_upload_params(options)
170
+ call_api(:post, "upload_presets", params.merge(only(options, :name, :unsigned, :disallow_public_id)), options)
171
+ end
172
+
150
173
  protected
151
174
 
152
175
  def self.call_api(method, uri, params, options)
@@ -158,6 +158,10 @@ module CloudinaryHelper
158
158
  cl_image_upload_tag("#{object_name}[#{method}]", options)
159
159
  end
160
160
 
161
+ def cl_unsigned_image_upload(object_name, method, upload_preset, options={})
162
+ cl_unsigned_image_upload_tag("#{object_name}[#{method}]", upload_preset, options)
163
+ end
164
+
161
165
  def cl_upload_url(options={})
162
166
  Cloudinary::Utils.cloudinary_api_url("upload", {:resource_type=>:auto}.merge(options))
163
167
  end
@@ -165,7 +169,11 @@ module CloudinaryHelper
165
169
  def cl_upload_tag_params(options={})
166
170
  cloudinary_params = Cloudinary::Uploader.build_upload_params(options)
167
171
  cloudinary_params[:callback] = build_callback_url(options)
168
- return Cloudinary::Utils.sign_request(cloudinary_params, options).to_json
172
+ if options[:unsigned]
173
+ return cloudinary_params.reject{|k, v| Cloudinary::Utils.safe_blank?(v)}.to_json
174
+ else
175
+ return Cloudinary::Utils.sign_request(cloudinary_params, options).to_json
176
+ end
169
177
  end
170
178
 
171
179
  def cl_image_upload_tag(field, options={})
@@ -180,6 +188,10 @@ module CloudinaryHelper
180
188
  content_tag("input", nil, tag_options)
181
189
  end
182
190
 
191
+ def cl_unsigned_image_upload_tag(field, upload_preset, options={})
192
+ cl_image_upload_tag(field, options.merge(:unsigned => true, :upload_preset => upload_preset))
193
+ end
194
+
183
195
  def cl_private_download_url(public_id, format, options = {})
184
196
  Cloudinary::Utils.private_download_url(public_id, format, options)
185
197
  end
@@ -243,6 +255,9 @@ module Cloudinary::FormBuilder
243
255
  def cl_image_upload(method, options={})
244
256
  @template.cl_image_upload(@object_name, method, objectify_options(options))
245
257
  end
258
+ def cl_unsigned_image_upload(method, upload_preset, options={})
259
+ @template.cl_unsigned_image_upload(@object_name, method, upload_preset, objectify_options(options))
260
+ end
246
261
  end
247
262
 
248
263
  if defined? ActionView::Helpers::AssetUrlHelper
@@ -15,6 +15,10 @@ class Cloudinary::Uploader
15
15
  end
16
16
 
17
17
  def self.build_upload_params(options)
18
+ #symbolize keys
19
+ options = options.clone
20
+ options.keys.each{|key| options[key.to_sym] = options.delete(key) if key.is_a?(String)}
21
+
18
22
  params = {:timestamp=>Time.now.to_i,
19
23
  :transformation => Cloudinary::Utils.generate_transformation_string(options.clone),
20
24
  :public_id=> options[:public_id],
@@ -48,9 +52,15 @@ class Cloudinary::Uploader
48
52
  :categorization => options[:categorization],
49
53
  :detection => options[:detection],
50
54
  :similarity_search => options[:similarity_search],
51
- :auto_tagging => options[:auto_tagging] && options[:auto_tagging].to_f}
55
+ :auto_tagging => options[:auto_tagging] && options[:auto_tagging].to_f,
56
+ :upload_preset => options[:upload_preset],
57
+ :phash => Cloudinary::Utils.as_safe_bool(options[:phash])}
52
58
  params
53
59
  end
60
+
61
+ def self.unsigned_upload(file, upload_preset, options={})
62
+ upload(file, options.merge(:unsigned => true, :upload_preset => upload_preset))
63
+ end
54
64
 
55
65
  def self.upload(file, options={})
56
66
  call_api("upload", options) do
@@ -258,8 +268,10 @@ class Cloudinary::Uploader
258
268
  params, non_signable = yield
259
269
  non_signable ||= []
260
270
 
261
- params[:signature] = Cloudinary::Utils.api_sign_request(params.reject{|k,v| non_signable.include?(k)}, api_secret)
262
- params[:api_key] = api_key
271
+ unless options[:unsigned]
272
+ params[:signature] = Cloudinary::Utils.api_sign_request(params.reject{|k,v| non_signable.include?(k)}, api_secret)
273
+ params[:api_key] = api_key
274
+ end
263
275
 
264
276
  result = nil
265
277
 
@@ -186,7 +186,7 @@ class Cloudinary::Utils
186
186
  def self.sign_request(params, options={})
187
187
  api_key = options[:api_key] || Cloudinary.config.api_key || raise(CloudinaryException, "Must supply api_key")
188
188
  api_secret = options[:api_secret] || Cloudinary.config.api_secret || raise(CloudinaryException, "Must supply api_secret")
189
- params = params.reject{|k, v| v.blank?}
189
+ params = params.reject{|k, v| self.class.safe_blank?(v)}
190
190
  params[:signature] = Cloudinary::Utils.api_sign_request(params, api_secret)
191
191
  params[:api_key] = api_key
192
192
  params
@@ -328,4 +328,8 @@ class Cloudinary::Utils
328
328
  when FalseClass then 0
329
329
  end
330
330
  end
331
+
332
+ def self.safe_blank?(value)
333
+ value.nil? || value == "" || value == []
334
+ end
331
335
  end
@@ -1,4 +1,4 @@
1
1
  # Copyright Cloudinary
2
2
  module Cloudinary
3
- VERSION = "1.0.70"
3
+ VERSION = "1.0.71"
4
4
  end
data/spec/api_spec.rb CHANGED
@@ -13,6 +13,10 @@ describe Cloudinary::Api do
13
13
  @api.delete_transformation("api_test_transformation") rescue nil
14
14
  @api.delete_transformation("api_test_transformation2") rescue nil
15
15
  @api.delete_transformation("api_test_transformation3") rescue nil
16
+ @api.delete_upload_preset("api_test_upload_preset") rescue nil
17
+ @api.delete_upload_preset("api_test_upload_preset2") rescue nil
18
+ @api.delete_upload_preset("api_test_upload_preset3") rescue nil
19
+ @api.delete_upload_preset("api_test_upload_preset4") rescue nil
16
20
  end
17
21
 
18
22
  it "should allow listing resource_types" do
@@ -65,6 +69,15 @@ describe Cloudinary::Api do
65
69
  resources.map{|resource| resource["context"]}.should include({"custom" => {"key" => "value"}})
66
70
  end
67
71
 
72
+ it "should allow listing resources by start date", :start_at => true do
73
+ sleep(2)
74
+ start_at = Time.now.to_s
75
+ sleep(2)
76
+ response = Cloudinary::Uploader.upload("spec/logo.png")
77
+ resources = @api.resources(:type=>"upload", :start_at=>start_at, :direction => "asc")["resources"]
78
+ resources.map{|resource| resource["public_id"]}.should == [response["public_id"]]
79
+ end
80
+
68
81
  it "should allow listing resources in both directions" do
69
82
  asc_resources = @api.resources(:type=>"upload", :prefix=>"api_test", :direction => "asc")["resources"]
70
83
  desc_resources = @api.resources(:type=>"upload", :prefix=>"api_test", :direction => "desc")["resources"]
@@ -191,6 +204,47 @@ describe Cloudinary::Api do
191
204
  lambda{@api.transformation("c_scale,w_100")}.should raise_error(Cloudinary::Api::NotFound)
192
205
  end
193
206
 
207
+ it "should allow creating and listing upload_presets", :upload_preset => true do
208
+ @api.create_upload_preset(:name => "api_test_upload_preset", :folder => "folder")
209
+ @api.create_upload_preset(:name => "api_test_upload_preset2", :folder => "folder2")
210
+ @api.create_upload_preset(:name => "api_test_upload_preset3", :folder => "folder3")
211
+ @api.upload_presets["presets"].first(3).map{|p| p["name"]}.should == ["api_test_upload_preset3", "api_test_upload_preset2", "api_test_upload_preset"]
212
+ @api.delete_upload_preset("api_test_upload_preset")
213
+ @api.delete_upload_preset("api_test_upload_preset2")
214
+ @api.delete_upload_preset("api_test_upload_preset3")
215
+ end
216
+
217
+ it "should allow getting a single upload_preset", :upload_preset => true do
218
+ result = @api.create_upload_preset(:unsigned => true, :folder => "folder", :width => 100, :crop => :scale, :tags => ["a","b","c"], :context => {:a => "b", :c => "d"})
219
+ name = result["name"]
220
+ preset = @api.upload_preset(name)
221
+ preset["name"].should == name
222
+ preset["unsigned"].should == true
223
+ preset["settings"]["folder"].should == "folder"
224
+ preset["settings"]["transformation"].should == [{"width" => 100, "crop" => "scale"}]
225
+ preset["settings"]["context"].should == {"a" => "b", "c" => "d"}
226
+ preset["settings"]["tags"].should == ["a","b","c"]
227
+ @api.delete_upload_preset(name)
228
+ end
229
+
230
+ it "should allow deleting upload_presets", :upload_preset => true do
231
+ @api.create_upload_preset(:name => "api_test_upload_preset4", :folder => "folder")
232
+ preset = @api.upload_preset("api_test_upload_preset4")
233
+ @api.delete_upload_preset("api_test_upload_preset4")
234
+ lambda{preset = @api.upload_preset("api_test_upload_preset4")}.should raise_error
235
+ end
236
+
237
+ it "should allow updating upload_presets", :upload_preset => true do
238
+ name = @api.create_upload_preset(:folder => "folder")["name"]
239
+ preset = @api.upload_preset(name)
240
+ @api.update_upload_preset(name, preset["settings"].merge(:colors => true, :unsigned => true, :disallow_public_id => true))
241
+ preset = @api.upload_preset(name)
242
+ preset["name"].should == name
243
+ preset["unsigned"].should == true
244
+ preset["settings"].should == {"folder" => "folder", "colors" => true, "disallow_public_id" => true}
245
+ @api.delete_upload_preset(name)
246
+ end
247
+
194
248
  # this test must be last because it deletes (potentially) all dependent transformations which some tests rely on. Excluded by default.
195
249
  it "should allow deleting all resources", :delete_all=>true do
196
250
  Cloudinary::Uploader.upload("spec/logo.png", :public_id=>"api_test5", :eager=>[:width=>101,:crop=>:scale])
@@ -211,15 +265,10 @@ describe Cloudinary::Api do
211
265
  api_result["moderation"][0]["status"].should == "approved"
212
266
  api_result["moderation"][0]["kind"].should == "manual"
213
267
  end
214
-
215
- it "should support requesting ocr info" do
216
- result = Cloudinary::Uploader.upload("spec/logo.png")
217
- lambda{Cloudinary::Api.update(result["public_id"], {:ocr => :illegal})}.should raise_error(Cloudinary::Api::BadRequest, /^Illegal value/)
218
- end
219
-
268
+
220
269
  it "should support requesting raw conversion" do
221
270
  result = Cloudinary::Uploader.upload("spec/docx.docx", :resource_type => :raw)
222
- lambda{Cloudinary::Api.update(result["public_id"], {:resource_type => :raw, :raw_convert => :illegal})}.should raise_error(Cloudinary::Api::BadRequest, /^Illegal value/)
271
+ lambda{Cloudinary::Api.update(result["public_id"], {:resource_type => :raw, :raw_convert => :illegal})}.should raise_error(Cloudinary::Api::BadRequest, /^Illegal value|not a valid/)
223
272
  end
224
273
 
225
274
  it "should support requesting categorization" do
@@ -232,7 +281,7 @@ describe Cloudinary::Api do
232
281
  lambda{Cloudinary::Api.update(result["public_id"], {:detection => :illegal})}.should raise_error(Cloudinary::Api::BadRequest, /^Illegal value/)
233
282
  end
234
283
 
235
- it "should support requesting ocr info" do
284
+ it "should support requesting auto_tagging" do
236
285
  result = Cloudinary::Uploader.upload("spec/logo.png")
237
286
  lambda{Cloudinary::Api.update(result["public_id"], {:auto_tagging => 0.5})}.should raise_error(Cloudinary::Api::BadRequest, /^Must use/)
238
287
  end
@@ -113,21 +113,17 @@ describe Cloudinary::Uploader do
113
113
  result["moderation"][0]["status"].should == "pending"
114
114
  result["moderation"][0]["kind"].should == "manual"
115
115
  end
116
-
117
- it "should support requesting ocr info" do
118
- lambda{Cloudinary::Uploader.upload("spec/logo.png", {:ocr => :illegal})}.should raise_error(CloudinaryException, /Illegal value/)
119
- end
120
-
116
+
121
117
  it "should support requesting raw conversion" do
122
- lambda{Cloudinary::Uploader.upload("spec/docx.docx", {:resource_type => :raw, :raw_convert => :illegal})}.should raise_error(CloudinaryException, /Illegal value/)
118
+ lambda{Cloudinary::Uploader.upload("spec/docx.docx", {:resource_type => :raw, :raw_convert => :illegal})}.should raise_error(CloudinaryException, /Illegal value|not a valid/)
123
119
  end
124
120
 
125
121
  it "should support requesting categorization" do
126
- lambda{Cloudinary::Uploader.upload("spec/logo.png", {:categorization => :illegal})}.should raise_error(CloudinaryException, /Illegal value/)
122
+ lambda{Cloudinary::Uploader.upload("spec/logo.png", {:categorization => :illegal})}.should raise_error(CloudinaryException, /Illegal value|not a valid/)
127
123
  end
128
124
 
129
125
  it "should support requesting detection" do
130
- lambda{Cloudinary::Uploader.upload("spec/logo.png", {:detection => :illegal})}.should raise_error(CloudinaryException, /Illegal value/)
126
+ lambda{Cloudinary::Uploader.upload("spec/logo.png", {:detection => :illegal})}.should raise_error(CloudinaryException, /Illegal value|not a valid/)
131
127
  end
132
128
 
133
129
  it "should support requesting auto_tagging" do
@@ -138,4 +134,11 @@ describe Cloudinary::Uploader do
138
134
  result = Cloudinary::Uploader.upload_large("spec/logo.png")
139
135
  result["public_id"].should match(/^[a-z0-9]+.png$/)
140
136
  end
137
+
138
+ it "should support unsigned uploading using presets", :upload_preset => true do
139
+ preset = Cloudinary::Api.create_upload_preset(:folder => "upload_folder", :unsigned => true)
140
+ result = Cloudinary::Uploader.unsigned_upload("spec/logo.png", preset["name"])
141
+ result["public_id"].should match(/^upload_folder\/[a-z0-9]+$/)
142
+ Cloudinary::Api.delete_upload_preset(preset["name"])
143
+ end
141
144
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudinary
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.70
4
+ version: 1.0.71
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-03-25 00:00:00.000000000 Z
14
+ date: 2014-04-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rest-client