qiniu-rs 3.1.0 → 3.2.0
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/Gemfile.lock +1 -1
- data/docs/README.md +15 -1
- data/lib/qiniu/rs.rb +1 -0
- data/lib/qiniu/rs/version.rb +1 -1
- data/lib/qiniu/tokens/upload_token.rb +3 -1
- data/spec/qiniu/rs/eu_spec.rb +12 -7
- data/spec/qiniu/rs/image_spec.rb +14 -22
- data/spec/qiniu/rs/io_spec.rb +12 -10
- data/spec/qiniu/rs/pub_spec.rb +6 -14
- data/spec/qiniu/rs/rs_spec.rb +10 -4
- data/spec/qiniu/rs/up_spec.rb +11 -1
- data/spec/qiniu/rs_spec.rb +25 -5
- data/spec/spec_helper.rb +0 -5
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/docs/README.md
CHANGED
@@ -120,7 +120,8 @@ title: Ruby SDK 使用指南 | 七牛云存储
|
|
120
120
|
:expires_in => expires_in_seconds,
|
121
121
|
:callback_url => callback_url,
|
122
122
|
:callback_body_type => callback_body_type,
|
123
|
-
:customer => end_user_id
|
123
|
+
:customer => end_user_id,
|
124
|
+
:escape => allow_upload_callback_api
|
124
125
|
|
125
126
|
**参数**
|
126
127
|
|
@@ -139,6 +140,19 @@ title: Ruby SDK 使用指南 | 七牛云存储
|
|
139
140
|
:customer
|
140
141
|
: 可选,字符串类型(String),客户方终端用户(End User)的ID,该字段可以用来标示一个文件的属主,这在一些特殊场景下(比如给终端用户上传的图片打上名字水印)非常有用。
|
141
142
|
|
143
|
+
:escape
|
144
|
+
: 可选,数字类型,可选值 0 或者 1,缺省为 0 。值为 1 表示 callback 传递的自定义数据中允许存在转义符号 `$(VarExpression)`,参考 [VarExpression](/v3/api/words/#VarExpression)。
|
145
|
+
|
146
|
+
当 `escape` 的值为 `1` 时,常见的转义语法如下:
|
147
|
+
|
148
|
+
- 若 `callbackBodyType` 为 `application/json` 时,一个典型的自定义回调数据([CallbackParams](/v3/api/io/#CallbackParams))为:
|
149
|
+
|
150
|
+
`{foo: "bar", w: $(imageInfo.width), h: $(imageInfo.height), exif: $(exif)}`
|
151
|
+
|
152
|
+
- 若 `callbackBodyType` 为 `application/x-www-form-urlencoded` 时,一个典型的自定义回调数据([CallbackParams](/v3/api/io/#CallbackParams))为:
|
153
|
+
|
154
|
+
`foo=bar&w=$(imageInfo.width)&h=$(imageInfo.height)&exif=$(exif)`
|
155
|
+
|
142
156
|
**返回值**
|
143
157
|
|
144
158
|
返回一个字符串类型(String)的用于上传文件用的临时授权 `upload_token`。
|
data/lib/qiniu/rs.rb
CHANGED
data/lib/qiniu/rs/version.rb
CHANGED
@@ -10,7 +10,7 @@ module Qiniu
|
|
10
10
|
|
11
11
|
include Utils
|
12
12
|
|
13
|
-
attr_accessor :scope, :expires_in, :callback_url, :callback_body_type, :customer
|
13
|
+
attr_accessor :scope, :expires_in, :callback_url, :callback_body_type, :customer, :escape
|
14
14
|
|
15
15
|
def initialize(opts = {})
|
16
16
|
@scope = opts[:scope]
|
@@ -18,6 +18,7 @@ module Qiniu
|
|
18
18
|
@callback_url = opts[:callback_url]
|
19
19
|
@callback_body_type = opts[:callback_body_type]
|
20
20
|
@customer = opts[:customer]
|
21
|
+
@escape = opts[:escape]
|
21
22
|
end
|
22
23
|
|
23
24
|
def generate_signature
|
@@ -25,6 +26,7 @@ module Qiniu
|
|
25
26
|
params[:callbackUrl] = @callback_url if !@callback_url.nil? && !@callback_url.empty?
|
26
27
|
params[:callbackBodyType] = @callback_body_type if !@callback_body_type.nil? && !@callback_body_type.empty?
|
27
28
|
params[:customer] = @customer if !@customer.nil? && !@customer.empty?
|
29
|
+
params[:escape] = 1 if @escape == 1 || @escape == true
|
28
30
|
urlsafe_base64_encode(params.to_json)
|
29
31
|
end
|
30
32
|
|
data/spec/qiniu/rs/eu_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
-
require 'qiniu/rs
|
4
|
+
require 'qiniu/rs'
|
5
5
|
require 'qiniu/rs/pub'
|
6
6
|
require 'qiniu/rs/eu'
|
7
7
|
|
@@ -14,12 +14,15 @@ module Qiniu
|
|
14
14
|
@bucket = "wm_test_bucket"
|
15
15
|
@key = "image_logo_for_test.png"
|
16
16
|
|
17
|
+
result = Qiniu::RS.mkbucket(@bucket)
|
18
|
+
puts result.inspect
|
19
|
+
result.should be_true
|
20
|
+
|
17
21
|
local_file = File.expand_path('../' + @key, __FILE__)
|
18
22
|
upopts = {:scope => @bucket, :expires_in => 3600, :customer => @customer_id}
|
19
23
|
uptoken = Qiniu::RS.generate_upload_token(upopts)
|
20
24
|
|
21
|
-
|
22
|
-
code.should == 200
|
25
|
+
data = Qiniu::RS.upload_file :uptoken => uptoken, :file => local_file, :bucket => @bucket, :key => @key
|
23
26
|
puts data.inspect
|
24
27
|
|
25
28
|
code2, data2 = Qiniu::RS::Pub.set_separator(@bucket, "-")
|
@@ -31,10 +34,12 @@ module Qiniu
|
|
31
34
|
puts data3.inspect
|
32
35
|
end
|
33
36
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
after :all do
|
38
|
+
@bucket = "wm_test_bucket"
|
39
|
+
result = Qiniu::RS.drop(@bucket)
|
40
|
+
puts result.inspect
|
41
|
+
result.should_not be_false
|
42
|
+
end
|
38
43
|
|
39
44
|
context ".set_watermark" do
|
40
45
|
it "should works" do
|
data/spec/qiniu/rs/image_spec.rb
CHANGED
@@ -10,35 +10,20 @@ module Qiniu
|
|
10
10
|
describe Image do
|
11
11
|
|
12
12
|
before :all do
|
13
|
-
=begin
|
14
|
-
code, data = Qiniu::RS::Auth.exchange_by_password!("test@qbox.net", "test")
|
15
|
-
code.should == 200
|
16
|
-
data.should be_an_instance_of(Hash)
|
17
|
-
data["access_token"].should_not be_empty
|
18
|
-
data["refresh_token"].should_not be_empty
|
19
|
-
data["refresh_token"].should_not be_empty
|
20
|
-
puts data.inspect
|
21
|
-
=end
|
22
13
|
|
23
14
|
@bucket = "test_images_12345"
|
24
15
|
@key = "image_logo_for_test.png"
|
25
16
|
|
26
|
-
|
27
|
-
|
28
|
-
result = Qiniu::RS.drop(@bucket)
|
29
|
-
result.should_not be_false
|
17
|
+
result = Qiniu::RS.mkbucket(@bucket)
|
30
18
|
puts result.inspect
|
31
|
-
|
32
|
-
put_url = Qiniu::RS.put_auth(10)
|
33
|
-
put_url.should_not be_false
|
34
|
-
put_url.should_not be_empty
|
35
|
-
result = Qiniu::RS.upload :url => put_url,
|
36
|
-
:file => local_file,
|
37
|
-
:bucket => @bucket,
|
38
|
-
:key => @key,
|
39
|
-
:enable_crc32_check => true
|
40
19
|
result.should be_true
|
41
20
|
|
21
|
+
local_file = File.expand_path('../' + @key, __FILE__)
|
22
|
+
|
23
|
+
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "awhy.xu@gmail.com"}
|
24
|
+
uptoken = Qiniu::RS.generate_upload_token(upopts)
|
25
|
+
data = Qiniu::RS.upload_file :uptoken => uptoken, :file => local_file, :bucket => @bucket, :key => @key
|
26
|
+
puts data.inspect
|
42
27
|
|
43
28
|
result = Qiniu::RS.get(@bucket, @key)
|
44
29
|
result["url"].should_not be_empty
|
@@ -56,6 +41,13 @@ module Qiniu
|
|
56
41
|
}
|
57
42
|
end
|
58
43
|
|
44
|
+
after :all do
|
45
|
+
@bucket = "test_images_12345"
|
46
|
+
result = Qiniu::RS.drop(@bucket)
|
47
|
+
puts result.inspect
|
48
|
+
result.should_not be_false
|
49
|
+
end
|
50
|
+
|
59
51
|
context ".info" do
|
60
52
|
it "should works" do
|
61
53
|
code, data = Qiniu::RS::Image.info(@source_image_url)
|
data/spec/qiniu/rs/io_spec.rb
CHANGED
@@ -10,17 +10,19 @@ module Qiniu
|
|
10
10
|
describe IO do
|
11
11
|
|
12
12
|
before :all do
|
13
|
-
=
|
14
|
-
code, data = Qiniu::RS::Auth.exchange_by_password!("test@qbox.net", "test")
|
15
|
-
code.should == 200
|
16
|
-
data.should be_an_instance_of(Hash)
|
17
|
-
data["access_token"].should_not be_empty
|
18
|
-
data["refresh_token"].should_not be_empty
|
19
|
-
data["refresh_token"].should_not be_empty
|
20
|
-
puts data.inspect
|
21
|
-
=end
|
22
|
-
@bucket = "test"
|
13
|
+
@bucket = "io_test_bucket"
|
23
14
|
@key = Digest::SHA1.hexdigest (Time.now.to_i+rand(100)).to_s
|
15
|
+
|
16
|
+
result = Qiniu::RS.mkbucket(@bucket)
|
17
|
+
puts result.inspect
|
18
|
+
result.should be_true
|
19
|
+
end
|
20
|
+
|
21
|
+
after :all do
|
22
|
+
@bucket = "io_test_bucket"
|
23
|
+
result = Qiniu::RS.drop(@bucket)
|
24
|
+
puts result.inspect
|
25
|
+
result.should_not be_false
|
24
26
|
end
|
25
27
|
|
26
28
|
context ".upload_file" do
|
data/spec/qiniu/rs/pub_spec.rb
CHANGED
@@ -10,24 +10,16 @@ module Qiniu
|
|
10
10
|
describe Pub do
|
11
11
|
|
12
12
|
before :all do
|
13
|
-
@bucket = "
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
=begin
|
20
|
-
context ".mkbucket" do
|
21
|
-
it "should works" do
|
22
|
-
code, data = Qiniu::RS::RS.mkbucket(@bucket)
|
23
|
-
code.should == 200
|
24
|
-
puts data.inspect
|
25
|
-
end
|
13
|
+
@bucket = "pub_test_bucket"
|
14
|
+
result = Qiniu::RS.mkbucket(@bucket)
|
15
|
+
puts result.inspect
|
16
|
+
result.should_not be_false
|
26
17
|
end
|
27
|
-
=end
|
28
18
|
|
29
19
|
after :all do
|
20
|
+
@bucket = "pub_test_bucket"
|
30
21
|
result = Qiniu::RS.drop(@bucket)
|
22
|
+
puts result.inspect
|
31
23
|
result.should_not be_false
|
32
24
|
end
|
33
25
|
|
data/spec/qiniu/rs/rs_spec.rb
CHANGED
@@ -11,13 +11,19 @@ module Qiniu
|
|
11
11
|
describe RS do
|
12
12
|
|
13
13
|
before :all do
|
14
|
-
|
15
|
-
@bucket = "test_bucket_1234"
|
14
|
+
@bucket = "rs_test_bucket"
|
16
15
|
@key = Digest::SHA1.hexdigest (Time.now.to_i+rand(100)).to_s
|
17
|
-
@domain = '
|
16
|
+
@domain = 'rs-test-bucket.dn.qbox.me'
|
18
17
|
|
19
18
|
code, data = Qiniu::RS::RS.mkbucket(@bucket)
|
20
|
-
puts data.inspect
|
19
|
+
puts [code, data].inspect
|
20
|
+
code.should == 200
|
21
|
+
end
|
22
|
+
|
23
|
+
after :all do
|
24
|
+
@bucket = "rs_test_bucket"
|
25
|
+
code, data = Qiniu::RS::RS.drop(@bucket)
|
26
|
+
puts [code, data].inspect
|
21
27
|
code.should == 200
|
22
28
|
end
|
23
29
|
|
data/spec/qiniu/rs/up_spec.rb
CHANGED
@@ -12,12 +12,22 @@ module Qiniu
|
|
12
12
|
before :all do
|
13
13
|
@localfile = "bigfile.txt"
|
14
14
|
File.open(@localfile, "w"){|f| 9437184.times{f.write(Random.rand(9).to_s)}}
|
15
|
-
@bucket = "
|
15
|
+
@bucket = "up_test_bucket"
|
16
16
|
@key = Digest::SHA1.hexdigest(@localfile+Time.now.to_s)
|
17
|
+
|
18
|
+
code, data = Qiniu::RS::RS.mkbucket(@bucket)
|
19
|
+
puts [code, data].inspect
|
20
|
+
code.should == 200
|
17
21
|
end
|
18
22
|
|
19
23
|
after :all do
|
24
|
+
@localfile = "bigfile.txt"
|
20
25
|
File.unlink(@localfile) if File.exists?(@localfile)
|
26
|
+
|
27
|
+
@bucket = "up_test_bucket"
|
28
|
+
code, data = Qiniu::RS::RS.drop(@bucket)
|
29
|
+
puts [code, data].inspect
|
30
|
+
code.should == 200
|
21
31
|
end
|
22
32
|
|
23
33
|
context ".upload_with_token" do
|
data/spec/qiniu/rs_spec.rb
CHANGED
@@ -10,13 +10,33 @@ module Qiniu
|
|
10
10
|
before :all do
|
11
11
|
@bucket = 'qiniu_rs_test'
|
12
12
|
@key = Digest::SHA1.hexdigest Time.now.to_s
|
13
|
-
@domain = '
|
13
|
+
@domain = 'qiniu-rs-test.dn.qbox.me'
|
14
|
+
|
15
|
+
result = Qiniu::RS.mkbucket(@bucket)
|
16
|
+
result.should_not be_false
|
14
17
|
|
15
18
|
@test_image_bucket = 'test_images_12345'
|
19
|
+
result2 = Qiniu::RS.mkbucket(@test_image_bucket)
|
20
|
+
puts result2.inspect
|
21
|
+
result2.should be_true
|
22
|
+
|
16
23
|
@test_image_key = 'image_logo_for_test.png'
|
24
|
+
local_file = File.expand_path('./rs/' + @test_image_key, File.dirname(__FILE__))
|
25
|
+
puts local_file.inspect
|
26
|
+
upopts = {:scope => @test_image_bucket, :expires_in => 3600, :customer => "awhy.xu@gmail.com"}
|
27
|
+
uptoken = Qiniu::RS.generate_upload_token(upopts)
|
28
|
+
data = Qiniu::RS.upload_file :uptoken => uptoken, :file => local_file, :bucket => @test_image_bucket, :key => @test_image_key
|
29
|
+
puts data.inspect
|
30
|
+
end
|
17
31
|
|
18
|
-
|
32
|
+
after :all do
|
33
|
+
result = Qiniu::RS.drop(@bucket)
|
34
|
+
puts result.inspect
|
19
35
|
result.should_not be_false
|
36
|
+
|
37
|
+
result2 = Qiniu::RS.drop(@test_image_bucket)
|
38
|
+
puts result2.inspect
|
39
|
+
result2.should_not be_false
|
20
40
|
end
|
21
41
|
|
22
42
|
context ".buckets" do
|
@@ -116,7 +136,7 @@ module Qiniu
|
|
116
136
|
|
117
137
|
context ".upload_file" do
|
118
138
|
it "should works" do
|
119
|
-
uptoken_opts = {:scope => @bucket}
|
139
|
+
uptoken_opts = {:scope => @bucket, :escape => 0}
|
120
140
|
upload_opts = {
|
121
141
|
:uptoken => Qiniu::RS.generate_upload_token(uptoken_opts),
|
122
142
|
:file => __FILE__,
|
@@ -137,7 +157,7 @@ module Qiniu
|
|
137
157
|
File.open(localfile, "w"){|f| 5242888.times{f.write(Random.rand(9).to_s)}}
|
138
158
|
key = Digest::SHA1.hexdigest(localfile+Time.now.to_s)
|
139
159
|
# generate the upload token
|
140
|
-
uptoken_opts = {:scope => @bucket, :expires_in => 3600, :customer => "awhy.xu@gmail.com"}
|
160
|
+
uptoken_opts = {:scope => @bucket, :expires_in => 3600, :customer => "awhy.xu@gmail.com", :escape => 0}
|
141
161
|
uptoken = Qiniu::RS.generate_upload_token(uptoken_opts)
|
142
162
|
# uploading
|
143
163
|
upload_opts = {
|
@@ -311,7 +331,7 @@ module Qiniu
|
|
311
331
|
|
312
332
|
context ".generate_upload_token" do
|
313
333
|
it "should works" do
|
314
|
-
data = Qiniu::RS.generate_upload_token({:scope => 'test_bucket', :expires_in => 3600})
|
334
|
+
data = Qiniu::RS.generate_upload_token({:scope => 'test_bucket', :expires_in => 3600, :escape => 0})
|
315
335
|
data.should_not be_empty
|
316
336
|
puts data.inspect
|
317
337
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -14,10 +14,5 @@ RSpec.configure do |config|
|
|
14
14
|
:up_host => "http://m1.qbox.me:13019",
|
15
15
|
:pub_host => "http://m1.qbox.me:13012",
|
16
16
|
:eu_host => "http://m1.qbox.me:13050"
|
17
|
-
|
18
|
-
=begin
|
19
|
-
Qiniu::RS.establish_connection! :access_key => "aPoWOtE9EFca1fLxFCtlkeZAOV7aADVMTLdSydmr",
|
20
|
-
:secret_key => "L3ShtjCQTCagVCDPfHJoOix7JO_o3qHz3ScyflUG"
|
21
|
-
=end
|
22
17
|
end
|
23
18
|
end
|
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.2.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: 2012-
|
12
|
+
date: 2012-11-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -185,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
185
185
|
version: '0'
|
186
186
|
segments:
|
187
187
|
- 0
|
188
|
-
hash: -
|
188
|
+
hash: -1772057481364600081
|
189
189
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
190
|
none: false
|
191
191
|
requirements:
|
@@ -194,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
194
|
version: '0'
|
195
195
|
segments:
|
196
196
|
- 0
|
197
|
-
hash: -
|
197
|
+
hash: -1772057481364600081
|
198
198
|
requirements: []
|
199
199
|
rubyforge_project:
|
200
200
|
rubygems_version: 1.8.24
|