qiniu-rs 2.0.5 → 2.1.1
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/README.md +2 -2
- data/lib/qiniu/rs.rb +4 -0
- data/lib/qiniu/rs/auth.rb +1 -1
- data/lib/qiniu/rs/config.rb +0 -2
- data/lib/qiniu/rs/utils.rb +23 -5
- data/lib/qiniu/rs/version.rb +1 -1
- data/spec/qiniu/rs_spec.rb +8 -0
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
# Qiniu Resource (Cloud) Storage SDK for Ruby - [](http://travis-ci.org/why404/qiniu-rs) [](https://gemnasium.com/why404/qiniu-rs)
|
1
|
+
# Qiniu Resource (Cloud) Storage SDK for Ruby - [](http://travis-ci.org/why404/qiniu-rs-for-ruby) [](https://gemnasium.com/why404/qiniu-rs-for-ruby)
|
2
2
|
|
3
3
|
# 关于
|
4
4
|
|
5
|
-
此 Ruby SDK 适用于 Ruby 1.8.x, 1.9.x, jruby, rbx, ree 版本,基于 [七牛云存储官方API](http://docs.qiniutek.com/
|
5
|
+
此 Ruby SDK 适用于 Ruby 1.8.x, 1.9.x, jruby, rbx, ree 版本,基于 [七牛云存储官方API](http://docs.qiniutek.com/v2/api/) 构建。使用此 SDK 构建您的网络应用程序,能让您以非常便捷地方式将数据安全地存储到七牛云存储上。无论您的网络应用是一个网站程序,还是包括从云端(服务端程序)到终端(手持设备应用)的架构的服务或应用,通过七牛云存储及其 SDK,都能让您应用程序的终端用户高速上传和下载,同时也让您的服务端更加轻盈。
|
6
6
|
|
7
7
|
## 安装
|
8
8
|
|
data/lib/qiniu/rs.rb
CHANGED
@@ -115,6 +115,10 @@ module Qiniu
|
|
115
115
|
Image.preivew_url(url, spec)
|
116
116
|
end
|
117
117
|
|
118
|
+
def generate_upload_token(scope, expires_in, callback_url = nil, return_url = nil)
|
119
|
+
Utils.generate_upload_token(scope, expires_in, callback_url, return_url)
|
120
|
+
end
|
121
|
+
|
118
122
|
end
|
119
123
|
|
120
124
|
end
|
data/lib/qiniu/rs/auth.rb
CHANGED
@@ -59,7 +59,7 @@ module Qiniu
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def call_with_signature(url, data, retry_times = 0)
|
62
|
-
code, data = http_request url, data, {:
|
62
|
+
code, data = http_request url, data, {:qbox_signature_token => generate_qbox_signature(url, data)}
|
63
63
|
[code, data]
|
64
64
|
end
|
65
65
|
|
data/lib/qiniu/rs/config.rb
CHANGED
@@ -21,9 +21,7 @@ module Qiniu
|
|
21
21
|
:content_type => 'application/x-www-form-urlencoded',
|
22
22
|
:auth_url => "https://acc.qbox.me/oauth2/token",
|
23
23
|
:rs_host => "http://rs.qbox.me:10100",
|
24
|
-
#:rs_host => "http://localhost:10100",
|
25
24
|
:io_host => "http://iovip.qbox.me",
|
26
|
-
#:io_host => "http://localhost:10200",
|
27
25
|
:client_id => "a75604760c4da4caaa456c0c5895c061c3065c5a",
|
28
26
|
:client_secret => "75df554a39f58accb7eb293b550fa59618674b7d",
|
29
27
|
:access_key => "",
|
data/lib/qiniu/rs/utils.rb
CHANGED
@@ -38,12 +38,15 @@ module Qiniu
|
|
38
38
|
:accept => :json,
|
39
39
|
:user_agent => Config.settings[:user_agent]
|
40
40
|
}
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
auth_token = nil
|
42
|
+
if !options[:qbox_signature_token].nil? && !options[:qbox_signature_token].empty?
|
43
|
+
auth_token = 'QBox ' + options[:qbox_signature_token]
|
44
|
+
#elsif !options[:upload_signature_token].nil? && !options[:upload_signature_token].empty?
|
45
|
+
# auth_token = 'UpToken ' + options[:upload_signature_token]
|
44
46
|
elsif options[:access_token]
|
45
|
-
|
47
|
+
auth_token = 'Bearer ' + options[:access_token]
|
46
48
|
end
|
49
|
+
header_options.merge!('Authorization' => auth_token) unless auth_token.nil?
|
47
50
|
case options[:method]
|
48
51
|
when :get
|
49
52
|
response = RestClient.get url, header_options
|
@@ -130,7 +133,9 @@ module Qiniu
|
|
130
133
|
File.open(filepath, "rb") { |f| Zlib.crc32 f.read }
|
131
134
|
end
|
132
135
|
|
133
|
-
def generate_qbox_signature(
|
136
|
+
def generate_qbox_signature(url, params)
|
137
|
+
access_key = Config.settings[:access_key]
|
138
|
+
secret_key = Config.settings[:secret_key]
|
134
139
|
uri = URI.parse(url)
|
135
140
|
signature = uri.path
|
136
141
|
query_string = uri.query
|
@@ -146,6 +151,19 @@ module Qiniu
|
|
146
151
|
%Q(#{access_key}:#{encoded_digest})
|
147
152
|
end
|
148
153
|
|
154
|
+
def generate_upload_token(scope, expires_in, callback_url = nil, return_url = nil)
|
155
|
+
access_key = Config.settings[:access_key]
|
156
|
+
secret_key = Config.settings[:secret_key]
|
157
|
+
params = {:scope => scope, :deadline => Time.now.to_i + expires_in}
|
158
|
+
params[:callbackUrl] = callback_url if !callback_url.nil? && !calback_url.empty?
|
159
|
+
params[:returnUrl] = return_url if !return_url.nil? && !return_url.empty?
|
160
|
+
signature = urlsafe_base64_encode(params.to_json)
|
161
|
+
hmac = HMAC::SHA1.new(secret_key)
|
162
|
+
hmac.update(signature)
|
163
|
+
encoded_digest = urlsafe_base64_encode(hmac.digest)
|
164
|
+
%Q(#{access_key}:#{encoded_digest}:#{signature})
|
165
|
+
end
|
166
|
+
|
149
167
|
end
|
150
168
|
end
|
151
169
|
end
|
data/lib/qiniu/rs/version.rb
CHANGED
data/spec/qiniu/rs_spec.rb
CHANGED
@@ -149,5 +149,13 @@ module Qiniu
|
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
152
|
+
context ".generate_upload_token" do
|
153
|
+
it "should works" do
|
154
|
+
data = Qiniu::RS.generate_upload_token('test_bucket', 3600)
|
155
|
+
data.should_not be_empty
|
156
|
+
puts data.inspect
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
152
160
|
end
|
153
161
|
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: 2.
|
4
|
+
version: 2.1.1
|
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-07-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -173,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
173
173
|
version: '0'
|
174
174
|
segments:
|
175
175
|
- 0
|
176
|
-
hash:
|
176
|
+
hash: 1345358308427521600
|
177
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
178
|
none: false
|
179
179
|
requirements:
|
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
182
|
version: '0'
|
183
183
|
segments:
|
184
184
|
- 0
|
185
|
-
hash:
|
185
|
+
hash: 1345358308427521600
|
186
186
|
requirements: []
|
187
187
|
rubyforge_project:
|
188
188
|
rubygems_version: 1.8.24
|