qiniu-rs 2.0.5 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qiniu-rs (2.0.5)
4
+ qiniu-rs (2.1.1)
5
5
  json (~> 1.7.3)
6
6
  mime-types (~> 1.19)
7
7
  rest-client (~> 1.6.7)
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # Qiniu Resource (Cloud) Storage SDK for Ruby - [![Build Status](https://secure.travis-ci.org/why404/qiniu-rs.png?branch=master)](http://travis-ci.org/why404/qiniu-rs) [![Dependency Status](https://gemnasium.com/why404/qiniu-rs.png)](https://gemnasium.com/why404/qiniu-rs)
1
+ # Qiniu Resource (Cloud) Storage SDK for Ruby - [![Build Status](https://secure.travis-ci.org/why404/qiniu-rs-for-ruby.png?branch=master)](http://travis-ci.org/why404/qiniu-rs-for-ruby) [![Dependency Status](https://gemnasium.com/why404/qiniu-rs-for-ruby.png)](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/v1/api/) 构建。使用此 SDK 构建您的网络应用程序,能让您以非常便捷地方式将数据安全地存储到七牛云存储上。无论您的网络应用是一个网站程序,还是包括从云端(服务端程序)到终端(手持设备应用)的架构的服务或应用,通过七牛云存储及其 SDK,都能让您应用程序的终端用户高速上传和下载,同时也让您的服务端更加轻盈。
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, {:signature_auth => true}
62
+ code, data = http_request url, data, {:qbox_signature_token => generate_qbox_signature(url, data)}
63
63
  [code, data]
64
64
  end
65
65
 
@@ -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 => "",
@@ -38,12 +38,15 @@ module Qiniu
38
38
  :accept => :json,
39
39
  :user_agent => Config.settings[:user_agent]
40
40
  }
41
- if options[:signature_auth] && options[:signature_auth] == true
42
- signature_token = generate_qbox_signature(Config.settings[:access_key], Config.settings[:secret_key], url, data)
43
- header_options.merge!('Authorization' => "QBox #{signature_token}")
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
- header_options.merge!('Authorization' => "Bearer #{options[:access_token]}")
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(access_key, secret_key, url, params)
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Qiniu
4
4
  module RS
5
- VERSION = "2.0.5"
5
+ VERSION = "2.1.1"
6
6
  end
7
7
  end
@@ -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.0.5
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-06-29 00:00:00.000000000 Z
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: -3585720177753596868
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: -3585720177753596868
185
+ hash: 1345358308427521600
186
186
  requirements: []
187
187
  rubyforge_project:
188
188
  rubygems_version: 1.8.24