Compare commits

..
99 Commits
Author SHA1 Message Date
Bai Long 785d960ac0 Merge pull request #133 from BluntBlade/master
加上对回调请求进行签名验证的逻辑
2015-09-24 13:22:20 +08:00
Liang Tao e308ce1cfd 调整版本号。 2015-09-13 20:50:11 +08:00
Liang Tao 1248008642 调整测试代码。 2015-09-13 20:46:00 +08:00
Liang Tao 57d522ce39 添加验证回调请求的函数。 2015-09-13 20:32:41 +08:00
Bai Long c2b72befb9 Merge pull request #132 from BluntBlade/master
修正对于 application/json; charset=utf-8 的判断。
2015-09-12 10:25:39 +08:00
Liang Tao 2912ed9eea Merge branch '20150326.application_json_utf8' 2015-08-24 18:09:34 +08:00
Liang Tao 52057ff062 恢复 exif 接口的单元测试,可以覆盖 application/json; charset=utf-8 的解析测试。 2015-08-24 18:09:22 +08:00
Bai Long 69c5eadede Merge pull request #126 from BluntBlade/master
合并一些常规修正逻辑
2015-06-26 14:04:07 +08:00
Liang Tao 9969818797 修正 CHANGELOG 中的 PR 号码。 2015-06-23 22:35:54 +08:00
Liang Tao 44dcf0b622 修改 Qiniu::Auth ,增加一个将底层异常转换成更友好提示的异常。 2015-06-23 22:28:37 +08:00
Liang Tao 6bf653f116 Merge branch 'master' of github.com:qiniu/ruby-sdk 2015-06-23 20:10:41 +08:00
Liang Tao 1b0491a2c9 修正入口函数 upload_file ,以正确地调用分片上传功能。 2015-05-13 21:23:32 +08:00
Liang Tao f53dec3242 修正对于 application/json; charset=utf-8 的判断。 2015-04-14 14:31:19 +08:00
longbai 821d2363b3 version upate 2015-04-08 17:22:28 +08:00
Bai Long e8fb64e7ec Merge pull request #122 from BluntBlade/master
兼容性和安全性调整
2015-03-26 07:59:42 +08:00
Liang Tao adb20cd815 修正测试用例。 2015-03-17 21:58:34 +08:00
Liang Tao fb9eb56bc0 修正 Pub 服务相关 SDK 。 2015-03-17 21:01:37 +08:00
Liang Tao 813f57241d 调整相对路径。 2015-03-17 17:46:45 +08:00
Liang Tao 4a86397b3d 调整 gemspec 路径。 2015-03-17 17:34:38 +08:00
Liang Tao fbea6bd019 升级 Gemfile.lock 文件。 2015-03-17 16:43:06 +08:00
Liang Tao ed6525a35e 修正过低版本的 gem 包引入的安全问题。OSVDB-117461 / CVE-2013-0269 2015-03-17 14:17:15 +08:00
Liang Tao 9d4316650d 针对 rails 3.0 调整 gemfile 。 2015-03-17 13:38:54 +08:00
Bai Long 5713ad93e4 Merge pull request #120 from quake/callback_fetch_key
添加3个参数 :callback_host :callback_body_type :callback_fetch_key
2015-02-02 14:07:44 +08:00
quake 63a89b57ae move params line block 2015-02-02 12:16:17 +08:00
quake 65d71d12ae add :callback_host :callback_body_type :callback_fetch_key to upload policy 2015-02-02 10:16:16 +08:00
Bai Long 5332645665 Merge pull request #114 from liluo/dev
updated runtime dependency mime-types version
2014-12-14 23:08:09 +08:00
liluo 946442f782 updated runtime dependency mime-types version 2014-12-14 16:39:17 +08:00
Bai Long 8e4805cf68 [ci skip] 2014-12-11 23:40:07 +08:00
Bai Long 78147d76f8 Merge pull request #113 from BluntBlade/master
将 mime-types 依赖版本升级至 2.4.3 。
2014-12-11 23:36:53 +08:00
Liang Tao 2bb0514df4 更新 README 说明,将版本号提到最新。 2014-12-11 23:08:17 +08:00
Liang Tao 0bca27457a 将 mime-types 依赖版本升级到 2.4.3 。 2014-12-11 23:05:25 +08:00
Bai Long b21833779e Merge pull request #112 from dekexu/master
七牛up_host的修改
2014-12-11 22:47:05 +08:00
xudeke a64fb3a63e real merge 2014-12-10 14:42:34 +08:00
deco 0d2f2f23dd usage added 2014-12-10 10:12:50 +08:00
xudeke d0b4fb7412 ok 2014-12-09 21:18:27 +08:00
xudeke 40bf2cfbbb string keys to symbol 2014-12-09 21:17:17 +08:00
deco 4e80a5ec98 Update README.md 2014-12-09 20:30:16 +08:00
xudeke 4fbfdbf472 允许海外服务器高速上传 2014-12-09 14:18:30 +08:00
xudeke d14fe23e45 ok 2014-12-09 14:16:59 +08:00
deco 3d0578cb88 Update README.md 2014-12-09 13:18:12 +08:00
deco 09b8921d20 七牛海外服务器上传 2014-12-09 13:12:44 +08:00
Bai Long 7d65b22e2e [ci skip] 2014-11-28 18:02:00 +08:00
Bai Long 8b000c0a98 Merge pull request #111 from BluntBlade/master
更新接口代码
2014-11-28 18:00:35 +08:00
Liang Tao f93e50c838 更新 ChangeLog 。 2014-11-28 16:38:47 +08:00
Liang Tao b8f43a1ded 为 upload 的最新版本接口添加 content-type/mimeType 设置方法。 2014-11-28 16:22:58 +08:00
Liang Tao 804fa4d5b6 添加rsf_host。 2014-08-01 17:08:05 +08:00
Liang Tao 0f2466d4c2 Merge branch 'master' of github.com:qiniu/ruby-sdk into list
Conflicts:
	lib/qiniu/config.rb
