qiniu_jxb_fix 6.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/.travis.yml +12 -0
- data/CHANGELOG.md +146 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +44 -0
- data/LICENSE +22 -0
- data/README.md +47 -0
- data/Rakefile +21 -0
- data/docs/README.md +790 -0
- data/lib/qiniu/abstract.rb +22 -0
- data/lib/qiniu/adt.rb +46 -0
- data/lib/qiniu/auth.rb +255 -0
- data/lib/qiniu/config.rb +60 -0
- data/lib/qiniu/exceptions.rb +120 -0
- data/lib/qiniu/fop.rb +4 -0
- data/lib/qiniu/http.rb +137 -0
- data/lib/qiniu/image.rb +38 -0
- data/lib/qiniu/log.rb +15 -0
- data/lib/qiniu/management.rb +166 -0
- data/lib/qiniu/misc.rb +35 -0
- data/lib/qiniu/pfop.rb +124 -0
- data/lib/qiniu/resumable_upload.rb +319 -0
- data/lib/qiniu/storage.rb +5 -0
- data/lib/qiniu/tokens/access_token.rb +23 -0
- data/lib/qiniu/tokens/download_token.rb +36 -0
- data/lib/qiniu/tokens/qbox_token.rb +38 -0
- data/lib/qiniu/tokens/upload_token.rb +57 -0
- data/lib/qiniu/upload.rb +134 -0
- data/lib/qiniu/utils.rb +109 -0
- data/lib/qiniu/version.rb +17 -0
- data/lib/qiniu-rs.rb +2 -0
- data/lib/qiniu.rb +209 -0
- data/qiniu.gemspec +29 -0
- data/rails3/Gemfile +4 -0
- data/rails3/qiniu.gemspec +29 -0
- data/spec/qiniu/abstract_spec.rb +30 -0
- data/spec/qiniu/auth_spec.rb +74 -0
- data/spec/qiniu/image_logo_for_test.png +0 -0
- data/spec/qiniu/image_spec.rb +80 -0
- data/spec/qiniu/management_spec.rb +163 -0
- data/spec/qiniu/misc_spec.rb +53 -0
- data/spec/qiniu/pfop_spec.rb +80 -0
- data/spec/qiniu/qiniu_spec.rb +321 -0
- data/spec/qiniu/tokens/qbox_token_spec.rb +29 -0
- data/spec/qiniu/upload_spec.rb +301 -0
- data/spec/qiniu/utils_spec.rb +49 -0
- data/spec/qiniu/version_spec.rb +10 -0
- data/spec/spec_helper.rb +19 -0
- metadata +222 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'qiniu/abstract'
|
5
|
+
|
6
|
+
describe Qiniu::Abstract do
|
7
|
+
before(:each) do
|
8
|
+
@klass = Class.new do
|
9
|
+
include Qiniu::Abstract
|
10
|
+
|
11
|
+
abstract_methods :foo, :bar
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "raises NotImplementedError" do
|
16
|
+
proc {
|
17
|
+
@klass.new.foo
|
18
|
+
}.should raise_error(NotImplementedError)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "can be overridden" do
|
22
|
+
subclass = Class.new(@klass) do
|
23
|
+
def foo
|
24
|
+
:overridden
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
subclass.new.foo.should == :overridden
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# vim: sw=2 ts=2
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
require 'qiniu/auth'
|
6
|
+
require 'qiniu/storage'
|
7
|
+
require 'digest/sha1'
|
8
|
+
|
9
|
+
module Qiniu
|
10
|
+
module Auth
|
11
|
+
describe Auth do
|
12
|
+
|
13
|
+
before :all do
|
14
|
+
@bucket = 'rubysdk'
|
15
|
+
end
|
16
|
+
after :all do
|
17
|
+
end
|
18
|
+
|
19
|
+
### 测试私有资源下载
|
20
|
+
context ".download_private_file" do
|
21
|
+
it "should works" do
|
22
|
+
### 生成Key
|
23
|
+
key = 'a_private_file'
|
24
|
+
key = make_unique_key_in_bucket(key)
|
25
|
+
puts "key=#{key}"
|
26
|
+
|
27
|
+
### 上传测试文件
|
28
|
+
pp = Auth::PutPolicy.new(@bucket, key)
|
29
|
+
code, data, raw_headers = Qiniu::Storage.upload_with_put_policy(
|
30
|
+
pp,
|
31
|
+
__FILE__
|
32
|
+
)
|
33
|
+
code.should == 200
|
34
|
+
puts data.inspect
|
35
|
+
puts raw_headers.inspect
|
36
|
+
|
37
|
+
### 获取下载地址
|
38
|
+
code, data = Qiniu::Storage.get(@bucket, key)
|
39
|
+
code.should == 200
|
40
|
+
puts data.inspect
|
41
|
+
|
42
|
+
url = data['url']
|
43
|
+
|
44
|
+
### 授权下载地址(不带参数)
|
45
|
+
download_url = Qiniu::Auth.authorize_download_url(url)
|
46
|
+
puts "download_url=#{download_url}"
|
47
|
+
|
48
|
+
result = RestClient.get(download_url)
|
49
|
+
result.code.should == 200
|
50
|
+
result.body.should_not be_empty
|
51
|
+
|
52
|
+
### 授权下载地址(带参数)
|
53
|
+
download_url = Qiniu::Auth.authorize_download_url(
|
54
|
+
url,
|
55
|
+
{
|
56
|
+
:fop => 'download/a.m3u8'
|
57
|
+
}
|
58
|
+
)
|
59
|
+
puts "download_url=#{download_url}"
|
60
|
+
|
61
|
+
result = RestClient.get(download_url)
|
62
|
+
result.code.should == 200
|
63
|
+
result.body.should_not be_empty
|
64
|
+
|
65
|
+
### 删除文件
|
66
|
+
code, data = Qiniu::Storage.delete(@bucket, key)
|
67
|
+
code.should == 200
|
68
|
+
puts data.inspect
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end # module Storage
|
74
|
+
end # module Qiniu
|
Binary file
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'qiniu/auth'
|
5
|
+
require 'qiniu'
|
6
|
+
require 'qiniu/fop'
|
7
|
+
|
8
|
+
module Qiniu
|
9
|
+
module Fop
|
10
|
+
describe Fop do
|
11
|
+
|
12
|
+
before :all do
|
13
|
+
@bucket = 'rubysdk'
|
14
|
+
pic_fname = "image_logo_for_test.png"
|
15
|
+
@key = make_unique_key_in_bucket(pic_fname)
|
16
|
+
|
17
|
+
local_file = File.expand_path('../' + pic_fname, __FILE__)
|
18
|
+
|
19
|
+
upopts = {
|
20
|
+
:scope => @bucket,
|
21
|
+
:expires_in => 3600,
|
22
|
+
:customer => "why404@gmail.com",
|
23
|
+
:async_options => "imageView/1/w/120/h/120",
|
24
|
+
:return_body => '{"size":$(fsize), "hash":$(etag), "width":$(imageInfo.width), "height":$(imageInfo.height)}'
|
25
|
+
}
|
26
|
+
uptoken = Qiniu.generate_upload_token(upopts)
|
27
|
+
data = Qiniu.upload_file :uptoken => uptoken, :file => local_file, :bucket => @bucket, :key => @key
|
28
|
+
puts data.inspect
|
29
|
+
|
30
|
+
data["size"].should_not be_zero
|
31
|
+
data["hash"].should_not be_empty
|
32
|
+
data["width"].should_not be_zero
|
33
|
+
data["height"].should_not be_zero
|
34
|
+
|
35
|
+
result = Qiniu.get(@bucket, @key)
|
36
|
+
result["url"].should_not be_empty
|
37
|
+
puts result.inspect
|
38
|
+
@source_image_url = result["url"]
|
39
|
+
|
40
|
+
@mogrify_options = {
|
41
|
+
:thumbnail => "!120x120>",
|
42
|
+
:gravity => "center",
|
43
|
+
:crop => "!120x120a0a0",
|
44
|
+
:quality => 85,
|
45
|
+
:rotate => 45,
|
46
|
+
:format => "jpg",
|
47
|
+
:auto_orient => true
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
after :all do
|
52
|
+
end
|
53
|
+
|
54
|
+
context ".info" do
|
55
|
+
it "should works" do
|
56
|
+
code, data = Qiniu::Fop::Image.info(@source_image_url)
|
57
|
+
code.should == 200
|
58
|
+
puts data.inspect
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
=begin
|
63
|
+
context ".exif" do
|
64
|
+
it "should works" do
|
65
|
+
code, data = Qiniu::Fop::Image.exif(@source_image_url)
|
66
|
+
puts data.inspect
|
67
|
+
end
|
68
|
+
end
|
69
|
+
=end
|
70
|
+
|
71
|
+
context ".mogrify_preview_url" do
|
72
|
+
it "should works" do
|
73
|
+
mogrify_preview_url = Qiniu::Fop::Image.mogrify_preview_url(@source_image_url, @mogrify_options)
|
74
|
+
puts mogrify_preview_url.inspect
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end # module Fop
|
80
|
+
end # module Qiniu
|
@@ -0,0 +1,163 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# vim: sw=2 ts=2
|
3
|
+
|
4
|
+
require 'digest/sha1'
|
5
|
+
require 'spec_helper'
|
6
|
+
require 'qiniu/auth'
|
7
|
+
require 'qiniu/management'
|
8
|
+
require 'qiniu'
|
9
|
+
|
10
|
+
module Qiniu
|
11
|
+
module Storage
|
12
|
+
describe Storage do
|
13
|
+
|
14
|
+
before :all do
|
15
|
+
@bucket = 'rubysdk'
|
16
|
+
|
17
|
+
@key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s)
|
18
|
+
@key = make_unique_key_in_bucket(@key)
|
19
|
+
|
20
|
+
@key2 = @key + rand(100).to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
after :all do
|
24
|
+
end
|
25
|
+
|
26
|
+
### 准备数据
|
27
|
+
context ".prepare_file" do
|
28
|
+
it "should works" do
|
29
|
+
pp = Auth::PutPolicy.new(@bucket, @key)
|
30
|
+
code, data, raw_headers = Qiniu::Storage.upload_with_put_policy(
|
31
|
+
pp,
|
32
|
+
__FILE__
|
33
|
+
)
|
34
|
+
code.should == 200
|
35
|
+
puts data.inspect
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context ".list" do
|
40
|
+
it "should works" do
|
41
|
+
bucket_name = 'rubysdk'
|
42
|
+
test_policy = Qiniu::Storage::ListPolicy.new(bucket_name, 1)
|
43
|
+
|
44
|
+
while !(Storage.list(test_policy)[1]['items'].empty?)
|
45
|
+
list_policy = Qiniu::Storage::ListPolicy.new(bucket_name)
|
46
|
+
Storage.list(list_policy)[1]['items'].each do |item|
|
47
|
+
puts Storage.delete(bucket_name, item['key'])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
### 列举Bucket
|
53
|
+
context ".buckets" do
|
54
|
+
it "should works" do
|
55
|
+
code, data = Storage.buckets
|
56
|
+
code.should == 200
|
57
|
+
puts data.inspect
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context ".stat" do
|
62
|
+
it "should works" do
|
63
|
+
code, data = Storage.stat(@bucket, @key)
|
64
|
+
code.should == 200
|
65
|
+
puts data.inspect
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context ".get" do
|
70
|
+
it "should works" do
|
71
|
+
code, data = Storage.get(@bucket, @key)
|
72
|
+
code.should == 200
|
73
|
+
puts data.inspect
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context ".batch" do
|
78
|
+
it "should works" do
|
79
|
+
code, data = Storage.batch("stat", @bucket, [@key])
|
80
|
+
code.should == 200
|
81
|
+
puts data.inspect
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context ".batch_stat" do
|
86
|
+
it "should works" do
|
87
|
+
code, data = Storage.batch_stat(@bucket, [@key])
|
88
|
+
code.should == 200
|
89
|
+
puts data.inspect
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context ".batch_get" do
|
94
|
+
it "should works" do
|
95
|
+
code, data = Storage.batch_get(@bucket, [@key])
|
96
|
+
code.should == 200
|
97
|
+
puts data.inspect
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context ".batch_copy" do
|
102
|
+
it "should works" do
|
103
|
+
code, data = Storage.batch_copy @bucket, @key, @bucket, @key2
|
104
|
+
code.should == 200
|
105
|
+
puts data.inspect
|
106
|
+
|
107
|
+
code, data = Storage.delete @bucket, @key2
|
108
|
+
code.should == 200
|
109
|
+
puts data.inspect
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context ".batch_move" do
|
114
|
+
it "should works" do
|
115
|
+
code, data = Storage.batch_move @bucket, @key, @bucket, @key2
|
116
|
+
code.should == 200
|
117
|
+
puts data.inspect
|
118
|
+
|
119
|
+
code3, data3 = Storage.batch_move @bucket, @key2, @bucket, @key
|
120
|
+
code3.should == 200
|
121
|
+
puts data3.inspect
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context ".move" do
|
126
|
+
it "should works" do
|
127
|
+
code, data = Storage.move(@bucket, @key, @bucket, @key2)
|
128
|
+
code.should == 200
|
129
|
+
puts data.inspect
|
130
|
+
|
131
|
+
code2, data2 = Storage.stat(@bucket, @key2)
|
132
|
+
code2.should == 200
|
133
|
+
puts data2.inspect
|
134
|
+
|
135
|
+
code3, data3 = Storage.move(@bucket, @key2, @bucket, @key)
|
136
|
+
code3.should == 200
|
137
|
+
puts data3.inspect
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context ".copy" do
|
142
|
+
it "should works" do
|
143
|
+
code, data = Storage.copy(@bucket, @key, @bucket, @key2)
|
144
|
+
code.should == 200
|
145
|
+
puts data.inspect
|
146
|
+
|
147
|
+
code, data = Storage.delete(@bucket, @key2)
|
148
|
+
code.should == 200
|
149
|
+
puts data.inspect
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context ".delete" do
|
154
|
+
it "should works" do
|
155
|
+
code, data = Storage.delete(@bucket, @key)
|
156
|
+
code.should == 200
|
157
|
+
puts data.inspect
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
end # module Storage
|
163
|
+
end # module Qiniu
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'qiniu/auth'
|
5
|
+
require 'qiniu'
|
6
|
+
require 'qiniu/misc'
|
7
|
+
|
8
|
+
module Qiniu
|
9
|
+
module Misc
|
10
|
+
describe Misc do
|
11
|
+
|
12
|
+
before :all do
|
13
|
+
@bucket = 'rubysdk'
|
14
|
+
end
|
15
|
+
|
16
|
+
after :all do
|
17
|
+
end
|
18
|
+
|
19
|
+
context ".set_protected" do
|
20
|
+
it "should works" do
|
21
|
+
code, data = Qiniu::Misc.set_protected(@bucket, 1)
|
22
|
+
code.should == 200
|
23
|
+
puts data.inspect
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context ".set_separator" do
|
28
|
+
it "should works" do
|
29
|
+
code, data = Qiniu::Misc.set_separator(@bucket, "-")
|
30
|
+
code.should == 200
|
31
|
+
puts data.inspect
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context ".set_style" do
|
36
|
+
it "should works" do
|
37
|
+
code, data = Qiniu::Misc.set_style(@bucket, "small.jpg", "imageMogr/auto-orient/thumbnail/!120x120r/gravity/center/crop/!120x120/quality/80")
|
38
|
+
code.should == 200
|
39
|
+
puts data.inspect
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context ".unset_style" do
|
44
|
+
it "should works" do
|
45
|
+
code, data = Qiniu::Misc.unset_style(@bucket, "small.jpg")
|
46
|
+
code.should == 200
|
47
|
+
puts data.inspect
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end # module Misc
|
53
|
+
end # module Qiniu
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# vim: sw=2 ts=2
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
require 'qiniu/auth'
|
6
|
+
require 'qiniu'
|
7
|
+
require 'qiniu/fop'
|
8
|
+
|
9
|
+
module Qiniu
|
10
|
+
module Fop
|
11
|
+
module Persistance
|
12
|
+
describe Persistance do
|
13
|
+
|
14
|
+
before :all do
|
15
|
+
@bucket = 'rubysdk'
|
16
|
+
|
17
|
+
pic_fname = "image_logo_for_test.png"
|
18
|
+
@key = make_unique_key_in_bucket(pic_fname)
|
19
|
+
|
20
|
+
local_file = File.expand_path('../' + pic_fname, __FILE__)
|
21
|
+
|
22
|
+
### 检查测试文件存在性
|
23
|
+
code, body, headers = Qiniu::Storage.stat(@bucket, @key)
|
24
|
+
if code == 404 || code == 612 then
|
25
|
+
# 文件不存在,尝试上传
|
26
|
+
pp = Qiniu::Auth.PutPolicy.new(@bucket, @key)
|
27
|
+
code, body, headers = Qiniu::Storage.upload_with_put_policy(
|
28
|
+
pp,
|
29
|
+
local_file
|
30
|
+
)
|
31
|
+
puts "Put a test file for Persistance cases"
|
32
|
+
puts code.inspect
|
33
|
+
puts body.inspect
|
34
|
+
puts header.inspect
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
after :all do
|
39
|
+
end
|
40
|
+
|
41
|
+
context ".pfop" do
|
42
|
+
it "should works" do
|
43
|
+
pp = Persistance::PfopPolicy.new(
|
44
|
+
@bucket,
|
45
|
+
@key,
|
46
|
+
'imageView2/1/w/80/h/80', # fops
|
47
|
+
'www.baidu.com' # notify_url
|
48
|
+
)
|
49
|
+
|
50
|
+
code, data, headers = Qiniu::Fop::Persistance.pfop(pp)
|
51
|
+
code.should == 200
|
52
|
+
puts data.inspect
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context ".prefop" do
|
57
|
+
it "should works" do
|
58
|
+
code, data, headers = Qiniu::Fop::Persistance.prefop('fakePersistentId')
|
59
|
+
code.should == 612
|
60
|
+
puts code.inspect
|
61
|
+
puts data.inspect
|
62
|
+
puts headers.inspect
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context ".p1" do
|
67
|
+
it "should works" do
|
68
|
+
url = 'http://fake.qiniudn.com/fake.jpg'
|
69
|
+
fop = 'imageView2/1/w/80/h/80'
|
70
|
+
target_url = "#{url}?p/1/#{CGI.escape(fop).gsub('+', '%20')}"
|
71
|
+
|
72
|
+
p1_url = Qiniu::Fop::Persistance.generate_p1_url(url, fop)
|
73
|
+
p1_url.should == target_url
|
74
|
+
puts p1_url.inspect
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end # module Persistance
|
79
|
+
end # module Fop
|
80
|
+
end # module Qiniu
|