cloudinary 1.0.48 → 1.0.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/cloudinary/carrier_wave.rb +13 -0
- data/lib/cloudinary/uploader.rb +19 -8
- data/lib/cloudinary/utils.rb +21 -0
- data/lib/cloudinary/version.rb +1 -1
- data/spec/uploader_spec.rb +62 -0
- data/spec/utils_spec.rb +12 -0
- metadata +4 -2
@@ -79,6 +79,19 @@ module Cloudinary::CarrierWave
|
|
79
79
|
@public_id ||= self.public_id
|
80
80
|
@public_id ||= @stored_public_id
|
81
81
|
@public_id ||= Cloudinary::Utils.random_public_id
|
82
|
+
end
|
83
|
+
|
84
|
+
def rename(to_public_id)
|
85
|
+
raise "rename cannot be used if the public_id method is overridden" if self.public_id
|
86
|
+
resource_type = Cloudinary::Utils.resource_type_for_format(self.filename || self.format)
|
87
|
+
from_public_id = self.my_public_id
|
88
|
+
@public_id = @stored_public_id = to_public_id
|
89
|
+
if resource_type == 'raw'
|
90
|
+
from_public_id = [from_public_id, self.format].join(".")
|
91
|
+
to_public_id = [to_public_id, self.format].join(".")
|
92
|
+
end
|
93
|
+
Cloudinary::Uploader.rename(from_public_id, to_public_id, :type=>self.storage_type, :resource_type=>resource_type)
|
94
|
+
storage.store_cloudinary_version(@stored_version)
|
82
95
|
end
|
83
96
|
|
84
97
|
def recreate_versions!
|
data/lib/cloudinary/uploader.rb
CHANGED
@@ -21,18 +21,18 @@ class Cloudinary::Uploader
|
|
21
21
|
:callback=> options[:callback],
|
22
22
|
:format=>options[:format],
|
23
23
|
:type=>options[:type],
|
24
|
-
:backup=>options[:backup],
|
25
|
-
:faces=>options[:faces],
|
26
|
-
:exif=>options[:exif],
|
27
|
-
:colors=>options[:colors],
|
28
|
-
:image_metadata=>options[:image_metadata],
|
29
|
-
:invalidate=>options[:invalidate],
|
24
|
+
:backup=>Cloudinary::Utils.as_safe_bool(options[:backup]),
|
25
|
+
:faces=>Cloudinary::Utils.as_safe_bool(options[:faces]),
|
26
|
+
:exif=>Cloudinary::Utils.as_safe_bool(options[:exif]),
|
27
|
+
:colors=>Cloudinary::Utils.as_safe_bool(options[:colors]),
|
28
|
+
:image_metadata=>Cloudinary::Utils.as_safe_bool(options[:image_metadata]),
|
29
|
+
:invalidate=>Cloudinary::Utils.as_safe_bool(options[:invalidate]),
|
30
30
|
:eager=>build_eager(options[:eager]),
|
31
31
|
:headers=>build_custom_headers(options[:headers]),
|
32
|
-
:use_filename=>options[:use_filename],
|
32
|
+
:use_filename=>Cloudinary::Utils.as_safe_bool(options[:use_filename]),
|
33
33
|
:notification_url=>options[:notification_url],
|
34
34
|
:eager_notification_url=>options[:eager_notification_url],
|
35
|
-
:eager_async=>options[:eager_async],
|
35
|
+
:eager_async=>Cloudinary::Utils.as_safe_bool(options[:eager_async]),
|
36
36
|
:tags=>options[:tags] && Cloudinary::Utils.build_array(options[:tags]).join(",")}
|
37
37
|
params
|
38
38
|
end
|
@@ -60,6 +60,17 @@ class Cloudinary::Uploader
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
def self.rename(from_public_id, to_public_id, options={})
|
64
|
+
call_api("rename", options) do
|
65
|
+
{
|
66
|
+
:timestamp=>Time.now.to_i,
|
67
|
+
:type=>options[:type],
|
68
|
+
:from_public_id=>from_public_id,
|
69
|
+
:to_public_id=>to_public_id,
|
70
|
+
}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
63
74
|
def self.exists?(public_id, options={})
|
64
75
|
cloudinary_url = Cloudinary::Utils.cloudinary_url(public_id, options)
|
65
76
|
begin
|
data/lib/cloudinary/utils.rb
CHANGED
@@ -272,4 +272,25 @@ class Cloudinary::Utils
|
|
272
272
|
return options.delete(option_name) if options.include?(option_name)
|
273
273
|
return Cloudinary.config.send(option_name) || default_value
|
274
274
|
end
|
275
|
+
|
276
|
+
def self.as_bool(value)
|
277
|
+
case value
|
278
|
+
when nil then nil
|
279
|
+
when String then value.downcase == "true" || value == "1"
|
280
|
+
when TrueClass then true
|
281
|
+
when FalseClass then false
|
282
|
+
when Fixnum then value != 0
|
283
|
+
when Symbol then value == :true
|
284
|
+
else
|
285
|
+
raise "Invalid boolean value #{value} of type #{value.class}"
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
def self.as_safe_bool(value)
|
290
|
+
case as_bool(value)
|
291
|
+
when nil then nil
|
292
|
+
when TrueClass then 1
|
293
|
+
when FalseClass then 0
|
294
|
+
end
|
295
|
+
end
|
275
296
|
end
|
data/lib/cloudinary/version.rb
CHANGED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'cloudinary'
|
3
|
+
|
4
|
+
describe Cloudinary::Uploader do
|
5
|
+
break puts("Please setup environment for api test to run") if Cloudinary.config.api_secret.blank?
|
6
|
+
|
7
|
+
it "should successfully upload file " do
|
8
|
+
result = Cloudinary::Uploader.upload("spec/logo.png")
|
9
|
+
result["width"].should == 241
|
10
|
+
result["height"].should == 51
|
11
|
+
expected_signature = Cloudinary::Utils.api_sign_request({:public_id=>result["public_id"], :version=>result["version"]}, Cloudinary.config.api_secret)
|
12
|
+
result["signature"].should == expected_signature
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should successfully upload file by url " do
|
16
|
+
result = Cloudinary::Uploader.upload("http://cloudinary.com/images/logo.png")
|
17
|
+
result["width"].should == 241
|
18
|
+
result["height"].should == 51
|
19
|
+
expected_signature = Cloudinary::Utils.api_sign_request({:public_id=>result["public_id"], :version=>result["version"]}, Cloudinary.config.api_secret)
|
20
|
+
result["signature"].should == expected_signature
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should successfully upload file by unicode url " do
|
24
|
+
result = Cloudinary::Uploader.upload("http://cloudinary.com/images/logo.png")
|
25
|
+
result["width"].should == 241
|
26
|
+
result["height"].should == 51
|
27
|
+
expected_signature = Cloudinary::Utils.api_sign_request({:public_id=>result["public_id"], :version=>result["version"]}, Cloudinary.config.api_secret)
|
28
|
+
result["signature"].should == expected_signature
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should support explicit " do
|
32
|
+
result = Cloudinary::Uploader.explicit("cloudinary", :type=>"twitter_name", :eager=>[{:crop=>"scale", :width=>"2.0"}])
|
33
|
+
url = Cloudinary::Utils.cloudinary_url("cloudinary", :type=>"twitter_name", :crop=>"scale", :width=>"2.0", :format=>"png", :version=>result["version"])
|
34
|
+
result["eager"][0]["url"].should == url
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should support eager " do
|
38
|
+
Cloudinary::Uploader.upload("spec/logo.png", :eager=>[{:crop=>"scale", :width=>"2.0"}])
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should support headers " do
|
42
|
+
Cloudinary::Uploader.upload("spec/logo.png", :headers=>["Link: 1"])
|
43
|
+
Cloudinary::Uploader.upload("spec/logo.png", :headers=>{"Link" => "1"})
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should successfully generate text image " do
|
47
|
+
result = Cloudinary::Uploader.text("hello world")
|
48
|
+
result["width"].should > 1
|
49
|
+
result["height"].should > 1
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should successfully upload file " do
|
53
|
+
result = Cloudinary::Uploader.upload("spec/logo.png")
|
54
|
+
Cloudinary::Uploader.add_tag("tag1", result["public_id"])
|
55
|
+
Cloudinary::Uploader.add_tag("tag2", result["public_id"])
|
56
|
+
Cloudinary::Api.resource(result["public_id"])["tags"].should == ["tag1", "tag2"]
|
57
|
+
Cloudinary::Uploader.remove_tag("tag1", result["public_id"])
|
58
|
+
Cloudinary::Api.resource(result["public_id"])["tags"].should == ["tag2"]
|
59
|
+
Cloudinary::Uploader.replace_tag("tag3", result["public_id"])
|
60
|
+
Cloudinary::Api.resource(result["public_id"])["tags"].should == ["tag3"]
|
61
|
+
end
|
62
|
+
end
|
data/spec/utils_spec.rb
CHANGED
@@ -378,4 +378,16 @@ describe Cloudinary::Utils do
|
|
378
378
|
Cloudinary::Uploader.build_upload_params(options)[:transformation].should == "c_scale,w_100"
|
379
379
|
options.length.should == 2
|
380
380
|
end
|
381
|
+
|
382
|
+
it "build_upload_params canonize booleans" do
|
383
|
+
options = {:backup=>true, :use_filename=>false, :colors=>"true", :exif=>"false", :colors=>:true,
|
384
|
+
:image_metadata=>:false, :invalidate=>1, :eager_async=>"1"}
|
385
|
+
params = Cloudinary::Uploader.build_upload_params(options)
|
386
|
+
Cloudinary::Api.only(params, *options.keys).should == {
|
387
|
+
:backup=>1, :use_filename=>0, :colors=>1, :exif=>0, :colors=>1,
|
388
|
+
:image_metadata=>0, :invalidate=>1, :eager_async=>1
|
389
|
+
}
|
390
|
+
Cloudinary::Uploader.build_upload_params(:backup=>nil)[:backup].should be_nil
|
391
|
+
Cloudinary::Uploader.build_upload_params({})[:backup].should be_nil
|
392
|
+
end
|
381
393
|
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.
|
4
|
+
version: 1.0.49
|
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: 2013-03-
|
14
|
+
date: 2013-03-21 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rest-client
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- spec/api_spec.rb
|
103
103
|
- spec/logo.png
|
104
104
|
- spec/spec_helper.rb
|
105
|
+
- spec/uploader_spec.rb
|
105
106
|
- spec/utils_spec.rb
|
106
107
|
- vendor/assets/javascripts/cloudinary/canvas-to-blob.min.js
|
107
108
|
- vendor/assets/javascripts/cloudinary/index.js
|
@@ -142,4 +143,5 @@ test_files:
|
|
142
143
|
- spec/api_spec.rb
|
143
144
|
- spec/logo.png
|
144
145
|
- spec/spec_helper.rb
|
146
|
+
- spec/uploader_spec.rb
|
145
147
|
- spec/utils_spec.rb
|