qiniu-rs 3.3.1 → 3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +9 -1
- data/Gemfile.lock +1 -1
- data/LICENSE +1 -1
- data/docs/README.md +99 -9
- data/lib/qiniu/rs.rb +22 -0
- data/lib/qiniu/rs/rs.rb +34 -0
- data/lib/qiniu/rs/version.rb +2 -2
- data/spec/qiniu/rs/rs_spec.rb +57 -0
- data/spec/qiniu/rs_spec.rb +47 -0
- metadata +4 -4
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
## CHANGE LOG
|
2
2
|
|
3
|
-
### v3.
|
3
|
+
### v3.4.0
|
4
|
+
|
5
|
+
增加文件复制/移动方法,包括批量复制/移动文件
|
4
6
|
|
7
|
+
- `Qiniu::RS.copy(source_bucket, source_key, target_bucket, target_key)`
|
8
|
+
- `Qiniu::RS.move(source_bucket, source_key, target_bucket, target_key)`
|
9
|
+
- `Qiniu::RS.batch_copy [source_bucket, source_key, target_bucket, target_key], ...`
|
10
|
+
- `Qiniu::RS.batch_move [source_bucket, source_key, target_bucket, target_key], ...`
|
11
|
+
|
12
|
+
### v3.3.1
|
5
13
|
|
6
14
|
确保单元测试里边用到的测试 Bucket 全局唯一
|
7
15
|
|
data/Gemfile.lock
CHANGED
data/LICENSE
CHANGED
data/docs/README.md
CHANGED
@@ -6,7 +6,7 @@ title: Ruby SDK 使用指南 | 七牛云存储
|
|
6
6
|
|
7
7
|
此 Ruby SDK 适用于 Ruby 1.8.x, 1.9.x, jruby, rbx, ree 版本,基于 [七牛云存储官方API](/v3/api/) 构建。使用此 SDK 构建您的网络应用程序,能让您以非常便捷地方式将数据安全地存储到七牛云存储上。无论您的网络应用是一个网站程序,还是包括从云端(服务端程序)到终端(手持设备应用)的架构的服务或应用,通过七牛云存储及其 SDK,都能让您应用程序的终端用户高速上传和下载,同时也让您的服务端更加轻盈。
|
8
8
|
|
9
|
-
七牛云存储 Ruby SDK 源码地址:<https://github.com/qiniu/ruby-sdk>
|
9
|
+
七牛云存储 Ruby SDK 源码地址:<https://github.com/qiniu/ruby-sdk> [![Build Status](https://api.travis-ci.org/qiniu/ruby-sdk.png?branch=master)](https://travis-ci.org/qiniu/ruby-sdk) [![Dependency Status](https://gemnasium.com/why404/qiniu-rs-for-ruby.png)](https://gemnasium.com/why404/qiniu-rs-for-ruby)
|
10
10
|
|
11
11
|
**目录**
|
12
12
|
|
@@ -186,10 +186,10 @@ title: Ruby SDK 使用指南 | 七牛云存储
|
|
186
186
|
: 必须,字符串类型(String),本地文件可被读取的有效路径
|
187
187
|
|
188
188
|
:bucket
|
189
|
-
: 必须,字符串类型(String
|
189
|
+
: 必须,字符串类型(String),空间名称。
|
190
190
|
|
191
191
|
:key
|
192
|
-
: 必须,字符串类型(String
|
192
|
+
: 必须,字符串类型(String),若把 Bucket 理解为关系性数据库的某个表,那么 key 类似数据库里边某个表的主键ID,需给每一个文件一个UUID用于进行标示。
|
193
193
|
|
194
194
|
:mime_type
|
195
195
|
: 可选,字符串类型(String),文件的 mime-type 值。如若不传入,SDK 会自行计算得出,若计算失败缺省使用 application/octet-stream 代替之。
|
@@ -364,10 +364,10 @@ pattern
|
|
364
364
|
**参数**
|
365
365
|
|
366
366
|
bucket
|
367
|
-
: 必须,字符串类型(String
|
367
|
+
: 必须,字符串类型(String),空间名称。
|
368
368
|
|
369
369
|
key
|
370
|
-
: 必须,字符串类型(String
|
370
|
+
: 必须,字符串类型(String),若把 Bucket 理解为关系性数据库的某个表,那么 key 类似数据库里边某个表的主键ID,需给每一个文件一个UUID用于进行标示。
|
371
371
|
|
372
372
|
**返回值**
|
373
373
|
|
@@ -392,6 +392,61 @@ mimeType
|
|
392
392
|
putTime
|
393
393
|
: 上传时间,单位是 百纳秒
|
394
394
|
|
395
|
+
|
396
|
+
<a name="copy"></a>
|
397
|
+
|
398
|
+
#### 复制单个文件
|
399
|
+
|
400
|
+
Qiniu::RS.copy(source_bucket, source_key, target_bucket, target_key)
|
401
|
+
|
402
|
+
可以通过 SDK 提供的 `Qiniu::RS.copy` 函数进行文件复制操作。
|
403
|
+
|
404
|
+
**参数**
|
405
|
+
|
406
|
+
source_bucket
|
407
|
+
: 必须,字符串类型(String),指定源空间。
|
408
|
+
|
409
|
+
source_key
|
410
|
+
: 必须,字符串类型(String),指定源文件。
|
411
|
+
|
412
|
+
target_bucket
|
413
|
+
: 必须,字符串类型(String),指定要复制到的目标空间。
|
414
|
+
|
415
|
+
target_key
|
416
|
+
: 必须,字符串类型(String),指定要复制到目标空间的目标文件名。
|
417
|
+
|
418
|
+
**返回值**
|
419
|
+
|
420
|
+
如果请求失败,返回 `false`;否则返回 `true` 。
|
421
|
+
|
422
|
+
|
423
|
+
<a name="move"></a>
|
424
|
+
|
425
|
+
#### 移动单个文件
|
426
|
+
|
427
|
+
Qiniu::RS.move(source_bucket, source_key, target_bucket, target_key)
|
428
|
+
|
429
|
+
可以通过 SDK 提供的 `Qiniu::RS.move` 函数进行文件移动操作。
|
430
|
+
|
431
|
+
**参数**
|
432
|
+
|
433
|
+
source_bucket
|
434
|
+
: 必须,字符串类型(String),指定源空间。
|
435
|
+
|
436
|
+
source_key
|
437
|
+
: 必须,字符串类型(String),指定源文件。
|
438
|
+
|
439
|
+
target_bucket
|
440
|
+
: 必须,字符串类型(String),指定要移动到的目标空间。
|
441
|
+
|
442
|
+
target_key
|
443
|
+
: 必须,字符串类型(String),指定要移动到目标空间的目标文件名。
|
444
|
+
|
445
|
+
**返回值**
|
446
|
+
|
447
|
+
如果请求失败,返回 `false`;否则返回 `true` 。
|
448
|
+
|
449
|
+
|
395
450
|
<a name="delete"></a>
|
396
451
|
|
397
452
|
### 删除单个文件
|
@@ -403,10 +458,10 @@ putTime
|
|
403
458
|
**参数**
|
404
459
|
|
405
460
|
bucket
|
406
|
-
: 必须,字符串类型(String
|
461
|
+
: 必须,字符串类型(String),空间名称。
|
407
462
|
|
408
463
|
key
|
409
|
-
: 必须,字符串类型(String
|
464
|
+
: 必须,字符串类型(String),若把 Bucket 理解为关系性数据库的某个表,那么 key 类似数据库里边某个表的主键ID,需给每一个文件一个UUID用于进行标示。
|
410
465
|
|
411
466
|
**返回值**
|
412
467
|
|
@@ -427,7 +482,7 @@ command
|
|
427
482
|
: 必须,字符串类型(String),其值可以是 `stat`, `get`, `delete` 中的一种
|
428
483
|
|
429
484
|
bucket
|
430
|
-
: 必须,字符串类型(String
|
485
|
+
: 必须,字符串类型(String),空间名称。
|
431
486
|
|
432
487
|
keys
|
433
488
|
: 必须,数组类型(Array),所要操作 `key` 的集合。
|
@@ -461,7 +516,7 @@ keys
|
|
461
516
|
**参数**
|
462
517
|
|
463
518
|
bucket
|
464
|
-
: 必须,字符串类型(String
|
519
|
+
: 必须,字符串类型(String),空间名称。
|
465
520
|
|
466
521
|
keys
|
467
522
|
: 必须,数组类型(Array),所要操作 `key` 的集合。
|
@@ -484,6 +539,41 @@ keys
|
|
484
539
|
...
|
485
540
|
]
|
486
541
|
|
542
|
+
|
543
|
+
<a name="batch-copy"></a>
|
544
|
+
|
545
|
+
#### 批量复制文件
|
546
|
+
|
547
|
+
Qiniu::RS.batch_copy(*args)
|
548
|
+
|
549
|
+
等价于,
|
550
|
+
|
551
|
+
Qiniu::RS.batch_copy [source_bucket, source_key, target_bucket, target_key], ...
|
552
|
+
|
553
|
+
`Qiniu::RS.batch_copy()` 的参数是一个可变长数组,其中每个数组其元素含义同 `Qiniu::RS.copy` 的参数一样。
|
554
|
+
|
555
|
+
**返回值**
|
556
|
+
|
557
|
+
如果批量删除成功,返回 `true` ,否则为 `false` 。
|
558
|
+
|
559
|
+
|
560
|
+
<a name="batch-move"></a>
|
561
|
+
|
562
|
+
#### 批量移动文件
|
563
|
+
|
564
|
+
Qiniu::RS.batch_move(*args)
|
565
|
+
|
566
|
+
等价于,
|
567
|
+
|
568
|
+
Qiniu::RS.batch_move [source_bucket, source_key, target_bucket, target_key], ...
|
569
|
+
|
570
|
+
`Qiniu::RS.batch_move()` 的参数是一个可变长数组,其中每个数组其元素含义同 `Qiniu::RS.move` 的参数一样。
|
571
|
+
|
572
|
+
**返回值**
|
573
|
+
|
574
|
+
如果批量删除成功,返回 `true` ,否则为 `false` 。
|
575
|
+
|
576
|
+
|
487
577
|
<a name="batch-delete"></a>
|
488
578
|
|
489
579
|
#### 批量删除文件
|
data/lib/qiniu/rs.rb
CHANGED
@@ -63,6 +63,7 @@ module Qiniu
|
|
63
63
|
code == StatusOK
|
64
64
|
end
|
65
65
|
|
66
|
+
=begin
|
66
67
|
def set_watermark(customer_id, options = {})
|
67
68
|
code, data = EU.set_watermark(customer_id, options)
|
68
69
|
code == StatusOK
|
@@ -72,6 +73,7 @@ module Qiniu
|
|
72
73
|
code, data = EU.get_watermark(customer_id)
|
73
74
|
code == StatusOK ? data : false
|
74
75
|
end
|
76
|
+
=end
|
75
77
|
|
76
78
|
def put_auth(expires_in = nil, callback_url = nil)
|
77
79
|
code, data = IO.put_auth(expires_in, callback_url)
|
@@ -149,6 +151,16 @@ module Qiniu
|
|
149
151
|
code == StatusOK ? data["url"] : false
|
150
152
|
end
|
151
153
|
|
154
|
+
def copy(source_bucket, source_key, target_bucket, target_key)
|
155
|
+
code, data = RS.copy(source_bucket, source_key, target_bucket, target_key)
|
156
|
+
code == StatusOK
|
157
|
+
end
|
158
|
+
|
159
|
+
def move(source_bucket, source_key, target_bucket, target_key)
|
160
|
+
code, data = RS.move(source_bucket, source_key, target_bucket, target_key)
|
161
|
+
code == StatusOK
|
162
|
+
end
|
163
|
+
|
152
164
|
def delete(bucket, key)
|
153
165
|
code, data = RS.delete(bucket, key)
|
154
166
|
code == StatusOK
|
@@ -169,6 +181,16 @@ module Qiniu
|
|
169
181
|
code == StatusOK ? data : false
|
170
182
|
end
|
171
183
|
|
184
|
+
def batch_copy(*args)
|
185
|
+
code, data = RS.batch_copy(args)
|
186
|
+
code == StatusOK
|
187
|
+
end
|
188
|
+
|
189
|
+
def batch_move(*args)
|
190
|
+
code, data = RS.batch_move(args)
|
191
|
+
code == StatusOK
|
192
|
+
end
|
193
|
+
|
172
194
|
def batch_download(bucket, keys)
|
173
195
|
code, data = RS.batch_get(bucket, keys)
|
174
196
|
return false unless code == StatusOK
|
data/lib/qiniu/rs/rs.rb
CHANGED
@@ -26,6 +26,16 @@ module Qiniu
|
|
26
26
|
Auth.request url
|
27
27
|
end
|
28
28
|
|
29
|
+
def copy(source_bucket, source_key, target_bucket, target_key)
|
30
|
+
uri = _generate_cp_or_mv_opstr('copy', source_bucket, source_key, target_bucket, target_key)
|
31
|
+
Auth.request Config.settings[:rs_host] + uri
|
32
|
+
end
|
33
|
+
|
34
|
+
def move(source_bucket, source_key, target_bucket, target_key)
|
35
|
+
uri = _generate_cp_or_mv_opstr('move', source_bucket, source_key, target_bucket, target_key)
|
36
|
+
Auth.request Config.settings[:rs_host] + uri
|
37
|
+
end
|
38
|
+
|
29
39
|
def delete(bucket, key)
|
30
40
|
Auth.request Config.settings[:rs_host] + '/delete/' + encode_entry_uri(bucket, key)
|
31
41
|
end
|
@@ -61,6 +71,14 @@ module Qiniu
|
|
61
71
|
batch("stat", bucket, keys)
|
62
72
|
end
|
63
73
|
|
74
|
+
def batch_copy(*args)
|
75
|
+
_batch_cp_or_mv('copy', args)
|
76
|
+
end
|
77
|
+
|
78
|
+
def batch_move(*args)
|
79
|
+
_batch_cp_or_mv('move', args)
|
80
|
+
end
|
81
|
+
|
64
82
|
def batch_delete(bucket, keys)
|
65
83
|
batch("delete", bucket, keys)
|
66
84
|
end
|
@@ -77,6 +95,22 @@ module Qiniu
|
|
77
95
|
save_as(bucket, key, source_image_url, mogrify_params_string)
|
78
96
|
end
|
79
97
|
|
98
|
+
private
|
99
|
+
|
100
|
+
def _generate_cp_or_mv_opstr(command, source_bucket, source_key, target_bucket, target_key)
|
101
|
+
source_encoded_entry_uri = encode_entry_uri(source_bucket, source_key)
|
102
|
+
target_encoded_entry_uri = encode_entry_uri(target_bucket, target_key)
|
103
|
+
%Q(/#{command}/#{source_encoded_entry_uri}/#{target_encoded_entry_uri})
|
104
|
+
end
|
105
|
+
|
106
|
+
def _batch_cp_or_mv(command, *op_args)
|
107
|
+
execs = []
|
108
|
+
op_args.each do |e|
|
109
|
+
execs << 'op=' + _generate_cp_or_mv_opstr(command, e[0], e[1], e[2], e[3]) if e.size == 4
|
110
|
+
end
|
111
|
+
Auth.request Config.settings[:rs_host] + "/batch?" + execs.join("&")
|
112
|
+
end
|
113
|
+
|
80
114
|
end
|
81
115
|
end
|
82
116
|
end
|
data/lib/qiniu/rs/version.rb
CHANGED
data/spec/qiniu/rs/rs_spec.rb
CHANGED
@@ -13,6 +13,7 @@ module Qiniu
|
|
13
13
|
before :all do
|
14
14
|
@bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
15
15
|
@key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s)
|
16
|
+
@key2 = @key + rand(100).to_s
|
16
17
|
#@domain = @bucket + '.dn.qbox.me'
|
17
18
|
|
18
19
|
code, data = Qiniu::RS::RS.mkbucket(@bucket)
|
@@ -89,6 +90,34 @@ module Qiniu
|
|
89
90
|
end
|
90
91
|
end
|
91
92
|
|
93
|
+
context ".batch_copy" do
|
94
|
+
it "should works" do
|
95
|
+
code, data = Qiniu::RS::RS.batch_copy [@bucket, @key, @bucket, @key2]
|
96
|
+
code.should == 200
|
97
|
+
puts data.inspect
|
98
|
+
|
99
|
+
#code2, data2 = Qiniu::RS::RS.stat(@bucket, @key2)
|
100
|
+
#code2.should == 200
|
101
|
+
#puts data2.inspect
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context ".batch_move" do
|
106
|
+
it "should works" do
|
107
|
+
code, data = Qiniu::RS::RS.batch_move [@bucket, @key, @bucket, @key2]
|
108
|
+
code.should == 200
|
109
|
+
puts data.inspect
|
110
|
+
|
111
|
+
#code2, data2 = Qiniu::RS::RS.stat(@bucket, @key2)
|
112
|
+
#code2.should == 200
|
113
|
+
#puts data2.inspect
|
114
|
+
|
115
|
+
code3, data3 = Qiniu::RS::RS.batch_move [@bucket, @key2, @bucket, @key]
|
116
|
+
code3.should == 200
|
117
|
+
puts data3.inspect
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
92
121
|
=begin
|
93
122
|
context ".publish" do
|
94
123
|
it "should works" do
|
@@ -107,6 +136,34 @@ module Qiniu
|
|
107
136
|
end
|
108
137
|
=end
|
109
138
|
|
139
|
+
context ".copy" do
|
140
|
+
it "should works" do
|
141
|
+
code, data = Qiniu::RS::RS.copy(@bucket, @key, @bucket, @key2)
|
142
|
+
code.should == 200
|
143
|
+
puts data.inspect
|
144
|
+
|
145
|
+
#code2, data2 = Qiniu::RS::RS.stat(@bucket, @key2)
|
146
|
+
#code2.should == 200
|
147
|
+
#puts data2.inspect
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
context ".move" do
|
152
|
+
it "should works" do
|
153
|
+
code, data = Qiniu::RS::RS.move(@bucket, @key, @bucket, @key2)
|
154
|
+
code.should == 200
|
155
|
+
puts data.inspect
|
156
|
+
|
157
|
+
code2, data2 = Qiniu::RS::RS.stat(@bucket, @key2)
|
158
|
+
code2.should == 200
|
159
|
+
puts data2.inspect
|
160
|
+
|
161
|
+
code3, data3 = Qiniu::RS::RS.move(@bucket, @key2, @bucket, @key)
|
162
|
+
code3.should == 200
|
163
|
+
puts data3.inspect
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
110
167
|
context ".delete" do
|
111
168
|
it "should works" do
|
112
169
|
code, data = Qiniu::RS::RS.delete(@bucket, @key)
|
data/spec/qiniu/rs_spec.rb
CHANGED
@@ -11,6 +11,7 @@ module Qiniu
|
|
11
11
|
before :all do
|
12
12
|
@bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
13
13
|
@key = Digest::SHA1.hexdigest Time.now.to_s
|
14
|
+
@key2 = @key + rand(100).to_s
|
14
15
|
#@domain = @bucket + '.dn.qbox.me'
|
15
16
|
|
16
17
|
result = Qiniu::RS.mkbucket(@bucket)
|
@@ -295,6 +296,52 @@ module Qiniu
|
|
295
296
|
end
|
296
297
|
=end
|
297
298
|
|
299
|
+
context ".batch_copy" do
|
300
|
+
it "should works" do
|
301
|
+
result = Qiniu::RS.batch_copy [@bucket, @key, @bucket, @key2]
|
302
|
+
result.should_not be_false
|
303
|
+
|
304
|
+
#result2 = Qiniu::RS.stat(@bucket, @key2)
|
305
|
+
#result2.should_not be_false
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
context ".batch_move" do
|
310
|
+
it "should works" do
|
311
|
+
result = Qiniu::RS::RS.batch_move [@bucket, @key, @bucket, @key2]
|
312
|
+
result.should_not be_false
|
313
|
+
|
314
|
+
#result2 = Qiniu::RS.stat(@bucket, @key2)
|
315
|
+
#result2.should_not be_false
|
316
|
+
|
317
|
+
result3 = Qiniu::RS.batch_move [@bucket, @key2, @bucket, @key]
|
318
|
+
result3.should_not be_false
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
context ".copy" do
|
323
|
+
it "should works" do
|
324
|
+
result = Qiniu::RS.copy(@bucket, @key, @bucket, @key2)
|
325
|
+
result.should_not be_false
|
326
|
+
|
327
|
+
#result2 = Qiniu::RS.stat(@bucket, @key2)
|
328
|
+
#result2.should_not be_false
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
context ".move" do
|
333
|
+
it "should works" do
|
334
|
+
result = Qiniu::RS.move(@bucket, @key, @bucket, @key2)
|
335
|
+
result.should_not be_false
|
336
|
+
|
337
|
+
result2 = Qiniu::RS.stat(@bucket, @key2)
|
338
|
+
result2.should_not be_false
|
339
|
+
|
340
|
+
result3 = Qiniu::RS.move(@bucket, @key2, @bucket, @key)
|
341
|
+
result3.should_not be_false
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
298
345
|
context ".delete" do
|
299
346
|
it "should works" do
|
300
347
|
result = Qiniu::RS.delete(@bucket, @key)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qiniu-rs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -188,7 +188,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
188
188
|
version: '0'
|
189
189
|
segments:
|
190
190
|
- 0
|
191
|
-
hash: -
|
191
|
+
hash: -3190608714994781075
|
192
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
193
|
none: false
|
194
194
|
requirements:
|
@@ -197,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
197
|
version: '0'
|
198
198
|
segments:
|
199
199
|
- 0
|
200
|
-
hash: -
|
200
|
+
hash: -3190608714994781075
|
201
201
|
requirements: []
|
202
202
|
rubyforge_project:
|
203
203
|
rubygems_version: 1.8.24
|