2014-07-29 10:20:02 +08:00
Bai Long 93c3cb8dea update version [ci skip] 2014-07-24 21:27:48 +08:00
Bai Long 3cccf69b61 update log [ci skip] 2014-07-24 21:26:35 +08:00
Bai Long b98cec1433 Merge pull request #103 from longbai/update_dependency
update test
2014-07-24 17:23:44 +08:00
longbai a29cfe5a71 update test 2014-07-24 14:38:59 +08:00
Bai Long 17f69da758 Update CHANGELOG.md 2014-07-11 15:55:04 +08:00
Bai Long 7280ca139a Merge pull request #100 from dp90219/master
a mistake. change `persistent_ops` to `persistentOps` and so on
2014-07-09 22:16:17 +08:00
Bai Long bc30779647 Merge pull request #99 from coaku/b_xzk_upload_qiniu_com
#9891
2014-07-09 21:55:13 +08:00
liupeng b6ab98b238 Merge branch 'master' of https://github.com/dp90219/ruby-sdk 2014-07-09 14:09:44 +08:00
liupeng db62d9bcd3 a mistake. change params[:persistent_ops] to params[:persistentOps] and so on 2014-07-09 14:06:16 +08:00
xuzhaokui 089ebb2354 upload.qiniu.com 2014-07-09 11:27:46 +08:00
liupeng e97582e370 a mistake. change persistent_ops to persistentOps and so on 2014-07-09 10:20:22 +08:00
Bai Long c01a43f3d9 Merge pull request #97 from dp90219/master
去除generate_upload_token 中旧的async_options, 添加 persistent_ops
2014-07-08 20:51:50 +08:00
Bai Long 4142c0182a Merge pull request #98 from BluntBlade/master
为过时方法添加说明。
2014-07-08 20:50:48 +08:00
Liang Tao 3d9d50c3c5 为过时方法添加说明。 2014-07-08 17:20:12 +08:00
liupeng e0c4a14e20 去除generate_upload_token 中旧的async_options, 添加 persistent_ops, persistent_notify_url, persistent_pipeline 2014-07-08 17:09:41 +08:00
Bai Long 67c4d63a05 Merge pull request #95 from BluntBlade/master
添加 authorize_download_url_2 方法,对包含中文或其它 utf-8 字符的Key做下载授权。
2014-07-01 15:41:30 +08:00
Liang Tao 5ffe9daf58 更新版本信息。 2014-07-01 15:27:35 +08:00
Liang Tao a6debbec49 Merge branch 'master' of github.com:qiniu/ruby-sdk 2014-07-01 15:04:55 +08:00
Liang Tao 58dfe18328 添加 authorize_download_url_2 方法,对包含中文或其它 utf-8 字符的Key做下载授权。 2014-07-01 14:40:48 +08:00
Liang Tao 1222559c71 添加 schema 和 port 参数。 2014-07-01 11:57:45 +08:00
Liang Tao 31cbf3a6fd 添加针对中文Key的私有资源下载URL授权方法。 2014-06-30 16:08:46 +08:00
Bai Long 3504d39cd0 Update README.md 2014-06-20 22:11:03 +08:00
Bai Long 2322bbcd9c Update Gemfile.lock 2014-06-20 21:24:15 +08:00
Bai Long 1ece11ea89 Update version.rb 2014-06-20 21:23:36 +08:00
Bai Long 48abc7f7c1 Update CHANGELOG.md 2014-06-20 21:21:01 +08:00
Bai Long 4aca5af37e Update CHANGELOG.md
调整user agent
2014-06-20 21:20:23 +08:00
Bai Long 35661ebcbf Update config.rb 2014-06-20 21:12:21 +08:00
Bai Long c87b75d3cf Merge pull request #94 from longbai/user-agent
User agent
2014-06-20 20:59:57 +08:00
longbai 328306814a add new user agent 2014-06-20 20:40:09 +08:00
longbai e2d8a07882 update site 2014-06-20 20:39:51 +08:00
Bai Long 8f11a43123 Merge pull request #93 from BluntBlade/master
为PutPolicy添加persistentPipeline参数。
2014-06-06 13:19:29 +08:00
Liang Tao 9d8f684eec 补充版本更新信息。 2014-06-06 12:18:14 +08:00
Liang Tao 244735a3f2 为PutPolicy添加persistentPipeline参数。 2014-06-06 12:15:00 +08:00
Bai Long 53d5f1bb4b Merge pull request #92 from BluntBlade/master
一些同步更新
2014-06-04 15:28:07 +08:00
Liang Tao de31e33460 添加Pull Request URL。 2014-06-04 14:58:24 +08:00
Liang Tao 01711a6fd4 Merge branch 'master' of github.com:BluntBlade/ruby-sdk 2014-06-04 14:53:35 +08:00
Liang Tao 5735dce6e9 Merge branch 'master' of github.com:qiniu/ruby-sdk 2014-06-04 14:48:17 +08:00
Liang Tao 788e21720b 添加版本说明。 2014-06-04 14:48:16 +08:00
Liang Tao 1f6e9ba47b 为authorize_download_url()添加:fop参数,以便生成含FOP指令的授权下载URL。 2014-06-04 14:40:23 +08:00
Liang Tao a424c79dd6 添加pipeline参数,用于指定命名转码队列。 2014-06-04 14:16:20 +08:00
Bai Long 7e66297bf9 Merge pull request #91 from longbai/remove-transform
remove transform
2014-05-30 19:59:32 +08:00
longbai ba91ee2377 remove transform 2014-05-30 18:44:04 +08:00
Liang Tao a70b6f5313 添加list接口。 2014-05-05 20:55:23 +08:00
Liang Tao 417b717bc5 去除未公开的参数。 2014-05-05 16:44:36 +08:00
Bai Long 5d07bc517c Merge pull request #90 from BluntBlade/master
去除已废弃的publish/unpublish接口。
2014-04-20 14:29:46 +08:00
Liang Tao ad579f402b 添加更新日志。 2014-04-20 09:29:01 +08:00
Liang Tao 34fc65bd99 去除已废弃的publish/unpublish接口。 2014-04-20 09:25:15 +08:00
Bai Long ecbeb51339 Merge pull request #86 from BluntBlade/master
添加pfop相关SDK内容。
2014-04-14 15:15:09 +08:00
Liang Tao ef0d79eb17 去掉不常见的Ruby版本,只测试必要的几个。 2014-04-08 14:05:00 +08:00
Liang Tao edc86e230e Merge branch 'http.renew' 2014-04-08 12:50:34 +08:00
Liang Tao 5718b720df 添加更多Debug日志以便追踪错误。 2014-04-08 12:50:28 +08:00
Liang Tao 5cc4db2231 添加pfop相关SDK内容。 2014-04-06 11:47:04 +08:00
34 changed files with 697 additions and 221 deletions
+1 -1
View File
@@ -1 +1 @@
--colour -f nested
--colour -f documentation
+5 -6
View File
@@ -1,13 +1,12 @@
language: ruby
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- 2.0.0
- 2.1.1
- jruby-18mode
- jruby-19mode
- ree
before_script:
- export QINIU_ACCESS_KEY=LGRqJsjX7LAvtdtX6hhyxs861lS57HwnOQmJsOuX
- export QINIU_SECRET_KEY=g_OxhuN5iJ1O7BoA6YdXyF6zSszk34UZFKDfdIIW
- export QINIU_ACCESS_KEY=QWYn5TFQsLLU1pL5MFEmX3s5DmHdUThav9WyOWOm
- export QINIU_SECRET_KEY=Bxckh6FA-Fbs9Yt3i3cbKVK22UPBmAOHJcL95pGz
gemfile:
- Gemfile
- rails3/Gemfile
+53
View File
@@ -1,5 +1,58 @@
## CHANGE LOG
### V6.5.1
- 为 Qiniu::Auth 添加验证七牛回调请求签名合法性的函数。[https://github.com/qiniu/ruby-sdk/pull/133](https://github.com/qiniu/ruby-sdk/pull/133)
### v6.5.0
- 为 Qiniu::Auth 添加一个异常处理逻辑,在 Access Key 和 Secret Key 未正常设置(nil 值)的情况下给出正确提示。[https://github.com/qiniu/ruby-sdk/pull/126](https://github.com/qiniu/ruby-sdk/pull/126)
### v6.4.2
- gem 兼容性调整 。 [https://github.com/qiniu/ruby-sdk/pull/122](https://github.com/qiniu/ruby-sdk/pull/122)
- 上传策略参数调整 。 [https://github.com/qiniu/ruby-sdk/pull/120](https://github.com/qiniu/ruby-sdk/pull/120)
### v6.4.1
- 将 mime-types 的依赖版本升级到 2.4.3 。 [https://github.com/qiniu/ruby-sdk/pull/113](https://github.com/qiniu/ruby-sdk/pull/113)
### v6.4.0
- 为 put_with_put_policy() 添加 opts 参数,允许使用 :content_type 键指定上传文件的 mime type。 [https://github.com/qiniu/ruby-sdk/pull/111](https://github.com/qiniu/ruby-sdk/pull/111)
### v6.3.2
- 调整上传host。 [https://github.com/qiniu/ruby-sdk/pull/103](https://github.com/qiniu/ruby-sdk/pull/103)
### v6.3.1
- 为过期方法添加说明。 [https://github.com/qiniu/ruby-sdk/pull/98](https://github.com/qiniu/ruby-sdk/pull/98)
- 修改上传域名。 [https://github.com/qiniu/ruby-sdk/pull/99](https://github.com/qiniu/ruby-sdk/pull/99)
- 增加pfop参数。 [https://github.com/qiniu/ruby-sdk/pull/100](https://github.com/qiniu/ruby-sdk/pull/100)
### v6.3.0
- 添加 authorize_download_url_2 方法,对包含中文或其它 utf-8 字符的 Key 做下载授权。 [https://github.com/qiniu/ruby-sdk/pull/95](https://github.com/qiniu/ruby-sdk/pull/95)
### v6.2.4
- 调整User Agent。 [https://github.com/qiniu/ruby-sdk/pull/94](https://github.com/qiniu/ruby-sdk/pull/94)
### v6.2.3
- 为上传策略添加`persistentPipeline`参数,用于指明使用哪个命名转码队列。 [https://github.com/qiniu/ruby-sdk/pull/93](https://github.com/qiniu/ruby-sdk/pull/93)
### v6.2.2
- 为/pfop接口添加`pipeline`参数,用于指明使用哪个命名转码队列。 [https://github.com/qiniu/ruby-sdk/pull/92](https://github.com/qiniu/ruby-sdk/pull/92)
- 为authorize_download_url()添加`:fop`参数,用于生成含数据处理指令的授权下载URL。
### v6.2.1
- 去除已废弃的publish/unpublish接口。 [https://github.com/qiniu/ruby-sdk/pull/90](https://github.com/qiniu/ruby-sdk/pull/90) (#8143)
### v6.2.0
- 重写与授权相关的函数并归入Qiniu::Auth空间,原授权凭证生成类维持不变。
+2 -2
View File
@@ -1,7 +1,7 @@
source 'https://rubygems.org'
# Specify your gem's dependencies in qiniu-s3.gemspec
gemspec
# Specify your gem's dependencies in qiniu.gemspec
gemspec :name => 'qiniu'
# platforms :jruby do
# gem "jruby-openssl"
+24 -17
View File
@@ -1,30 +1,37 @@
PATH
remote: .
specs:
qiniu (6.2.0)
json (~> 1.7)
qiniu (6.5.1)
json (~> 1.8)
mime-types (~> 1.19)
rest-client (~> 1.6)
rest-client (~> 1.7.3)
ruby-hmac (~> 0.4)
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.1.3)
diff-lcs (1.2.5)
fakeweb (1.3.0)
json (1.8.1)
mime-types (1.23)
rake (10.0.3)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec (2.12.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.12.0)
rspec-core (2.12.2)
rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.2)
json (1.8.2)
mime-types (1.25.1)
netrc (0.10.3)
rake (10.4.2)
rest-client (1.7.3)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
rspec (3.2.0)
rspec-core (~> 3.2.0)
rspec-expectations (~> 3.2.0)
rspec-mocks (~> 3.2.0)
rspec-core (3.2.2)
rspec-support (~> 3.2.0)
rspec-expectations (3.2.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.2.0)
rspec-mocks (3.2.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.2.0)
rspec-support (3.2.2)
ruby-hmac (0.4.0)
PLATFORMS
+2 -2
View File
@@ -2,7 +2,7 @@
## 关于
此 Ruby SDK 适用于 Ruby 1.8.x, 1.9.x, 2.0.x, jruby, rbx, ree 版本,基于 [七牛云存储官方API](http://developer.qiniu.com/docs/v6/index.html) 构建。使用此 SDK 构建您的网络应用程序,能让您以非常便捷地方式将数据安全地存储到七牛云存储上。无论您的网络应用是一个网站程序,还是包括从云端(服务端程序)到终端(手持设备应用)的架构的服务或应用,通过七牛云存储及其 SDK,都能让您应用程序的终端用户高速上传和下载,同时也让您的服务端更加轻盈。
此 Ruby SDK 适用于 Ruby 1.9.x, 2.0.x, 2.1.x, jruby版本,基于 [七牛云存储官方API](http://developer.qiniu.com/docs/v6/index.html) 构建。使用此 SDK 构建您的网络应用程序,能让您以非常便捷地方式将数据安全地存储到七牛云存储上。无论您的网络应用是一个网站程序,还是包括从云端(服务端程序)到终端(手持设备应用)的架构的服务或应用,通过七牛云存储及其 SDK,都能让您应用程序的终端用户高速上传和下载,同时也让您的服务端更加轻盈。
## 状态
@@ -15,7 +15,7 @@
在您 Ruby 应用程序的 `Gemfile` 文件中,添加如下一行代码:
gem 'qiniu', '~> 6.1.0'
gem 'qiniu', '~> 6.4.1'
然后,在应用程序所在的目录下,可以运行 `bundle` 安装依赖包:
+1 -12
View File
@@ -64,12 +64,11 @@ module Qiniu
opts[:enable_resumable_upload] = true unless opts.has_key?(:enable_resumable_upload)
if opts[:enable_resumable_upload] && File::size(source_file) > Config.settings[:block_size]
code, data, raw_headers = Storage.upload_with_token(opts[:uptoken],
code, data, raw_headers = Storage.resumable_upload_with_token(opts[:uptoken],
opts[:file],
opts[:bucket],
opts[:key],
opts[:mime_type],
opts[:note],
opts[:customer],
opts[:callback_params],
opts[:rotate])
@@ -156,16 +155,6 @@ module Qiniu
code == StatusOK ? data : false
end
def publish(domain, bucket)
code, data = Storage.publish(domain, bucket)
code == StatusOK
end
def unpublish(domain)
code, data = Storage.unpublish(domain)
code == StatusOK
end
def drop(bucket)
code, data = Storage.drop(bucket)
code == StatusOK
+46
View File
@@ -0,0 +1,46 @@
# -*- encoding: utf-8 -*-
# vim: sw=2 ts=2
require 'uri'
module Qiniu
module ADT
class ApiSpecification
public
def to_str; return ""; end
end # class ApiSpecification
module Policy
public
def to_json
args = {}
self.params.each_pair do |key, fld|
val = self.__send__(key)
if !val.nil? then
args[fld] = val
end
end
return args.to_json
end # to_json
def to_query_string
args = []
self.params.each_pair do |key, fld|
val = self.__send__(key)
if !val.nil? then
new_fld = CGI.escape(fld.to_s)
new_val = CGI.escape(val.to_s).gsub('+', '%20')
args.push("#{new_fld}=#{new_val}")
end
end
return args.join("&")
end # to_query_string
end # module Policy
end # module ADT
end # module Qiniu
+83 -20
View File
@@ -3,6 +3,7 @@
require 'hmac-sha1'
require 'uri'
require 'cgi'
require 'qiniu/exceptions'
@@ -24,6 +25,18 @@ module Qiniu
# 默认授权期1小时
return Time.now.to_i + DEFAULT_AUTH_SECONDS
end # calculate_deadline
def calculate_hmac_sha1_digest(sk, str)
begin
sign = HMAC::SHA1.new(sk).update(str).digest
rescue RuntimeError => e
raise RuntimeError, "Please set Qiniu's access_key and secret_key before authorize any tokens."
rescue
raise
else
return sign
end
end
end # class << self
class PutPolicy
@@ -48,18 +61,20 @@ module Qiniu
:return_url => "returnUrl" ,
:return_body => "returnBody" ,
:callback_url => "callbackUrl" ,
:callback_host => "callbackHost" ,
:callback_body => "callbackBody" ,
:callback_body_type => "callbackBodyType" ,
:persistent_ops => "persistentOps" ,
:persistent_notify_url => "persistentNotifyUrl" ,
:transform => "transform" ,
:persistent_pipeline => "persistentPipeline" ,
# 数值类型参数
:deadline => "deadline" ,
:insert_only => "insertOnly" ,
:fsize_limit => "fsizeLimit" ,
:callback_fetch_key => "callbackFetchKey" ,
:detect_mime => "detectMime" ,
:mime_limit => "mimeLimit" ,
:fop_timeout => "fopTimeout"
:mime_limit => "mimeLimit"
} # PARAMS
public
@@ -140,20 +155,33 @@ module Qiniu
access_key = Config.settings[:access_key]
secret_key = Config.settings[:secret_key]
download_url = url
### URL变换:追加FOP指令
if args[:fop].is_a?(String) && args[:fop] != '' then
if download_url.index('?').is_a?(Fixnum) then
# 已有参数
download_url = "#{download_url}&#{args[:fop]}"
else
# 尚无参数
download_url = "#{download_url}?#{args[:fop]}"
end
end
### 授权期计算
e = Auth.calculate_deadline(args[:expires_in], args[:deadline])
### URL变换:追加授权期参数
if url.index('?').is_a?(Fixnum) then
if download_url.index('?').is_a?(Fixnum) then
# 已有参数
download_url = "#{url}&e=#{e}"
download_url = "#{download_url}&e=#{e}"
else
# 尚无参数
download_url = "#{url}?e=#{e}"
download_url = "#{download_url}?e=#{e}"
end
### 生成数字签名
sign = HMAC::SHA1.new(secret_key).update(download_url).digest
sign = calculate_hmac_sha1_digest(secret_key, download_url)
encoded_sign = Utils.urlsafe_base64_encode(sign)
### 生成下载授权凭证
@@ -163,11 +191,22 @@ module Qiniu
return "#{download_url}&token=#{dntoken}"
end # authorize_download_url
def generate_acctoken(url, body = '')
### 提取AK/SK信息
access_key = Config.settings[:access_key]
secret_key = Config.settings[:secret_key]
### 对包含中文或其它 utf-8 字符的 Key 做下载授权
def authorize_download_url_2(domain, key, args = EMPTY_ARGS)
url_encoded_key = CGI::escape(key)
schema = args[:schema] || "http"
port = args[:port]
if port.nil? then
download_url = "#{schema}://#{domain}/#{url_encoded_key}"
else
download_url = "#{schema}://#{domain}:#{port}/#{url_encoded_key}"
end
return authorize_download_url(download_url, args)
end # authorize_download_url_2
def generate_acctoken_sign_with_mac(access_key, secret_key, url, body)
### 解析URL,生成待签名字符串
uri = URI.parse(url)
signing_str = uri.path
@@ -184,18 +223,17 @@ module Qiniu
# 如果有Body,则也加上
# (仅限于mime == "application/x-www-form-urlencoded"的情况)
if body.is_a?(String) && !body.empty?
signing_str += body
signing_str += body
end
### 生成数字签名
sign = HMAC::SHA1.new(secret_key).update(signing_str).digest
encoded_sign = Utils.urlsafe_base64_encode(sign)
sign = calculate_hmac_sha1_digest(secret_key, signing_str)
return Utils.urlsafe_base64_encode(sign)
end # generate_acctoken_sign_with_mac
### 生成管理授权凭证
acctoken = "#{access_key}:#{encoded_sign}"
### 返回管理授权凭证
return acctoken
def generate_acctoken(url, body = '')
encoded_sign = generate_acctoken_sign_with_mac(Config.settings[:access_key], Config.settings[:secret_key], url, body)
return "#{Config.settings[:access_key]}:#{encoded_sign}"
end # generate_acctoken
def generate_uptoken(put_policy)
@@ -207,7 +245,7 @@ module Qiniu
encoded_put_policy = Utils.urlsafe_base64_encode(put_policy.to_json)
### 生成数字签名
sign = HMAC::SHA1.new(secret_key).update(encoded_put_policy).digest
sign = calculate_hmac_sha1_digest(secret_key, encoded_put_policy)
encoded_sign = Utils.urlsafe_base64_encode(sign)
### 生成上传授权凭证
@@ -216,6 +254,31 @@ module Qiniu
### 返回上传授权凭证
return uptoken
end # generate_uptoken
def authenticate_callback_request(auth_str, url, body = '')
### 提取AK/SK信息
access_key = Config.settings[:access_key]
secret_key = Config.settings[:secret_key]
### 检查签名格式
ak_pos = auth_str.index(access_key)
if ak_pos.nil? then
return false
end
colon_pos = auth_str.index(':', ak_pos + 1)
if colon_pos.nil? || ((ak_pos + access_key.length) != colon_pos) then
return false
end
encoded_sign = generate_acctoken_sign_with_mac(access_key, secret_key, url, body)
sign_pos = auth_str.index(encoded_sign, colon_pos + 1)
if sign_pos.nil? || ((sign_pos + encoded_sign.length) != auth_str.length) then
return false
end
return true
end # authenticate_callback_request
end # class << self
end # module Auth
+6 -6
View File
@@ -15,16 +15,15 @@ module Qiniu
class << self
DEFAULT_OPTIONS = {
:user_agent => 'Qiniu-RS-Ruby-SDK-' + Version.to_s + '()',
:user_agent => 'QiniuRuby/' + Version.to_s + ' ('+RUBY_PLATFORM+')' + ' Ruby/'+ RUBY_VERSION,
:method => :post,
:content_type => 'application/x-www-form-urlencoded',
:auth_url => "https://acc.qbox.me/oauth2/token",
:rs_host => "http://rs.qiniu.com",
:rsf_host => "http://rsf.qbox.me",
:up_host => "http://up.qiniu.com",
:pub_host => "http://pu.qbox.me:10200",
:eu_host => "http://eu.qbox.me",
:client_id => "a75604760c4da4caaa456c0c5895c061c3065c5a",
:client_secret => "75df554a39f58accb7eb293b550fa59618674b7d",
:access_key => "",
:secret_key => "",
:auto_reconnect => true,
@@ -32,16 +31,17 @@ module Qiniu
:block_size => 1024*1024*4,
:chunk_size => 1024*256,
:enable_debug => true,
:tmpdir => Dir.tmpdir + File::SEPARATOR + 'Qiniu-RS-Ruby-SDK'
:tmpdir => Dir.tmpdir + File::SEPARATOR + 'QiniuRuby'
}
REQUIRED_OPTION_KEYS = [:access_key, :secret_key]
REQUIRED_OPTION_KEYS = [:access_key, :secret_key, :up_host]
attr_reader :settings, :default_params
def load config_file
if File.exist?(config_file)
config_options = YAML.load_file(config_file)
config_options.symbolize_keys!
initialize_connect(config_options)
else
raise MissingConfError, config_file
@@ -49,7 +49,7 @@ module Qiniu
end
def initialize_connect options = {}
@settings = DEFAULT_OPTIONS.merge(options)
@settings = DEFAULT_OPTIONS.merge!(options)
REQUIRED_OPTION_KEYS.each do |opt|
raise MissingArgsError, [opt] unless @settings.has_key?(opt)
end
+1
View File
@@ -1,3 +1,4 @@
# -*- encoding: utf-8 -*-
require 'qiniu/image'
require 'qiniu/pfop'
+10 -2
View File
@@ -22,6 +22,7 @@ module Qiniu
def get (url, opts = {})
### 配置请求Header
req_headers = {
:connection => 'close',
:accept => '*/*',
:user_agent => Config.settings[:user_agent]
}
@@ -36,6 +37,9 @@ module Qiniu
return response.code.to_i, response.body, response.raw_headers
rescue => e
Log.logger.warn "#{e.message} => Qiniu::HTTP.get('#{url}')"
if e.respond_to?(:response) && e.response.respond_to?(:code) then
return e.response.code, e.response.body, e.response.raw_headers
end
return nil, nil, nil
end # get
@@ -61,7 +65,7 @@ module Qiniu
end
content_type = resp_headers["content-type"][0]
if !content_type.nil? && content_type == API_RESULT_MIMETYPE then
if !content_type.nil? && !content_type.downcase.index(API_RESULT_MIMETYPE).nil? then
# 如果是JSON格式,则反序列化
resp_body = Utils.safe_json_parse(resp_body)
end
@@ -72,6 +76,7 @@ module Qiniu
def post (url, req_body = nil, opts = {})
### 配置请求Header
req_headers = {
:connection => 'close',
:accept => '*/*',
:user_agent => Config.settings[:user_agent]
}
@@ -86,6 +91,9 @@ module Qiniu
return response.code.to_i, response.body, response.raw_headers
rescue => e
Log.logger.warn "#{e.message} => Qiniu::HTTP.post('#{url}')"
if e.respond_to?(:response) && e.response.respond_to?(:code) then
return e.response.code, e.response.body, e.response.raw_headers
end
return nil, nil, nil
end # post
@@ -109,7 +117,7 @@ module Qiniu
end
content_type = resp_headers["content-type"][0]
if !content_type.nil? && content_type == API_RESULT_MIMETYPE then
if !content_type.nil? && !content_type.downcase.index(API_RESULT_MIMETYPE).nil? then
# 如果是JSON格式,则反序列化
resp_body = Utils.safe_json_parse(resp_body)
end
+62 -36
View File
@@ -1,10 +1,48 @@
# -*- encoding: utf-8 -*-
# vim: sw=2 ts=2
require 'qiniu/adt'
require 'qiniu/http'
module Qiniu
module Storage
class ListPolicy
include ADT::Policy
private
def initialize(bucket,
limit = 1000,
prefix = '',
delimiter = '')
@bucket = bucket
@limit = limit
@prefix = prefix
@delimiter = delimiter
end # initialize
public
PARAMS = {
# 字符串类型参数
:bucket => "bucket",
:prefix => "prefix",
:delimiter => "delimiter",
:marker => "marker",
# 数值类型参数
:limit => "limit"
} # PARAMS
PARAMS.each_pair do |key, fld|
attr_accessor key
end
def params
return PARAMS
end # params
alias :to_s :to_query_string
end # class ListPolicy
class << self
include Utils
@@ -14,22 +52,6 @@ module Qiniu
return HTTP.management_post(url)
end # buckets
PRIVATE_BUCKET = 0
PUBLIC_BUCKET = 1
def mkbucket(bucket_name, is_public = PUBLIC_BUCKET)
url = Config.settings[:rs_host] + '/mkbucket2/' + bucket_name + '/public/' + is_public.to_s
return HTTP.management_post(url)
end # mkbucket
def make_a_private_bucket(bucket_name)
return mkbucket(bucket_name, PRIVATE_BUCKET)
end # make_a_private_bucket
def make_a_public_bucket(bucket_name)
return mkbucket(bucket_name, PUBLIC_BUCKET)
end # make_a_public_bucket
def stat(bucket, key)
url = Config.settings[:rs_host] + '/stat/' + encode_entry_uri(bucket, key)
return HTTP.management_post(url)
@@ -60,23 +82,6 @@ module Qiniu
return HTTP.management_post(url)
end # delete
def publish(domain, bucket)
encoded_domain = Utils.urlsafe_base64_encode(domain)
url = Config.settings[:rs_host] + "/publish/#{encoded_domain}/from/#{bucket}"
return HTTP.management_post(url)
end # publish
def unpublish(domain)
encoded_domain = Utils.urlsafe_base64_encode(domain)
url = Config.settings[:rs_host] + "/unpublish/#{encoded_domain}"
return HTTP.management_post(url)
end # unpublish
def drop(bucket)
url = Config.settings[:rs_host] + "/drop/#{bucket}"
return HTTP.management_post(url)
end # drop
def batch(command, bucket, keys)
execs = []
keys.each do |key|
@@ -119,6 +124,26 @@ module Qiniu
save_as(bucket, key, source_image_url, mogrify_params_string)
end # image_mogrify_save_as
def list(list_policy)
url = Config.settings[:rsf_host] + '/list?' + list_policy.to_query_string()
resp_code, resp_body, resp_headers = HTTP.management_post(url)
if resp_code == 0 || resp_code > 299 then
has_more = false
return resp_code, resp_body, resp_headers, has_more, list_policy
end
has_more = (resp_body['marker'].is_a?(String) && resp_body['marker'] != '')
if has_more then
new_list_policy = list_policy.clone()
new_list_policy.marker = resp_body['marker']
else
new_list_policy = list_policy
end
return resp_code, resp_body, resp_headers, has_more, new_list_policy
end # list
private
def _generate_cp_or_mv_opstr(command, source_bucket, source_key, target_bucket, target_key)
@@ -129,12 +154,13 @@ module Qiniu
def _batch_cp_or_mv(command, *op_args)
execs = []
op_args.each do |e|
op_args.each do |e|
execs << 'op=' + _generate_cp_or_mv_opstr(command, e[0], e[1], e[2], e[3]) if e.size == 4
end
end
url = Config.settings[:rs_host] + "/batch"
return HTTP.management_post(url, execs.join("&"))
end # _batch_cp_or_mv
end
end # class << self
end # module Storage
end # module Qiniu
+2
View File
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-
require 'qiniu/http'
module Qiniu
module Misc
class << self
+124
View File
@@ -0,0 +1,124 @@
# -*- encoding: utf-8 -*-
# vim: sw=2 ts=2
require 'qiniu/adt'
require 'qiniu/http'
module Qiniu
module Fop
module Persistance
class PfopPolicy
include ADT::Policy
private
def initialize(bucket,
key,
fops,
notify_url)
@bucket = bucket
@key = key
@notify_url = notify_url
self.fops!(fops)
end # initialize
public
PARAMS = {
# 字符串类型参数
:bucket => "bucket",
:key => "key",
:fops => "fops",
:notify_url => "notifyURL",
:pipeline => "pipeline",
# 数值类型参数
:force => "force"
} # PARAMS
PARAMS.each_pair do |key, fld|
attr_accessor key
end
def params
return PARAMS
end # params
def fops! (fops)
if fops.is_a?(Hash) then
fops = fops.values
end
if fops.is_a?(Array) then
new_fops = []
fops.each do |v|
if v.is_a?(ApiSpecification) then
new_fops.push(v.to_s)
end
end
@fops = new_fops.join(";")
else
@fops = fops.to_s
end
end # fops!
def force!
@force = 1
end # force!
alias :to_s :to_json
end # class PfopPolicy
class << self
API_HOST = 'http://api.qiniu.com'
PFOP_URL = API_HOST + '/pfop/'
def pfop (args)
### 生成fop指令串
if args.is_a?(PfopPolicy) then
# PfopPolicy的各个字段按固定顺序组织
body = args.to_query_string()
elsif args.is_a?(Hash) then
# 无法保证固定字段顺序
body = HTTP.generate_query_string(args)
else
# 由调用者保证固定字段顺序
body = args.to_s
end
### 发送请求
return HTTP.management_post(PFOP_URL, body)
end # pfop
PREFOP_URL = API_HOST + '/status/get/prefop?id='
def prefop (persistent_id)
### 抽取persistentId
if persistent_id.is_a?(Hash) then
pid = persistent_id['persistentId']
else
pid = persistent_id.to_s
end
### 发送请求
url = PREFOP_URL + pid
return HTTP.api_get(url)
end # prefop
def generate_p1_url (url, fop)
# 如果fop是ApiSpecification,则各字段按固定顺序组织,保证一致性
# 否则由调用者保证固定字段顺序
fop = CGI.escape(fop.to_s).gsub('+', '%20')
### 生成url
return url + '?p/1/' + fop
end # generate_pl_url
end # class << self
end # module Persistance
end # module Fop
end # module Qiniu
+17 -8
View File
@@ -106,14 +106,14 @@ module Qiniu
options[:headers][:content_type] = content_type
end
code, data = HTTP.api_post(url, data, options)
code, data, raw_headers = HTTP.api_post(url, data, options)
unless HTTP.is_response_ok?(code)
retry_times += 1
if Config.settings[:auto_reconnect] && retry_times < Config.settings[:max_retry_times]
return _call_binary_with_token(uptoken, url, data, options[:content_type], retry_times)
end
end
[code, data]
return code, data, raw_headers
end # _call_binary_with_token
def _mkblock(uptoken, block_size, body)
@@ -150,7 +150,10 @@ module Qiniu
if result_length != body_length
raise FileSeekReadError.new(fpath, block_index, seek_pos, body_length, result_length)
end
code, data = _mkblock(uptoken, block_size, body)
code, data, raw_headers = _mkblock(uptoken, block_size, body)
Utils.debug "Mkblk : #{code.inspect} #{data.inspect} #{raw_headers.inspect}"
body_crc32 = Zlib.crc32(body)
if HTTP.is_response_ok?(code) && data["crc32"] == body_crc32
progress[:ctx] = data["ctx"]
@@ -164,6 +167,7 @@ module Qiniu
break
elsif i == retry_times && data["crc32"] != body_crc32
Log.logger.error %Q(Uploading block error. Expected crc32: #{body_crc32}, but got: #{data["crc32"]})
return code, data, raw_headers
end
end
elsif progress[:offset] + progress[:restsize] != block_size
@@ -181,7 +185,10 @@ module Qiniu
if result_length != body_length
raise FileSeekReadError.new(fpath, block_index, seek_pos, body_length, result_length)
end
code, data = _putblock(progress[:host], uptoken, progress[:ctx], progress[:offset], body)
code, data, raw_headers = _putblock(progress[:host], uptoken, progress[:ctx], progress[:offset], body)
Utils.debug "Bput : #{code.inspect} #{data.inspect} #{raw_headers.inspect}"
body_crc32 = Zlib.crc32(body)
if HTTP.is_response_ok?(code) && data["crc32"] == body_crc32
progress[:ctx] = data["ctx"]
@@ -195,11 +202,12 @@ module Qiniu
break
elsif i == retry_times && data["crc32"] != body_crc32
Log.logger.error %Q(Uploading block error. Expected crc32: #{body_crc32}, but got: #{data["crc32"]})
return code, data, raw_headers
end
end
end
# return
return [code, data]
return code, data, raw_headers
end # _resumable_put_block
def _block_count(fsize)
@@ -291,19 +299,20 @@ module Qiniu
checksums = []
block_count.times{checksums << ''}
code, data = _resumable_put(uptoken, fh, checksums, progresses, block_notifier, chunk_notifier)
code, data, raw_headers = _resumable_put(uptoken, fh, checksums, progresses, block_notifier, chunk_notifier)
if HTTP.is_response_ok?(code)
uphost = data["host"]
entry_uri = bucket + ':' + key
code, data = _mkfile(uphost, uptoken, entry_uri, fsize, checksums, mime_type, custom_meta, customer, callback_params, rotate)
code, data, raw_headers = _mkfile(uphost, uptoken, entry_uri, fsize, checksums, mime_type, custom_meta, customer, callback_params, rotate)
Utils.debug "Mkfile : #{code.inspect} #{data.inspect} #{raw_headers.inspect}"
end
if HTTP.is_response_ok?(code)
Utils.debug "File #{fh.path} {size: #{fsize}} successfully uploaded."
end
[code, data]
return code, data, raw_headers
end # _resumable_upload
end # self class
end # module Storage
+2
View File
@@ -4,6 +4,8 @@ require 'hmac-sha1'
require 'qiniu/config'
require 'qiniu/utils'
### AccessToken 类已经过时,请改用 Qiniu::Auth.generate_acctoken 方法 ###
module Qiniu
class AccessToken
+3
View File
@@ -4,6 +4,9 @@ require 'json'
require 'qiniu/tokens/access_token'
require 'qiniu/utils'
### DownloadToken 类已经过时,请改用 Qiniu::Auth.authorize_download_url 方法 ###
### 或 Qiniu::Auth.authorize_download_url_2 方法 ###
module Qiniu
class DownloadToken < AccessToken
+10 -2
View File
@@ -4,6 +4,8 @@ require 'json'
require 'qiniu/tokens/access_token'
require 'qiniu/utils'
### UploadToken 类已经过时,请改用 Qiniu::Auth.generate_uptoken 方法 ###
module Qiniu
class UploadToken < AccessToken
@@ -19,7 +21,9 @@ module Qiniu
@callback_body_type = opts[:callback_body_type]
@customer = opts[:customer]
@escape = opts[:escape]
@async_options = opts[:async_options]
@persistent_ops = opts[:persistent_ops]
@persistent_notify_url = opts[:persistent_notify_url]
@persistent_pipeline = opts[:persistent_pipeline]
@return_body = opts[:return_body]
@return_url = opts[:return_url]
end
@@ -31,9 +35,13 @@ module Qiniu
params[:callbackBodyType] = @callback_body_type if !@callback_body_type.nil? && !@callback_body_type.empty?
params[:customer] = @customer if !@customer.nil? && !@customer.empty?
params[:escape] = 1 if @escape == 1 || @escape == true
params[:asyncOps] = @async_options if !@async_options.nil? && !@async_options.empty?
params[:returnBody] = @return_body if !@return_body.nil? && !@return_body.empty?
params[:returnUrl] = @return_url if !@return_url.nil? && !@return_url.empty?
params[:persistentOps] = @persistent_ops if !@persistent_ops.nil? && !@persistent_ops.empty?
params[:persistentNotifyUrl] = @persistent_notify_url if !@persistent_notify_url.nil? && !@persistent_notify_url.empty?
params[:persistentPipeline] = @persistent_pipeline if !@persistent_pipeline.nil? && !@persistent_pipeline.empty?
Utils.urlsafe_base64_encode(params.to_json)
end
Executable → Regular
+13 -4
View File
@@ -47,15 +47,23 @@ module Qiniu
def upload_with_token_2(uptoken,
local_file,
key = nil,
x_vars = nil)
x_vars = nil,
opts = {})
### 构造URL
url = Config.settings[:up_host]
url[/\/*$/] = ''
url += '/'
### 构造HTTP Body
file = File.new(local_file, 'rb')
if not opts[:content_type].nil?
file.define_singleton_method("content_type") do
opts[:content_type]
end
end
post_data = {
:file => File.new(local_file, 'rb'),
:file => file,
:multipart => true,
}
if not uptoken.nil?
@@ -84,13 +92,14 @@ module Qiniu
def upload_with_put_policy(put_policy,
local_file,
key = nil,
x_vars = nil)
x_vars = nil,
opts = {})
uptoken = Auth.generate_uptoken(put_policy)
if key.nil? then
key = put_policy.key
end
return upload_with_token_2(uptoken, local_file, key, x_vars)
return upload_with_token_2(uptoken, local_file, key, x_vars, opts)
end # upload_with_put_policy
private
+2 -2
View File
@@ -3,8 +3,8 @@
module Qiniu
module Version
MAJOR = 6
MINOR = 2
PATCH = 0
MINOR = 5
PATCH = 1
# Returns a version string by joining <tt>MAJOR</tt>, <tt>MINOR</tt>, and <tt>PATCH</tt> with <tt>'.'</tt>
#
# Example
+3 -3
View File
@@ -21,9 +21,9 @@ Gem::Specification.new do |gem|
gem.add_development_dependency "rake", ">= 0.9"
gem.add_development_dependency "rspec", ">= 2.11"
gem.add_development_dependency "fakeweb", "~> 1.3"
gem.add_runtime_dependency "json", "~> 1.7"
gem.add_runtime_dependency "rest-client", "~> 1.6"
gem.add_runtime_dependency "mime-types", "~> 1.19"
gem.add_runtime_dependency "json", "~> 1.8"
gem.add_runtime_dependency "rest-client", "~> 1.7.3"
gem.add_runtime_dependency "mime-types", "~> 2.4.3"
gem.add_runtime_dependency "ruby-hmac", "~> 0.4"
gem.add_runtime_dependency "jruby-openssl", "~> 0.7" if RUBY_PLATFORM == "java"
end
Executable
+4
View File
@@ -0,0 +1,4 @@
source 'https://rubygems.org'
# Specify your gem's dependencies in rails3/qiniu.gemspec
gemspec :name => 'qiniu'
+29
View File
@@ -0,0 +1,29 @@
# -*- encoding: utf-8 -*-
require File.expand_path('../../lib/qiniu/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ["why404","BluntBlade"]
gem.email = ["sdk@qiniu.com"]
gem.description = %q{Qiniu Resource (Cloud) Storage SDK for Ruby. See: http://developer.qiniu.com/docs/v6/sdk/ruby-sdk.html}
gem.summary = %q{Qiniu Resource (Cloud) Storage SDK for Ruby}
gem.homepage = "https://github.com/qiniu/ruby-sdk"
gem.files = `git ls-files`.split($\)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.name = "qiniu"
gem.require_paths = ["lib"]
gem.version = Qiniu::Version.to_s
gem.license = "MIT"
# specify any dependencies here; for example:
gem.add_development_dependency "rake", ">= 0.9"
gem.add_development_dependency "rspec", ">= 2.11"
gem.add_development_dependency "fakeweb", "~> 1.3"
gem.add_runtime_dependency "json", "~> 1.8"
gem.add_runtime_dependency "rest-client", "~> 1.7.3"
gem.add_runtime_dependency "mime-types", "~> 1.19"
gem.add_runtime_dependency "ruby-hmac", "~> 0.4"
gem.add_runtime_dependency "jruby-openssl", "~> 0.7" if RUBY_PLATFORM == "java"
end
+65 -12
View File
@@ -1,25 +1,20 @@
# -*- encoding: utf-8 -*-
# vim: sw=2 ts=2
require 'spec_helper'
require 'qiniu/auth'
require 'qiniu/config'
require 'qiniu/storage'
require 'digest/sha1'
module Qiniu
module Auth
module Auth
describe Auth do
before :all do
@bucket = 'RubySDK-Test-Private'
@bucket = make_unique_bucket(@bucket)
### 尝试创建Bucket
result = Qiniu::Storage.make_a_private_bucket(@bucket)
puts result.inspect
@bucket = 'rubysdk'
end
after :all do
### 不删除Bucket以备下次使用
end
### 测试私有资源下载
@@ -56,7 +51,12 @@ module Qiniu
result.body.should_not be_empty
### 授权下载地址(带参数)
download_url = Qiniu::Auth.authorize_download_url(url + '?download/a.m3u8')
download_url = Qiniu::Auth.authorize_download_url(
url,
{
:fop => 'download/a.m3u8'
}
)
puts "download_url=#{download_url}"
result = RestClient.get(download_url)
@@ -69,7 +69,60 @@ module Qiniu
puts data.inspect
end
end
end
end # module Storage
### 测试回调签名
context ".authenticate_callback_request" do
it "should works" do
url = '/test.php'
body = 'name=xxx&size=1234'
false.should == Qiniu::Auth.authenticate_callback_request('ABCD', url, body)
false.should == Qiniu::Auth.authenticate_callback_request(Config.settings[:access_key], url, body)
false.should == Qiniu::Auth.authenticate_callback_request('QBox ' + Config.settings[:access_key] + ':', url, body)
false.should == Qiniu::Auth.authenticate_callback_request('QBox ' + Config.settings[:access_key] + ':????', url, body)
acctoken = Qiniu::Auth.generate_acctoken(url, body)
auth_str = 'QBox ' + acctoken
false.should == Qiniu::Auth.authenticate_callback_request(auth_str + ' ', url, body)
true.should == Qiniu::Auth.authenticate_callback_request(auth_str, url, body)
true.should == Qiniu::Auth.authenticate_callback_request(acctoken, url, body)
end
end
end # module Auth
module Exception_Auth
describe Exception_Auth, :not_set_ak_sk => true do
### 测试未设置 ak/sk 的异常抛出情况
context ".not_set_ak_sk" do
it "should works" do
puts Qiniu::Config.instance_variable_get("@settings").inspect
begin
uptoken = Qiniu::Auth.generate_uptoken({})
rescue => e
e.message.should == "Please set Qiniu's access_key and secret_key before authorize any tokens."
else
fail "Not raise any exception."
end
begin
download_url = Qiniu::Auth.authorize_download_url("http://test.qiniudn.com/a_private_file")
rescue => e
e.message.should == "Please set Qiniu's access_key and secret_key before authorize any tokens."
else
fail "Not raise any exception."
end
begin
acctoken = Qiniu::Auth.generate_acctoken("http://rsf.qbox.me/list")
rescue => e
e.message.should == "Please set Qiniu's access_key and secret_key before authorize any tokens."
else
fail "Not raise any exception."
end
end
end
end
end # module Exception_Auth
end # module Qiniu
+8 -13
View File
@@ -10,15 +10,7 @@ module Qiniu
describe Fop do
before :all do
### 复用RubySDK-Test-Storage空间
@bucket = 'RubySDK-Test-Storage'
@bucket = make_unique_bucket(@bucket)
### 尝试创建空间
result = Qiniu.mkbucket(@bucket)
puts result.inspect
@bucket = 'rubysdk'
pic_fname = "image_logo_for_test.png"
@key = make_unique_key_in_bucket(pic_fname)
@@ -57,7 +49,6 @@ module Qiniu
end
after :all do
### 不删除Bucket以备下次使用
end
context ".info" do
@@ -68,14 +59,18 @@ module Qiniu
end
end
=begin
context ".exif" do
it "should works" do
code, data = Qiniu::Fop::Image.exif(@source_image_url)
result = Qiniu.get(@bucket, 'gogopher.jpg')
result["url"].should_not be_empty
puts result.inspect
code, data, headers = Qiniu::Fop::Image.exif(result["url"])
code.should == 200
puts data.inspect
puts headers.inspect
end
end
=end
context ".mogrify_preview_url" do
it "should works" do
+1 -7
View File
@@ -12,12 +12,7 @@ module Qiniu
describe Storage do
before :all do
@bucket = 'RubySDK-Test-Management'
@bucket = make_unique_bucket(@bucket)
### 尝试创建Bucket
result = Qiniu.mkbucket(@bucket)
puts result.inspect
@bucket = 'rubysdk'
@key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s)
@key = make_unique_key_in_bucket(@key)
@@ -26,7 +21,6 @@ module Qiniu
end
after :all do
### 不删除Bucket以备下次使用
end
### 准备数据
+1 -7
View File
@@ -10,16 +10,10 @@ module Qiniu
describe Misc do
before :all do
### 复用RubySDK-Test-Management空间
@bucket = 'RubySDK-Test-Management'
@bucket = make_unique_bucket(@bucket)
result = Qiniu.mkbucket(@bucket)
puts result.inspect
@bucket = 'rubysdk'
end
after :all do
### 不删除Bucket以备下次使用
end
context ".set_protected" do
+80
View File
@@ -0,0 +1,80 @@
# -*- encoding: utf-8 -*-
# vim: sw=2 ts=2
require 'spec_helper'
require 'qiniu/auth'
require 'qiniu'
require 'qiniu/fop'
module Qiniu
module Fop
module Persistance
describe Persistance do
before :all do
@bucket = 'rubysdk'
pic_fname = "image_logo_for_test.png"
@key = make_unique_key_in_bucket(pic_fname)
local_file = File.expand_path('../' + pic_fname, __FILE__)
### 检查测试文件存在性
code, body, headers = Qiniu::Storage.stat(@bucket, @key)
if code == 404 || code == 612 then
# 文件不存在,尝试上传
pp = Qiniu::Auth.PutPolicy.new(@bucket, @key)
code, body, headers = Qiniu::Storage.upload_with_put_policy(
pp,
local_file
)
puts "Put a test file for Persistance cases"
puts code.inspect
puts body.inspect
puts header.inspect
end
end
after :all do
end
context ".pfop" do
it "should works" do
pp = Persistance::PfopPolicy.new(
@bucket,
@key,
'imageView2/1/w/80/h/80', # fops
'www.baidu.com' # notify_url
)
code, data, headers = Qiniu::Fop::Persistance.pfop(pp)
code.should == 200
puts data.inspect
end
end
context ".prefop" do
it "should works" do
code, data, headers = Qiniu::Fop::Persistance.prefop('fakePersistentId')
code.should == 612
puts code.inspect
puts data.inspect
puts headers.inspect
end
end
context ".p1" do
it "should works" do
url = 'http://fake.qiniudn.com/fake.jpg'
fop = 'imageView2/1/w/80/h/80'
target_url = "#{url}?p/1/#{CGI.escape(fop).gsub('+', '%20')}"
p1_url = Qiniu::Fop::Persistance.generate_p1_url(url, fop)
p1_url.should == target_url
puts p1_url.inspect
end
end
end
end # module Persistance
end # module Fop
end # module Qiniu
+27 -45
View File
@@ -9,15 +9,10 @@ module Qiniu
describe Qiniu do
before :all do
@bucket = 'RubySDK-Test'
@bucket = make_unique_bucket(@bucket)
@bucket = 'rubysdk'
@test_image_bucket = @bucket
### 尝试创建Bucket
result = Qiniu.mkbucket(@bucket)
puts result.inspect
@key = Digest::SHA1.hexdigest Time.now.to_s
@key = make_unique_key_in_bucket(@key)
@@ -34,13 +29,12 @@ module Qiniu
end
after :all do
### 不删除Bucket以备下次使用
end
context ".buckets" do
it "should works" do
result = Qiniu.buckets
result.should_not be_false
expect(result).to_not be_empty
puts result.inspect
end
end
@@ -48,7 +42,7 @@ module Qiniu
context ".set_protected" do
it "should works" do
result = Qiniu.set_protected(@bucket, 1)
result.should_not be_false
expect(result).to eq(true)
puts result.inspect
end
end
@@ -56,7 +50,7 @@ module Qiniu
context ".set_separator" do
it "should works" do
result = Qiniu.set_separator(@bucket, "-")
result.should_not be_false
expect(result).to eq(true)
puts result.inspect
end
end
@@ -64,7 +58,7 @@ module Qiniu
context ".set_style" do
it "should works" do
result = Qiniu.set_style(@bucket, "small.jpg", "imageMogr/auto-orient/thumbnail/!120x120r/gravity/center/crop/!120x120/quality/80")
result.should_not be_false
expect(result).to eq(true)
puts result.inspect
end
end
@@ -72,7 +66,7 @@ module Qiniu
context ".unset_style" do
it "should works" do
result = Qiniu.unset_style(@bucket, "small.jpg")
result.should_not be_false
expect(result).to eq(true)
puts result.inspect
end
end
@@ -88,7 +82,7 @@ module Qiniu
:enable_crc32_check => true
}
result = Qiniu.upload_file(upload_opts)
result.should_not be_false
expect(result).to_not be_empty
puts result.inspect
end
@@ -138,24 +132,22 @@ module Qiniu
File.unlink(localfile) if File.exists?(localfile)
#expect
puts result1.inspect
result1.should_not be_false
result1.should_not be_empty
expect(result1).to_not be_empty
#stat
result2 = Qiniu.stat(@bucket, key)
puts result2.inspect
result2.should_not be_false
expect(result2).to_not be_empty
#delete
result3 = Qiniu.delete(@bucket, key)
puts result3.inspect
result3.should_not be_false
expect(result3).to eq(true)
end
end
context ".stat" do
it "should works" do
result = Qiniu.stat(@bucket, @key)
result.should_not be_false
result.should_not be_empty
expect(result).to_not be_empty
puts result.inspect
end
end
@@ -163,8 +155,7 @@ module Qiniu
context ".get" do
it "should works" do
result = Qiniu.get(@bucket, @key, "qiniu_spec.rb", 10)
result.should_not be_false
result.should_not be_empty
expect(result).to_not be_empty
puts result.inspect
end
end
@@ -172,8 +163,7 @@ module Qiniu
context ".download" do
it "should works" do
result = Qiniu.download(@bucket, @key, "rs_spec.rb", 10)
result.should_not be_false
result.should_not be_empty
expect(result).to_not be_empty
puts result.inspect
end
end
@@ -181,8 +171,7 @@ module Qiniu
context ".batch" do
it "should works" do
result = Qiniu.batch("stat", @bucket, [@key])
result.should_not be_false
result.should_not be_empty
expect(result).to_not be_empty
puts result.inspect
end
end
@@ -190,8 +179,7 @@ module Qiniu
context ".batch_stat" do
it "should works" do
result = Qiniu.batch_stat(@bucket, [@key])
result.should_not be_false
result.should_not be_empty
expect(result).to_not be_empty
puts result.inspect
end
end
@@ -199,8 +187,7 @@ module Qiniu
context ".batch_get" do
it "should works" do
result = Qiniu.batch_get(@bucket, [@key])
result.should_not be_false
result.should_not be_empty
expect(result).to_not be_empty
puts result.inspect
end
end
@@ -208,8 +195,7 @@ module Qiniu
context ".batch_download" do
it "should works" do
result = Qiniu.batch_download(@bucket, [@key])
result.should_not be_false
result.should_not be_empty
expect(result).to_not be_empty
puts result.inspect
end
end
@@ -242,42 +228,40 @@ module Qiniu
context ".move" do
it "should works" do
result = Qiniu.move(@bucket, @key, @bucket, @key2)
result.should_not be_false
expect(result).to eq(true)
result2 = Qiniu.stat(@bucket, @key2)
result2.should_not be_false
expect(result2).to_not be_empty
result3 = Qiniu.move(@bucket, @key2, @bucket, @key)
result3.should_not be_false
expect(result3).to eq(true)
end
end
context ".copy" do
it "should works" do
result = Qiniu.copy(@bucket, @key, @bucket, @key2)
result.should_not be_false
expect(result).to eq(true)
result3 = Qiniu.delete(@bucket, @key2)
result3.should_not be_false
expect(result3).to eq(true)
end
end
context ".delete" do
it "should works" do
result = Qiniu.delete(@bucket, @key)
result.should_not be_false
expect(result).to eq(true)
end
end
context ".image_info" do
it "should works" do
data = Qiniu.get(@test_image_bucket, @test_image_key)
data.should_not be_false
data.should_not be_empty
expect(data).to_not be_empty
puts data.inspect
result = Qiniu.image_info(data["url"])
result.should_not be_false
result.should_not be_empty
expect(result).to_not be_empty
puts result.inspect
end
end
@@ -285,8 +269,7 @@ module Qiniu
context ".image_mogrify_save_as" do
it "should works" do
data = Qiniu.get(@test_image_bucket, @test_image_key)
data.should_not be_false
data.should_not be_empty
expect(data).to_not be_empty
puts data.inspect
dest_key = "cropped-" + @test_image_key
@@ -301,8 +284,7 @@ module Qiniu
:auto_orient => true
}
result2 = Qiniu.image_mogrify_save_as(@test_image_bucket, dest_key, src_img_url, mogrify_options)
result2.should_not be_false
result2.should_not be_empty
expect(result2).to_not be_empty
puts result2.inspect
end
end
+2 -2
View File
@@ -7,7 +7,7 @@ module Qiniu
module RS
describe QboxToken do
before :all do
@qbox_token = QboxToken.new(:url => 'www.qiniutek.com?key1=value1',
@qbox_token = QboxToken.new(:url => 'www.qiniu.com?key1=value1',
:params => { :key2 => 'value2' })
@qbox_token.access_key = 'access_key'
@qbox_token.secret_key = 'secret_key'
@@ -21,7 +21,7 @@ module Qiniu
context "#generate_signature" do
it "should generate signature" do
@qbox_token.generate_signature.should == "www.qiniutek.com?key1=value1\nkey2=value2"
@qbox_token.generate_signature.should == "www.qiniu.com?key1=value1\nkey2=value2"
end
end
end
+1 -8
View File
@@ -11,12 +11,7 @@ module Qiniu
describe Storage do
before :all do
@bucket = 'RubySDK-Test-Storage'
@bucket = make_unique_bucket(@bucket)
### 尝试创建Bucket
result = Qiniu.mkbucket(@bucket)
puts result.inspect
@bucket = 'rubysdk'
@key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s)
@key = make_unique_key_in_bucket(@key)
@@ -53,8 +48,6 @@ module Qiniu
File.unlink(@localfile_4m) if File.exists?(@localfile_4m)
File.unlink(@localfile_8m) if File.exists?(@localfile_8m)
File.unlink(@localfile_1m) if File.exists?(@localfile_1m)
### 不删除Bucket以备下次使用
end
### 测试单文件直传
+4 -4
View File
@@ -26,8 +26,8 @@ module Qiniu
context ".send_request_with" do
it "should works" do
FakeWeb.allow_net_connect = false
FakeWeb.register_uri(:get, "http://docs.qiniutek.com/", :body => {:abc => 123}.to_json)
res = Utils.send_request_with 'http://docs.qiniutek.com/', nil, :method => :get
FakeWeb.register_uri(:get, "http://develoepr.qiniu.com/", :body => {:abc => 123}.to_json)
res = Utils.send_request_with 'http://develoepr.qiniu.com/', nil, :method => :get
res.should == [200, {"abc" => 123}, {}]
end
@@ -35,9 +35,9 @@ module Qiniu
context "upstream return http #{code}" do
it "should raise RestClient::RequestFailed" do
FakeWeb.allow_net_connect = false
FakeWeb.register_uri(:get, "http://docs.qiniutek.com/", :status => code)
FakeWeb.register_uri(:get, "http://develoepr.qiniu.com/", :status => code)
lambda {
res = Utils.send_request_with 'http://docs.qiniutek.com/', nil, :method => :get
res = Utils.send_request_with 'http://develoepr.qiniu.com/', nil, :method => :get
}.should raise_error RestClient::RequestFailed
end
end
+3
View File
@@ -8,6 +8,9 @@ RSpec.configure do |config|
config.before :all do
Qiniu.establish_connection! :access_key => ENV["QINIU_ACCESS_KEY"], :secret_key => ENV["QINIU_SECRET_KEY"]
end
config.before :each, :not_set_ak_sk => true do
Qiniu.establish_connection! :access_key => nil, :secret_key => nil
end
end
def make_unique_bucket (bucket)