qiniu 6.0.1 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +2 -2
- data/README.md +4 -3
- data/lib/qiniu.rb +0 -10
- data/lib/qiniu/auth.rb +7 -7
- data/lib/qiniu/config.rb +0 -1
- data/lib/qiniu/upload.rb +0 -21
- data/lib/qiniu/utils.rb +5 -3
- data/lib/qiniu/version.rb +2 -2
- data/spec/qiniu/image_spec.rb +9 -7
- data/spec/qiniu/management_spec.rb +25 -48
- data/spec/qiniu/misc_spec.rb +5 -5
- data/spec/qiniu/qiniu_spec.rb +15 -71
- data/spec/qiniu/upload_spec.rb +128 -48
- data/spec/qiniu/utils_spec.rb +1 -1
- data/spec/spec_helper.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5df0656bef38c727a292ffe6ec54aba7ab0c8cac
|
4
|
+
data.tar.gz: 69d504ea0f9c61410e96600f55aa5cbea08f331e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c74fb96b07fee02ab56fb4b25b9ac52637ea478bd3da685238644c0f1b034662211d7b9d483d50b428fc5c69030cb5bae148e14ba0059c4029e80c1d9c498240
|
7
|
+
data.tar.gz: f76c79b88f64661c3876f77ecff944d9bb63ce25ac389d3cfb826abc515ce1646c5edfd44312ba43e907629114b61ca0801c6b883c920ba2312e3ae29a5f1b5a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
## CHANGE LOG
|
2
2
|
|
3
|
+
### v6.1.0
|
4
|
+
|
5
|
+
- Qiniu::Storage所有上传接口返回第三个值raw_headers,类型为Hash,包含已解析的HTTP响应报文中的所有Header信息。
|
6
|
+
|
7
|
+
该返回值主要用于调试。当遇到难以理解或解释的错误时,请将其中的X-Log和X-Reqid两项信息[通过邮件反馈](mailto:support@qiniu.com?subject=Ruby-SDK-Bug-Report)给我们。
|
8
|
+
|
9
|
+
- 更新Qiniu::Storage所有上传接口的测试用例,打印HTTP响应Header信息。
|
10
|
+
|
11
|
+
- 删除过时的Qiniu::Storage#put_file方法和相关测试用例。
|
12
|
+
|
13
|
+
该方法调用的API已过时并逐步废弃,建议用户尽快迁移到Qiniu::Storage#upload_with_token_2方法上。
|
14
|
+
|
3
15
|
### v6.0.1
|
4
16
|
|
5
17
|
- 重新划分命名空间,存储相关归入Qiniu::Storage,数据处理相关归入Qiniu::Fop,杂项相关归入Qiniu::Misc。
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
qiniu (6.0
|
4
|
+
qiniu (6.1.0)
|
5
5
|
json (~> 1.7)
|
6
6
|
mime-types (~> 1.19)
|
7
7
|
rest-client (~> 1.6)
|
@@ -12,7 +12,7 @@ GEM
|
|
12
12
|
specs:
|
13
13
|
diff-lcs (1.1.3)
|
14
14
|
fakeweb (1.3.0)
|
15
|
-
json (1.
|
15
|
+
json (1.8.1)
|
16
16
|
mime-types (1.23)
|
17
17
|
rake (10.0.3)
|
18
18
|
rest-client (1.6.7)
|
data/README.md
CHANGED
@@ -6,14 +6,15 @@
|
|
6
6
|
|
7
7
|
## 状态
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
[![Build Status](https://api.travis-ci.org/qiniu/ruby-sdk.png?branch=master)](https://travis-ci.org/qiniu/ruby-sdk)
|
10
|
+
[![Gem Version](https://badge.fury.io/rb/qiniu.png)](http://badge.fury.io/rb/qiniu)
|
11
|
+
[![Dependency Status](https://gemnasium.com/qiniu/ruby-sdk.png)](https://gemnasium.com/qiniu/ruby-sdk)
|
11
12
|
|
12
13
|
## 安装
|
13
14
|
|
14
15
|
在您 Ruby 应用程序的 `Gemfile` 文件中,添加如下一行代码:
|
15
16
|
|
16
|
-
gem 'qiniu'
|
17
|
+
gem 'qiniu', '~> 6.1.0'
|
17
18
|
|
18
19
|
然后,在应用程序所在的目录下,可以运行 `bundle` 安装依赖包:
|
19
20
|
|
data/lib/qiniu.rb
CHANGED
@@ -54,16 +54,6 @@ module Qiniu
|
|
54
54
|
code == StatusOK
|
55
55
|
end
|
56
56
|
|
57
|
-
def put_file opts = {}
|
58
|
-
code, data = Storage.put_file(opts[:file],
|
59
|
-
opts[:bucket],
|
60
|
-
opts[:key],
|
61
|
-
opts[:mime_type],
|
62
|
-
opts[:note],
|
63
|
-
opts[:enable_crc32_check])
|
64
|
-
code == StatusOK
|
65
|
-
end
|
66
|
-
|
67
57
|
def upload_file opts = {}
|
68
58
|
uncontained_opts = [:uptoken, :file, :bucket, :key] - opts.keys
|
69
59
|
raise MissingArgsError, uncontained_opts unless uncontained_opts.empty?
|
data/lib/qiniu/auth.rb
CHANGED
@@ -10,16 +10,16 @@ module Qiniu
|
|
10
10
|
include Utils
|
11
11
|
|
12
12
|
def call_with_signature(url, data, retry_times = 0, options = {})
|
13
|
-
code, data = http_request url, data, options.merge({:qbox_signature_token => generate_qbox_signature(url, data, options[:mime])})
|
14
|
-
[code, data]
|
15
|
-
end
|
13
|
+
code, data, raw_headers = http_request url, data, options.merge({:qbox_signature_token => generate_qbox_signature(url, data, options[:mime])})
|
14
|
+
[code, data, raw_headers]
|
15
|
+
end # call_with_signature
|
16
16
|
|
17
17
|
def request(url, data = nil, options = {})
|
18
|
-
code, data = Auth.call_with_signature(url, data, 0, options)
|
19
|
-
[code, data]
|
20
|
-
end
|
18
|
+
code, data, raw_headers = Auth.call_with_signature(url, data, 0, options)
|
19
|
+
[code, data, raw_headers]
|
20
|
+
end # request
|
21
21
|
|
22
|
-
end
|
22
|
+
end # class << self
|
23
23
|
|
24
24
|
end # module Auth
|
25
25
|
end # module Qiniu
|
data/lib/qiniu/config.rb
CHANGED
@@ -20,7 +20,6 @@ module Qiniu
|
|
20
20
|
:content_type => 'application/x-www-form-urlencoded',
|
21
21
|
:auth_url => "https://acc.qbox.me/oauth2/token",
|
22
22
|
:rs_host => "http://rs.qiniu.com",
|
23
|
-
:io_host => "http://iovip.qbox.me",
|
24
23
|
:up_host => "http://up.qiniu.com",
|
25
24
|
:pub_host => "http://pu.qbox.me:10200",
|
26
25
|
:eu_host => "http://eu.qbox.me",
|
data/lib/qiniu/upload.rb
CHANGED
@@ -5,27 +5,6 @@ module Qiniu
|
|
5
5
|
class << self
|
6
6
|
include Utils
|
7
7
|
|
8
|
-
def put_file(local_file,
|
9
|
-
bucket,
|
10
|
-
key = nil,
|
11
|
-
mime_type = nil,
|
12
|
-
custom_meta = nil,
|
13
|
-
enable_crc32_check = false)
|
14
|
-
action_params = _generate_action_params(
|
15
|
-
local_file,
|
16
|
-
bucket,
|
17
|
-
key,
|
18
|
-
mime_type,
|
19
|
-
custom_meta,
|
20
|
-
enable_crc32_check
|
21
|
-
)
|
22
|
-
|
23
|
-
url = Config.settings[:io_host] + action_params
|
24
|
-
options = {:content_type => 'application/octet-stream'}
|
25
|
-
|
26
|
-
Auth.request url, ::IO.read(local_file), options
|
27
|
-
end # put_file
|
28
|
-
|
29
8
|
def upload_with_token(uptoken,
|
30
9
|
local_file,
|
31
10
|
bucket,
|
data/lib/qiniu/utils.rb
CHANGED
@@ -74,10 +74,11 @@ module Qiniu
|
|
74
74
|
else
|
75
75
|
data = {}
|
76
76
|
body = response.respond_to?(:body) ? response.body : {}
|
77
|
+
raw_headers = response.respond_to?(:raw_headers) ? response.raw_headers : {}
|
77
78
|
data = safe_json_parse(body) unless body.empty?
|
78
79
|
end
|
79
|
-
[code, data]
|
80
|
-
end
|
80
|
+
[code, data, raw_headers]
|
81
|
+
end # send_request_with
|
81
82
|
|
82
83
|
def http_request url, data = nil, options = {}
|
83
84
|
retry_times = 0
|
@@ -99,9 +100,10 @@ module Qiniu
|
|
99
100
|
res = e.response
|
100
101
|
code = res.code.to_i if res.respond_to? :code
|
101
102
|
body = res.respond_to?(:body) ? res.body : ""
|
103
|
+
raw_headers = res.respond_to?(:raw_headers) ? res.raw_headers : {}
|
102
104
|
data = safe_json_parse(body) unless body.empty?
|
103
105
|
end
|
104
|
-
[code, data]
|
106
|
+
[code, data, raw_headers]
|
105
107
|
end
|
106
108
|
end
|
107
109
|
|
data/lib/qiniu/version.rb
CHANGED
data/spec/qiniu/image_spec.rb
CHANGED
@@ -11,14 +11,18 @@ module Qiniu
|
|
11
11
|
|
12
12
|
before :all do
|
13
13
|
|
14
|
-
|
15
|
-
@
|
14
|
+
### 复用RubySDK-Test-Storage空间
|
15
|
+
@bucket = 'RubySDK-Test-Storage'
|
16
|
+
@bucket = make_unique_bucket(@bucket)
|
16
17
|
|
18
|
+
### 尝试创建空间
|
17
19
|
result = Qiniu.mkbucket(@bucket)
|
18
20
|
puts result.inspect
|
19
|
-
result.should be_true
|
20
21
|
|
21
|
-
|
22
|
+
pic_fname = "image_logo_for_test.png"
|
23
|
+
@key = make_unique_key_in_bucket(pic_fname)
|
24
|
+
|
25
|
+
local_file = File.expand_path('../' + pic_fname, __FILE__)
|
22
26
|
|
23
27
|
upopts = {
|
24
28
|
:scope => @bucket,
|
@@ -53,9 +57,7 @@ module Qiniu
|
|
53
57
|
end
|
54
58
|
|
55
59
|
after :all do
|
56
|
-
|
57
|
-
puts result.inspect
|
58
|
-
result.should_not be_false
|
60
|
+
### 不删除Bucket以备下次使用
|
59
61
|
end
|
60
62
|
|
61
63
|
context ".info" do
|
@@ -11,29 +11,40 @@ module Qiniu
|
|
11
11
|
describe Storage do
|
12
12
|
|
13
13
|
before :all do
|
14
|
-
@bucket = '
|
14
|
+
@bucket = 'RubySDK-Test-Management'
|
15
|
+
@bucket = make_unique_bucket(@bucket)
|
16
|
+
|
17
|
+
### 尝试创建Bucket
|
18
|
+
result = Qiniu.mkbucket(@bucket)
|
19
|
+
puts result.inspect
|
20
|
+
|
15
21
|
@key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s)
|
16
|
-
@
|
22
|
+
@key = make_unique_key_in_bucket(@key)
|
17
23
|
|
18
|
-
|
19
|
-
puts [code, data].inspect
|
20
|
-
code.should == 200
|
24
|
+
@key2 = @key + rand(100).to_s
|
21
25
|
end
|
22
26
|
|
23
27
|
after :all do
|
24
|
-
|
25
|
-
puts [code, data].inspect
|
26
|
-
code.should == 200
|
28
|
+
### 不删除Bucket以备下次使用
|
27
29
|
end
|
28
30
|
|
29
|
-
|
31
|
+
### 准备数据
|
32
|
+
context ".upload_with_token_2" do
|
30
33
|
it "should works" do
|
31
|
-
|
34
|
+
upopts = {:scope => @bucket, :expires_in => 3600, :endUser => "why404@gmail.com"}
|
35
|
+
uptoken = Qiniu.generate_upload_token(upopts)
|
36
|
+
|
37
|
+
code, data, raw_headers = Qiniu::Storage.upload_with_token_2(
|
38
|
+
uptoken,
|
39
|
+
__FILE__,
|
40
|
+
@key
|
41
|
+
)
|
32
42
|
code.should == 200
|
33
43
|
puts data.inspect
|
34
44
|
end
|
35
45
|
end
|
36
46
|
|
47
|
+
### 列举Bucket
|
37
48
|
context ".buckets" do
|
38
49
|
it "should works" do
|
39
50
|
code, data = Storage.buckets
|
@@ -52,7 +63,7 @@ module Qiniu
|
|
52
63
|
|
53
64
|
context ".get" do
|
54
65
|
it "should works" do
|
55
|
-
code, data = Storage.get(@bucket, @key
|
66
|
+
code, data = Storage.get(@bucket, @key)
|
56
67
|
code.should == 200
|
57
68
|
puts data.inspect
|
58
69
|
end
|
@@ -88,10 +99,6 @@ module Qiniu
|
|
88
99
|
code.should == 200
|
89
100
|
puts data.inspect
|
90
101
|
|
91
|
-
#code2, data2 = Qiniu.stat(@bucket, @key2)
|
92
|
-
#code2.should == 200
|
93
|
-
#puts data2.inspect
|
94
|
-
|
95
102
|
code, data = Storage.delete @bucket, @key2
|
96
103
|
code.should == 200
|
97
104
|
puts data.inspect
|
@@ -104,34 +111,12 @@ module Qiniu
|
|
104
111
|
code.should == 200
|
105
112
|
puts data.inspect
|
106
113
|
|
107
|
-
#code2, data2 = Qiniu.stat(@bucket, @key2)
|
108
|
-
#code2.should == 200
|
109
|
-
#puts data2.inspect
|
110
|
-
|
111
114
|
code3, data3 = Storage.batch_move @bucket, @key2, @bucket, @key
|
112
115
|
code3.should == 200
|
113
116
|
puts data3.inspect
|
114
117
|
end
|
115
118
|
end
|
116
119
|
|
117
|
-
=begin
|
118
|
-
context ".publish" do
|
119
|
-
it "should works" do
|
120
|
-
code, data = Qiniu.publish(@domain, @bucket)
|
121
|
-
code.should == 200
|
122
|
-
puts data.inspect
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
context ".unpublish" do
|
127
|
-
it "should works" do
|
128
|
-
code, data = Qiniu.unpublish(@domain)
|
129
|
-
code.should == 200
|
130
|
-
puts data.inspect
|
131
|
-
end
|
132
|
-
end
|
133
|
-
=end
|
134
|
-
|
135
120
|
context ".move" do
|
136
121
|
it "should works" do
|
137
122
|
code, data = Storage.move(@bucket, @key, @bucket, @key2)
|
@@ -154,23 +139,15 @@ module Qiniu
|
|
154
139
|
code.should == 200
|
155
140
|
puts data.inspect
|
156
141
|
|
157
|
-
|
158
|
-
#code2.should == 200
|
159
|
-
#puts data2.inspect
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
context ".delete" do
|
164
|
-
it "should works" do
|
165
|
-
code, data = Storage.delete(@bucket, @key)
|
142
|
+
code, data = Storage.delete(@bucket, @key2)
|
166
143
|
code.should == 200
|
167
144
|
puts data.inspect
|
168
145
|
end
|
169
146
|
end
|
170
147
|
|
171
|
-
context ".
|
148
|
+
context ".delete" do
|
172
149
|
it "should works" do
|
173
|
-
code, data = Storage.
|
150
|
+
code, data = Storage.delete(@bucket, @key)
|
174
151
|
code.should == 200
|
175
152
|
puts data.inspect
|
176
153
|
end
|
data/spec/qiniu/misc_spec.rb
CHANGED
@@ -10,16 +10,16 @@ module Qiniu
|
|
10
10
|
describe Misc do
|
11
11
|
|
12
12
|
before :all do
|
13
|
-
|
13
|
+
### 复用RubySDK-Test-Management空间
|
14
|
+
@bucket = 'RubySDK-Test-Management'
|
15
|
+
@bucket = make_unique_bucket(@bucket)
|
16
|
+
|
14
17
|
result = Qiniu.mkbucket(@bucket)
|
15
18
|
puts result.inspect
|
16
|
-
result.should_not be_false
|
17
19
|
end
|
18
20
|
|
19
21
|
after :all do
|
20
|
-
|
21
|
-
puts result.inspect
|
22
|
-
result.should_not be_false
|
22
|
+
### 不删除Bucket以备下次使用
|
23
23
|
end
|
24
24
|
|
25
25
|
context ".set_protected" do
|
data/spec/qiniu/qiniu_spec.rb
CHANGED
@@ -9,18 +9,20 @@ module Qiniu
|
|
9
9
|
describe Qiniu do
|
10
10
|
|
11
11
|
before :all do
|
12
|
-
@bucket = '
|
13
|
-
@
|
14
|
-
@key2 = @key + rand(100).to_s
|
15
|
-
#@domain = @bucket + '.dn.qbox.me'
|
12
|
+
@bucket = 'RubySDK-Test'
|
13
|
+
@bucket = make_unique_bucket(@bucket)
|
16
14
|
|
15
|
+
@test_image_bucket = @bucket
|
16
|
+
|
17
|
+
### 尝试创建Bucket
|
17
18
|
result = Qiniu.mkbucket(@bucket)
|
18
|
-
result.
|
19
|
+
puts result.inspect
|
20
|
+
|
21
|
+
@key = Digest::SHA1.hexdigest Time.now.to_s
|
22
|
+
@key = make_unique_key_in_bucket(@key)
|
19
23
|
|
20
|
-
@
|
21
|
-
|
22
|
-
puts result2.inspect
|
23
|
-
result2.should be_true
|
24
|
+
@key2 = @key + rand(100).to_s
|
25
|
+
#@domain = @bucket + '.dn.qbox.me'
|
24
26
|
|
25
27
|
@test_image_key = 'image_logo_for_test.png'
|
26
28
|
local_file = File.expand_path('./' + @test_image_key, File.dirname(__FILE__))
|
@@ -32,27 +34,7 @@ module Qiniu
|
|
32
34
|
end
|
33
35
|
|
34
36
|
after :all do
|
35
|
-
|
36
|
-
#result.should_not be_false
|
37
|
-
|
38
|
-
result1 = Qiniu.drop(@bucket)
|
39
|
-
puts result1.inspect
|
40
|
-
result1.should_not be_false
|
41
|
-
|
42
|
-
result2 = Qiniu.drop(@test_image_bucket)
|
43
|
-
puts result2.inspect
|
44
|
-
result2.should_not be_false
|
45
|
-
end
|
46
|
-
|
47
|
-
context ".put_file" do
|
48
|
-
it "should works" do
|
49
|
-
result = Qiniu.put_file :file => __FILE__,
|
50
|
-
:bucket => @bucket,
|
51
|
-
:key => @key,
|
52
|
-
:mime_type => 'application/x-ruby',
|
53
|
-
:enable_crc32_check => true
|
54
|
-
result.should be_true
|
55
|
-
end
|
37
|
+
### 不删除Bucket以备下次使用
|
56
38
|
end
|
57
39
|
|
58
40
|
context ".buckets" do
|
@@ -180,7 +162,7 @@ module Qiniu
|
|
180
162
|
|
181
163
|
context ".get" do
|
182
164
|
it "should works" do
|
183
|
-
result = Qiniu.get(@bucket, @key, "
|
165
|
+
result = Qiniu.get(@bucket, @key, "qiniu_spec.rb", 10)
|
184
166
|
result.should_not be_false
|
185
167
|
result.should_not be_empty
|
186
168
|
puts result.inspect
|
@@ -232,24 +214,6 @@ module Qiniu
|
|
232
214
|
end
|
233
215
|
end
|
234
216
|
|
235
|
-
=begin
|
236
|
-
context ".publish" do
|
237
|
-
it "should works" do
|
238
|
-
result = Qiniu.publish(@domain, @bucket)
|
239
|
-
result.should_not be_false
|
240
|
-
end
|
241
|
-
end
|
242
|
-
=end
|
243
|
-
|
244
|
-
=begin
|
245
|
-
context ".unpublish" do
|
246
|
-
it "should works" do
|
247
|
-
result = Qiniu.unpublish(@domain)
|
248
|
-
result.should_not be_false
|
249
|
-
end
|
250
|
-
end
|
251
|
-
=end
|
252
|
-
|
253
217
|
=begin
|
254
218
|
context ".batch_copy" do
|
255
219
|
it "should works" do
|
@@ -293,8 +257,8 @@ module Qiniu
|
|
293
257
|
result = Qiniu.copy(@bucket, @key, @bucket, @key2)
|
294
258
|
result.should_not be_false
|
295
259
|
|
296
|
-
|
297
|
-
|
260
|
+
result3 = Qiniu.delete(@bucket, @key2)
|
261
|
+
result3.should_not be_false
|
298
262
|
end
|
299
263
|
end
|
300
264
|
|
@@ -305,13 +269,6 @@ module Qiniu
|
|
305
269
|
end
|
306
270
|
end
|
307
271
|
|
308
|
-
context ".drop" do
|
309
|
-
it "should works" do
|
310
|
-
result = Qiniu.drop(@bucket)
|
311
|
-
result.should_not be_false
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
272
|
context ".image_info" do
|
316
273
|
it "should works" do
|
317
274
|
data = Qiniu.get(@test_image_bucket, @test_image_key)
|
@@ -325,19 +282,6 @@ module Qiniu
|
|
325
282
|
end
|
326
283
|
end
|
327
284
|
|
328
|
-
=begin
|
329
|
-
context ".image_exif" do
|
330
|
-
it "should works" do
|
331
|
-
data = Qiniu.get(@test_image_bucket, @test_image_key)
|
332
|
-
data.should_not be_false
|
333
|
-
data.should_not be_empty
|
334
|
-
puts data.inspect
|
335
|
-
result = Qiniu.image_exif(data["url"])
|
336
|
-
puts result.inspect
|
337
|
-
end
|
338
|
-
end
|
339
|
-
=end
|
340
|
-
|
341
285
|
context ".image_mogrify_save_as" do
|
342
286
|
it "should works" do
|
343
287
|
data = Qiniu.get(@test_image_bucket, @test_image_key)
|
data/spec/qiniu/upload_spec.rb
CHANGED
@@ -10,56 +10,86 @@ module Qiniu
|
|
10
10
|
describe Storage do
|
11
11
|
|
12
12
|
before :all do
|
13
|
-
@bucket = '
|
14
|
-
@
|
13
|
+
@bucket = 'RubySDK-Test-Storage'
|
14
|
+
@bucket = make_unique_bucket(@bucket)
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
### 尝试创建Bucket
|
17
|
+
result = Qiniu.mkbucket(@bucket)
|
18
|
+
puts result.inspect
|
19
19
|
|
20
|
-
@
|
21
|
-
|
22
|
-
|
20
|
+
@key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s)
|
21
|
+
@key = make_unique_key_in_bucket(@key)
|
22
|
+
puts "key=#{@key}"
|
23
23
|
|
24
|
-
@
|
25
|
-
File.open(@
|
26
|
-
@
|
24
|
+
@localfile_5m = "5M.txt"
|
25
|
+
File.open(@localfile_5m, "w"){|f| 5242888.times{ f.write(rand(9).to_s) }}
|
26
|
+
@key_5m = Digest::SHA1.hexdigest(@localfile_5m+Time.now.to_s)
|
27
|
+
@key_5m = make_unique_key_in_bucket(@key_5m)
|
28
|
+
puts "key_5m=#{@key_5m}"
|
27
29
|
|
28
|
-
@
|
29
|
-
File.open(@
|
30
|
-
@
|
30
|
+
@localfile_4m = "4M.txt"
|
31
|
+
File.open(@localfile_4m, "w"){|f| (1 << 22).times{ f.write(rand(9).to_s) }}
|
32
|
+
@key_4m = Digest::SHA1.hexdigest(@localfile_4m+Time.now.to_s)
|
33
|
+
@key_4m = make_unique_key_in_bucket(@key_4m)
|
34
|
+
puts "key_4m=#{@key_4m}"
|
31
35
|
|
32
|
-
|
33
|
-
|
34
|
-
|
36
|
+
@localfile_8m = "8M.txt"
|
37
|
+
File.open(@localfile_8m, "w"){|f| (1 << 23).times{ f.write(rand(9).to_s) }}
|
38
|
+
@key_8m = Digest::SHA1.hexdigest(@localfile_8m+Time.now.to_s)
|
39
|
+
@key_8m = make_unique_key_in_bucket(@key_8m)
|
40
|
+
puts "key_8m=#{@key_8m}"
|
41
|
+
|
42
|
+
@localfile_1m = "1M.txt"
|
43
|
+
File.open(@localfile_1m, "w"){|f| (1 << 20).times{ f.write(rand(9).to_s) }}
|
44
|
+
@key_1m = Digest::SHA1.hexdigest(@localfile_1m+Time.now.to_s)
|
45
|
+
@key_1m = make_unique_key_in_bucket(@key_1m)
|
46
|
+
puts "key_1m=#{@key_1m}"
|
35
47
|
end
|
36
48
|
|
37
49
|
after :all do
|
38
|
-
|
39
|
-
File.unlink(@
|
40
|
-
File.unlink(@
|
41
|
-
File.unlink(@
|
50
|
+
### 清除本地临时文件
|
51
|
+
File.unlink(@localfile_5m) if File.exists?(@localfile_5m)
|
52
|
+
File.unlink(@localfile_4m) if File.exists?(@localfile_4m)
|
53
|
+
File.unlink(@localfile_8m) if File.exists?(@localfile_8m)
|
54
|
+
File.unlink(@localfile_1m) if File.exists?(@localfile_1m)
|
42
55
|
|
43
|
-
|
44
|
-
puts result.inspect
|
45
|
-
result.should_not be_false
|
56
|
+
### 不删除Bucket以备下次使用
|
46
57
|
end
|
47
58
|
|
48
|
-
|
59
|
+
### 测试单文件直传
|
60
|
+
context ".upload_with_token" do
|
49
61
|
it "should works" do
|
50
|
-
|
62
|
+
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
|
63
|
+
uptoken = Qiniu.generate_upload_token(upopts)
|
64
|
+
code, data, raw_headers = Qiniu::Storage.upload_with_token(
|
65
|
+
uptoken,
|
66
|
+
__FILE__,
|
67
|
+
@bucket,
|
68
|
+
@key,
|
69
|
+
nil,
|
70
|
+
nil,
|
71
|
+
nil,
|
72
|
+
true
|
73
|
+
)
|
51
74
|
code.should == 200
|
52
75
|
puts data.inspect
|
76
|
+
puts raw_headers.inspect
|
53
77
|
end
|
54
78
|
end
|
55
79
|
|
56
|
-
context ".
|
57
|
-
it "should
|
58
|
-
|
59
|
-
|
60
|
-
code, data = Qiniu::Storage.upload_with_token(uptoken, __FILE__, @bucket, @key, nil, nil, nil, true)
|
80
|
+
context ".stat" do
|
81
|
+
it "should exists" do
|
82
|
+
code, data = Qiniu::Storage.stat(@bucket, @key)
|
83
|
+
puts data.inspect
|
61
84
|
code.should == 200
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context ".delete" do
|
89
|
+
it "should works" do
|
90
|
+
code, data = Qiniu::Storage.delete(@bucket, @key)
|
62
91
|
puts data.inspect
|
92
|
+
code.should == 200
|
63
93
|
end
|
64
94
|
end
|
65
95
|
|
@@ -68,26 +98,55 @@ module Qiniu
|
|
68
98
|
upopts = {:scope => @bucket, :expires_in => 3600, :endUser => "why404@gmail.com"}
|
69
99
|
uptoken = Qiniu.generate_upload_token(upopts)
|
70
100
|
|
71
|
-
code, data = Qiniu::Storage.upload_with_token_2(
|
101
|
+
code, data, raw_headers = Qiniu::Storage.upload_with_token_2(
|
102
|
+
uptoken,
|
103
|
+
__FILE__,
|
104
|
+
@key
|
105
|
+
)
|
72
106
|
|
73
107
|
code.should == 200
|
74
108
|
puts data.inspect
|
109
|
+
puts raw_headers.inspect
|
75
110
|
end
|
76
111
|
end # .upload_with_token_2
|
77
112
|
|
113
|
+
context ".stat" do
|
114
|
+
it "should exists" do
|
115
|
+
code, data = Qiniu::Storage.stat(@bucket, @key)
|
116
|
+
puts data.inspect
|
117
|
+
code.should == 200
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context ".delete" do
|
122
|
+
it "should works" do
|
123
|
+
code, data = Qiniu::Storage.delete(@bucket, @key)
|
124
|
+
puts data.inspect
|
125
|
+
code.should == 200
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
### 测试断点续上传
|
78
130
|
context ".resumable_upload_with_token" do
|
79
131
|
it "should works" do
|
80
132
|
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
|
81
133
|
uptoken = Qiniu.generate_upload_token(upopts)
|
82
|
-
code, data = Qiniu::Storage.resumable_upload_with_token(
|
83
|
-
|
134
|
+
code, data, raw_headers = Qiniu::Storage.resumable_upload_with_token(
|
135
|
+
uptoken,
|
136
|
+
@localfile_5m,
|
137
|
+
@bucket,
|
138
|
+
@key_5m
|
139
|
+
)
|
84
140
|
(code/100).should == 2
|
141
|
+
puts data.inspect
|
142
|
+
puts raw_headers.inspect
|
143
|
+
puts "key_5m=#{@key_5m}"
|
85
144
|
end
|
86
145
|
end
|
87
146
|
|
88
147
|
context ".stat" do
|
89
148
|
it "should exists" do
|
90
|
-
code, data = Qiniu::Storage.stat(@bucket, @
|
149
|
+
code, data = Qiniu::Storage.stat(@bucket, @key_5m)
|
91
150
|
puts data.inspect
|
92
151
|
code.should == 200
|
93
152
|
end
|
@@ -95,7 +154,7 @@ module Qiniu
|
|
95
154
|
|
96
155
|
context ".delete" do
|
97
156
|
it "should works" do
|
98
|
-
code, data = Qiniu::Storage.delete(@bucket, @
|
157
|
+
code, data = Qiniu::Storage.delete(@bucket, @key_5m)
|
99
158
|
puts data.inspect
|
100
159
|
code.should == 200
|
101
160
|
end
|
@@ -105,15 +164,22 @@ module Qiniu
|
|
105
164
|
it "should works" do
|
106
165
|
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
|
107
166
|
uptoken = Qiniu.generate_upload_token(upopts)
|
108
|
-
code, data = Qiniu::Storage.resumable_upload_with_token(
|
109
|
-
|
167
|
+
code, data, raw_headers = Qiniu::Storage.resumable_upload_with_token(
|
168
|
+
uptoken,
|
169
|
+
@localfile_4m,
|
170
|
+
@bucket,
|
171
|
+
@key_4m
|
172
|
+
)
|
110
173
|
(code/100).should == 2
|
174
|
+
puts data.inspect
|
175
|
+
puts raw_headers.inspect
|
176
|
+
puts "key_4m=#{@key_4m}"
|
111
177
|
end
|
112
178
|
end
|
113
179
|
|
114
180
|
context ".stat" do
|
115
181
|
it "should exists" do
|
116
|
-
code, data = Qiniu::Storage.stat(@bucket, @
|
182
|
+
code, data = Qiniu::Storage.stat(@bucket, @key_4m)
|
117
183
|
puts data.inspect
|
118
184
|
code.should == 200
|
119
185
|
end
|
@@ -121,7 +187,7 @@ module Qiniu
|
|
121
187
|
|
122
188
|
context ".delete" do
|
123
189
|
it "should works" do
|
124
|
-
code, data = Qiniu::Storage.delete(@bucket, @
|
190
|
+
code, data = Qiniu::Storage.delete(@bucket, @key_4m)
|
125
191
|
puts data.inspect
|
126
192
|
code.should == 200
|
127
193
|
end
|
@@ -131,15 +197,22 @@ module Qiniu
|
|
131
197
|
it "should works" do
|
132
198
|
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
|
133
199
|
uptoken = Qiniu.generate_upload_token(upopts)
|
134
|
-
code, data = Qiniu::Storage.resumable_upload_with_token(
|
135
|
-
|
200
|
+
code, data, raw_headers = Qiniu::Storage.resumable_upload_with_token(
|
201
|
+
uptoken,
|
202
|
+
@localfile_8m,
|
203
|
+
@bucket,
|
204
|
+
@key_8m
|
205
|
+
)
|
136
206
|
(code/100).should == 2
|
207
|
+
puts data.inspect
|
208
|
+
puts raw_headers.inspect
|
209
|
+
puts "key_8m=#{@key_8m}"
|
137
210
|
end
|
138
211
|
end
|
139
212
|
|
140
213
|
context ".stat" do
|
141
214
|
it "should exists" do
|
142
|
-
code, data = Qiniu::Storage.stat(@bucket, @
|
215
|
+
code, data = Qiniu::Storage.stat(@bucket, @key_8m)
|
143
216
|
puts data.inspect
|
144
217
|
code.should == 200
|
145
218
|
end
|
@@ -147,7 +220,7 @@ module Qiniu
|
|
147
220
|
|
148
221
|
context ".delete" do
|
149
222
|
it "should works" do
|
150
|
-
code, data = Qiniu::Storage.delete(@bucket, @
|
223
|
+
code, data = Qiniu::Storage.delete(@bucket, @key_8m)
|
151
224
|
puts data.inspect
|
152
225
|
code.should == 200
|
153
226
|
end
|
@@ -157,15 +230,22 @@ module Qiniu
|
|
157
230
|
it "should works" do
|
158
231
|
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
|
159
232
|
uptoken = Qiniu.generate_upload_token(upopts)
|
160
|
-
code, data = Qiniu::Storage.resumable_upload_with_token(
|
161
|
-
|
233
|
+
code, data, raw_headers = Qiniu::Storage.resumable_upload_with_token(
|
234
|
+
uptoken,
|
235
|
+
@localfile_1m,
|
236
|
+
@bucket,
|
237
|
+
@key_1m
|
238
|
+
)
|
162
239
|
(code/100).should == 2
|
240
|
+
puts data.inspect
|
241
|
+
puts raw_headers.inspect
|
242
|
+
puts "key_1m=#{@key_1m}"
|
163
243
|
end
|
164
244
|
end
|
165
245
|
|
166
246
|
context ".stat" do
|
167
247
|
it "should exists" do
|
168
|
-
code, data = Qiniu::Storage.stat(@bucket, @
|
248
|
+
code, data = Qiniu::Storage.stat(@bucket, @key_1m)
|
169
249
|
puts data.inspect
|
170
250
|
code.should == 200
|
171
251
|
end
|
@@ -173,7 +253,7 @@ module Qiniu
|
|
173
253
|
|
174
254
|
context ".delete" do
|
175
255
|
it "should works" do
|
176
|
-
code, data = Qiniu::Storage.delete(@bucket, @
|
256
|
+
code, data = Qiniu::Storage.delete(@bucket, @key_1m)
|
177
257
|
puts data.inspect
|
178
258
|
code.should == 200
|
179
259
|
end
|
data/spec/qiniu/utils_spec.rb
CHANGED
@@ -28,7 +28,7 @@ module Qiniu
|
|
28
28
|
FakeWeb.allow_net_connect = false
|
29
29
|
FakeWeb.register_uri(:get, "http://docs.qiniutek.com/", :body => {:abc => 123}.to_json)
|
30
30
|
res = Utils.send_request_with 'http://docs.qiniutek.com/', nil, :method => :get
|
31
|
-
res.should == [200, {"abc" => 123}]
|
31
|
+
res.should == [200, {"abc" => 123}, {}]
|
32
32
|
end
|
33
33
|
|
34
34
|
[400, 500].each do |code|
|
data/spec/spec_helper.rb
CHANGED
@@ -9,3 +9,11 @@ RSpec.configure do |config|
|
|
9
9
|
Qiniu.establish_connection! :access_key => ENV["QINIU_ACCESS_KEY"], :secret_key => ENV["QINIU_SECRET_KEY"]
|
10
10
|
end
|
11
11
|
end
|
12
|
+
|
13
|
+
def make_unique_bucket (bucket)
|
14
|
+
bucket + "-" + ENV["QINIU_ACCESS_KEY"][0, 8]
|
15
|
+
end # make_unique_bucket
|
16
|
+
|
17
|
+
def make_unique_key_in_bucket (key)
|
18
|
+
"#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}-" + key
|
19
|
+
end # make_unique_key_in_bucket
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qiniu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.0
|
4
|
+
version: 6.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- why404
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|