mirror of
https://github.com/wahyd4/ruby-sdk.git
synced 2026-08-10 21:36:41 +10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67280b714e | ||
|
|
8f86e6903a | ||
|
|
47cf54069d | ||
|
|
0bb4edcade | ||
|
|
b1e6235b2e | ||
|
|
e5d2367a27 | ||
|
|
3186ba40df | ||
|
|
c5708424b9 | ||
|
|
f85ee1159b | ||
|
|
804c7609ef | ||
|
|
49ab640493 | ||
|
|
85f8e68399 | ||
|
|
7dbec75553 | ||
|
|
3299d2bd02 | ||
|
|
ec8c50383b | ||
|
|
9cc157c21d | ||
|
|
3d40d4e967 | ||
|
|
fa85e838fc | ||
|
|
38970b66e3 | ||
|
|
63ccf3f2dc | ||
|
|
5c011aa816 | ||
|
|
7b507f15c6 | ||
|
|
aab7277b50 | ||
|
|
eaed72eeaa | ||
|
|
60cc7274b1 | ||
|
|
466a4ba07e | ||
|
|
444956f161 | ||
|
|
0e4b5d00bc | ||
|
|
5d2745d148 | ||
|
|
3026a40d99 | ||
|
|
84f7cc6205 | ||
|
|
5562df4b28 | ||
|
|
70c4664e0d | ||
|
|
2096bff7a7 | ||
|
|
b0af3c1814 | ||
|
|
9bda6845a0 | ||
|
|
d9422cbcf4 | ||
|
|
38c054f24c | ||
|
|
f85c4fab41 | ||
|
|
f9bbcfeec6 | ||
|
|
e3d4a80b54 | ||
|
|
61aae133cf | ||
|
|
c3e2a3d44b | ||
|
|
06b019008a | ||
|
|
957b5d1499 | ||
|
|
5b0a561cc1 | ||
|
|
d1e60697c3 | ||
|
|
089b6bc7c6 | ||
|
|
f1edde2e54 | ||
|
|
8aca8bf33e | ||
|
|
69bb9cb913 |
+3
-1
@@ -7,6 +7,8 @@ rvm:
|
|||||||
- jruby-19mode
|
- jruby-19mode
|
||||||
- rbx-18mode
|
- rbx-18mode
|
||||||
- rbx-19mode
|
- rbx-19mode
|
||||||
- ruby-head
|
|
||||||
- jruby-head
|
- jruby-head
|
||||||
- ree
|
- ree
|
||||||
|
before_script:
|
||||||
|
- export QINIU_ACCESS_KEY=LGRqJsjX7LAvtdtX6hhyxs861lS57HwnOQmJsOuX
|
||||||
|
- export QINIU_SECRET_KEY=g_OxhuN5iJ1O7BoA6YdXyF6zSszk34UZFKDfdIIW
|
||||||
|
|||||||
@@ -1,5 +1,53 @@
|
|||||||
## CHANGE LOG
|
## CHANGE LOG
|
||||||
|
|
||||||
|
### v3.4.6
|
||||||
|
|
||||||
|
- `Qiniu::RS.generate_download_token()` 方法的 `:pattern` 调整为必选项。
|
||||||
|
|
||||||
|
### v3.4.5
|
||||||
|
|
||||||
|
- `Qiniu::RS.generate_upload_token()` 方法新增 `:callback_body` 和 `return_url` 选项。
|
||||||
|
- 选项含义参考: <http://docs.qiniu.com/api/v6/put.html#uploadToken-args>
|
||||||
|
|
||||||
|
### v3.4.2
|
||||||
|
|
||||||
|
- `Qiniu::RS.generate_upload_token()` 方法新增 `:return_body` 选项。
|
||||||
|
|
||||||
|
该选项(`:return_body`)可设置文件上传成功后,执行七牛云存储规定的回调API,并以 JSON 响应格式返回其执行结果。参考 [uploadToken 之 returnBody 说明](http://docs.qiniu.com/api/v6/put.html#uploadToken-returnBody)。
|
||||||
|
|
||||||
|
### v3.4.1
|
||||||
|
|
||||||
|
增加为上传文件进行预转的选项,参见 [uploadToken 之 asyncOps 说明](http://docs.qiniu.com/api/v6/put.html#uploadToken-asyncOps)
|
||||||
|
|
||||||
|
- `Qiniu::RS.generate_upload_token()` 方法新增 `:async_options` 选项用于进行预转操作。
|
||||||
|
|
||||||
|
### v3.4.0
|
||||||
|
|
||||||
|
增加文件复制/移动方法,包括批量复制/移动文件
|
||||||
|
|
||||||
|
- `Qiniu::RS.copy(source_bucket, source_key, target_bucket, target_key)`
|
||||||
|
- `Qiniu::RS.move(source_bucket, source_key, target_bucket, target_key)`
|
||||||
|
- `Qiniu::RS.batch_copy [source_bucket, source_key, target_bucket, target_key], ...`
|
||||||
|
- `Qiniu::RS.batch_move [source_bucket, source_key, target_bucket, target_key], ...`
|
||||||
|
|
||||||
|
### v3.3.1
|
||||||
|
|
||||||
|
确保单元测试里边用到的测试 Bucket 全局唯一
|
||||||
|
|
||||||
|
使得10多种不通的 Ruby 宿主环境能隔离互不影响地执行单元/集成测试
|
||||||
|
|
||||||
|
Ruby 宿主环境如下
|
||||||
|
|
||||||
|
1.8.7, 1.9.2, 1.9.3, jruby-18mode, jruby-19mode, rbx-18mode, rbx-19mode, ruby-head, jruby-head, ree
|
||||||
|
|
||||||
|
详见 <https://travis-ci.org/qiniu/ruby-sdk>
|
||||||
|
|
||||||
|
### v3.3.0
|
||||||
|
|
||||||
|
私有资源下载新版实现,添加 Qiniu::RS.generate_download_token() 方法。参考 [downloadToken](http://docs.qiniutek.com/v3/api/io/#get)
|
||||||
|
|
||||||
|
详见 [Ruby SDK 使用文档之私有资源下载](http://docs.qiniutek.com/v3/sdk/ruby/#download-private-files)
|
||||||
|
|
||||||
### v3.2.2
|
### v3.2.2
|
||||||
|
|
||||||
fixed E701 error
|
fixed E701 error
|
||||||
|
|||||||
+8
-8
@@ -1,7 +1,7 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
qiniu-rs (3.2.2)
|
qiniu-rs (3.4.6)
|
||||||
json (~> 1.7)
|
json (~> 1.7)
|
||||||
mime-types (~> 1.19)
|
mime-types (~> 1.19)
|
||||||
rest-client (~> 1.6)
|
rest-client (~> 1.6)
|
||||||
@@ -12,19 +12,19 @@ GEM
|
|||||||
specs:
|
specs:
|
||||||
diff-lcs (1.1.3)
|
diff-lcs (1.1.3)
|
||||||
fakeweb (1.3.0)
|
fakeweb (1.3.0)
|
||||||
json (1.7.5)
|
json (1.7.7)
|
||||||
mime-types (1.19)
|
mime-types (1.23)
|
||||||
rake (10.0.2)
|
rake (10.0.3)
|
||||||
rest-client (1.6.7)
|
rest-client (1.6.7)
|
||||||
mime-types (>= 1.16)
|
mime-types (>= 1.16)
|
||||||
rspec (2.12.0)
|
rspec (2.12.0)
|
||||||
rspec-core (~> 2.12.0)
|
rspec-core (~> 2.12.0)
|
||||||
rspec-expectations (~> 2.12.0)
|
rspec-expectations (~> 2.12.0)
|
||||||
rspec-mocks (~> 2.12.0)
|
rspec-mocks (~> 2.12.0)
|
||||||
rspec-core (2.12.1)
|
rspec-core (2.12.2)
|
||||||
rspec-expectations (2.12.0)
|
rspec-expectations (2.12.1)
|
||||||
diff-lcs (~> 1.1.3)
|
diff-lcs (~> 1.1.3)
|
||||||
rspec-mocks (2.12.0)
|
rspec-mocks (2.12.2)
|
||||||
ruby-hmac (0.4.0)
|
ruby-hmac (0.4.0)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
@@ -34,4 +34,4 @@ DEPENDENCIES
|
|||||||
fakeweb (~> 1.3)
|
fakeweb (~> 1.3)
|
||||||
qiniu-rs!
|
qiniu-rs!
|
||||||
rake (>= 0.9)
|
rake (>= 0.9)
|
||||||
rspec (~> 2.11)
|
rspec (>= 2.11)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 2012 why404
|
Copyright (c) 2012-2013 qiniutek.com
|
||||||
|
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Qiniu Resource (Cloud) Storage SDK for Ruby - [](http://travis-ci.org/why404/qiniu-rs-for-ruby) [](https://gemnasium.com/why404/qiniu-rs-for-ruby)
|
# Qiniu Resource (Cloud) Storage SDK for Ruby
|
||||||
|
|
||||||
# 关于
|
# 关于
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
## 许可证
|
## 许可证
|
||||||
|
|
||||||
Copyright (c) 2012 qiniutek.com
|
Copyright (c) 2012-2013 qiniutek.com
|
||||||
|
|
||||||
基于 MIT 协议发布:
|
基于 MIT 协议发布:
|
||||||
|
|
||||||
|
|||||||
+250
-507
File diff suppressed because it is too large
Load Diff
+39
-3
@@ -17,6 +17,7 @@ module Qiniu
|
|||||||
autoload :AccessToken, 'qiniu/tokens/access_token'
|
autoload :AccessToken, 'qiniu/tokens/access_token'
|
||||||
autoload :QboxToken, 'qiniu/tokens/qbox_token'
|
autoload :QboxToken, 'qiniu/tokens/qbox_token'
|
||||||
autoload :UploadToken, 'qiniu/tokens/upload_token'
|
autoload :UploadToken, 'qiniu/tokens/upload_token'
|
||||||
|
autoload :DownloadToken, 'qiniu/tokens/download_token'
|
||||||
autoload :Abstract, 'qiniu/rs/abstract'
|
autoload :Abstract, 'qiniu/rs/abstract'
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
@@ -62,6 +63,7 @@ module Qiniu
|
|||||||
code == StatusOK
|
code == StatusOK
|
||||||
end
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
def set_watermark(customer_id, options = {})
|
def set_watermark(customer_id, options = {})
|
||||||
code, data = EU.set_watermark(customer_id, options)
|
code, data = EU.set_watermark(customer_id, options)
|
||||||
code == StatusOK
|
code == StatusOK
|
||||||
@@ -71,6 +73,7 @@ module Qiniu
|
|||||||
code, data = EU.get_watermark(customer_id)
|
code, data = EU.get_watermark(customer_id)
|
||||||
code == StatusOK ? data : false
|
code == StatusOK ? data : false
|
||||||
end
|
end
|
||||||
|
=end
|
||||||
|
|
||||||
def put_auth(expires_in = nil, callback_url = nil)
|
def put_auth(expires_in = nil, callback_url = nil)
|
||||||
code, data = IO.put_auth(expires_in, callback_url)
|
code, data = IO.put_auth(expires_in, callback_url)
|
||||||
@@ -100,12 +103,14 @@ module Qiniu
|
|||||||
end
|
end
|
||||||
|
|
||||||
def upload_file opts = {}
|
def upload_file opts = {}
|
||||||
[:uptoken, :file, :bucket, :key].each do |opt|
|
uncontained_opts = [:uptoken, :file, :bucket, :key] - opts.keys
|
||||||
raise MissingArgsError, [opt] unless opts.has_key?(opt)
|
raise MissingArgsError, uncontained_opts unless uncontained_opts.empty?
|
||||||
end
|
|
||||||
source_file = opts[:file]
|
source_file = opts[:file]
|
||||||
raise NoSuchFileError, source_file unless File.exist?(source_file)
|
raise NoSuchFileError, source_file unless File.exist?(source_file)
|
||||||
|
|
||||||
opts[:enable_resumable_upload] = true unless opts.has_key?(:enable_resumable_upload)
|
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]
|
if opts[:enable_resumable_upload] && File::size(source_file) > Config.settings[:block_size]
|
||||||
code, data = UP.upload_with_token(opts[:uptoken],
|
code, data = UP.upload_with_token(opts[:uptoken],
|
||||||
opts[:file],
|
opts[:file],
|
||||||
@@ -146,6 +151,16 @@ module Qiniu
|
|||||||
code == StatusOK ? data["url"] : false
|
code == StatusOK ? data["url"] : false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def copy(source_bucket, source_key, target_bucket, target_key)
|
||||||
|
code, data = RS.copy(source_bucket, source_key, target_bucket, target_key)
|
||||||
|
code == StatusOK
|
||||||
|
end
|
||||||
|
|
||||||
|
def move(source_bucket, source_key, target_bucket, target_key)
|
||||||
|
code, data = RS.move(source_bucket, source_key, target_bucket, target_key)
|
||||||
|
code == StatusOK
|
||||||
|
end
|
||||||
|
|
||||||
def delete(bucket, key)
|
def delete(bucket, key)
|
||||||
code, data = RS.delete(bucket, key)
|
code, data = RS.delete(bucket, key)
|
||||||
code == StatusOK
|
code == StatusOK
|
||||||
@@ -166,6 +181,16 @@ module Qiniu
|
|||||||
code == StatusOK ? data : false
|
code == StatusOK ? data : false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def batch_copy(*args)
|
||||||
|
code, data = RS.batch_copy(args)
|
||||||
|
code == StatusOK
|
||||||
|
end
|
||||||
|
|
||||||
|
def batch_move(*args)
|
||||||
|
code, data = RS.batch_move(args)
|
||||||
|
code == StatusOK
|
||||||
|
end
|
||||||
|
|
||||||
def batch_download(bucket, keys)
|
def batch_download(bucket, keys)
|
||||||
code, data = RS.batch_get(bucket, keys)
|
code, data = RS.batch_get(bucket, keys)
|
||||||
return false unless code == StatusOK
|
return false unless code == StatusOK
|
||||||
@@ -227,6 +252,17 @@ module Qiniu
|
|||||||
#token_obj.callback_body_type = opts[:callback_body_type]
|
#token_obj.callback_body_type = opts[:callback_body_type]
|
||||||
#token_obj.customer = opts[:customer]
|
#token_obj.customer = opts[:customer]
|
||||||
#token_obj.escape = opts[:escape]
|
#token_obj.escape = opts[:escape]
|
||||||
|
#token_obj.async_options = opts[:async_options]
|
||||||
|
#token_obj.return_body = opts[:return_body]
|
||||||
|
token_obj.generate_token
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_download_token(opts = {})
|
||||||
|
token_obj = DownloadToken.new(opts)
|
||||||
|
token_obj.access_key = Config.settings[:access_key]
|
||||||
|
token_obj.secret_key = Config.settings[:secret_key]
|
||||||
|
#token_obj.expires_in = opts[:expires_in]
|
||||||
|
#token_obj.pattern = opts[:pattern]
|
||||||
token_obj.generate_token
|
token_obj.generate_token
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,16 @@ module Qiniu
|
|||||||
Auth.request url
|
Auth.request url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def copy(source_bucket, source_key, target_bucket, target_key)
|
||||||
|
uri = _generate_cp_or_mv_opstr('copy', source_bucket, source_key, target_bucket, target_key)
|
||||||
|
Auth.request Config.settings[:rs_host] + uri
|
||||||
|
end
|
||||||
|
|
||||||
|
def move(source_bucket, source_key, target_bucket, target_key)
|
||||||
|
uri = _generate_cp_or_mv_opstr('move', source_bucket, source_key, target_bucket, target_key)
|
||||||
|
Auth.request Config.settings[:rs_host] + uri
|
||||||
|
end
|
||||||
|
|
||||||
def delete(bucket, key)
|
def delete(bucket, key)
|
||||||
Auth.request Config.settings[:rs_host] + '/delete/' + encode_entry_uri(bucket, key)
|
Auth.request Config.settings[:rs_host] + '/delete/' + encode_entry_uri(bucket, key)
|
||||||
end
|
end
|
||||||
@@ -61,6 +71,14 @@ module Qiniu
|
|||||||
batch("stat", bucket, keys)
|
batch("stat", bucket, keys)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def batch_copy(*args)
|
||||||
|
_batch_cp_or_mv('copy', args)
|
||||||
|
end
|
||||||
|
|
||||||
|
def batch_move(*args)
|
||||||
|
_batch_cp_or_mv('move', args)
|
||||||
|
end
|
||||||
|
|
||||||
def batch_delete(bucket, keys)
|
def batch_delete(bucket, keys)
|
||||||
batch("delete", bucket, keys)
|
batch("delete", bucket, keys)
|
||||||
end
|
end
|
||||||
@@ -77,6 +95,22 @@ module Qiniu
|
|||||||
save_as(bucket, key, source_image_url, mogrify_params_string)
|
save_as(bucket, key, source_image_url, mogrify_params_string)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def _generate_cp_or_mv_opstr(command, source_bucket, source_key, target_bucket, target_key)
|
||||||
|
source_encoded_entry_uri = encode_entry_uri(source_bucket, source_key)
|
||||||
|
target_encoded_entry_uri = encode_entry_uri(target_bucket, target_key)
|
||||||
|
%Q(/#{command}/#{source_encoded_entry_uri}/#{target_encoded_entry_uri})
|
||||||
|
end
|
||||||
|
|
||||||
|
def _batch_cp_or_mv(command, *op_args)
|
||||||
|
execs = []
|
||||||
|
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
|
||||||
|
Auth.request Config.settings[:rs_host] + "/batch?" + execs.join("&")
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+5
-9
@@ -58,7 +58,7 @@ module Qiniu
|
|||||||
class TmpData
|
class TmpData
|
||||||
def initialize(dir, filename)
|
def initialize(dir, filename)
|
||||||
@tmpdir = Config.settings[:tmpdir] + File::SEPARATOR + dir
|
@tmpdir = Config.settings[:tmpdir] + File::SEPARATOR + dir
|
||||||
FileUtils.mkdir_p(@tmpdir) unless Dir.exists?(@tmpdir)
|
FileUtils.mkdir_p(@tmpdir) unless File.directory?(@tmpdir)
|
||||||
@tmpfile = @tmpdir + File::SEPARATOR + filename
|
@tmpfile = @tmpdir + File::SEPARATOR + filename
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ module Qiniu
|
|||||||
end
|
end
|
||||||
|
|
||||||
def sweep!
|
def sweep!
|
||||||
FileUtils.rm_r(@tmpdir) if Dir.exists?(@tmpdir)
|
FileUtils.rm_r(@tmpdir) if File.directory?(@tmpdir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -100,7 +100,6 @@ module Qiniu
|
|||||||
customer = nil,
|
customer = nil,
|
||||||
callback_params = nil,
|
callback_params = nil,
|
||||||
rotate = nil)
|
rotate = nil)
|
||||||
raise NoSuchFileError, local_file unless File.exist?(local_file)
|
|
||||||
begin
|
begin
|
||||||
ifile = File.open(local_file, 'rb')
|
ifile = File.open(local_file, 'rb')
|
||||||
fh = FileData.new(ifile)
|
fh = FileData.new(ifile)
|
||||||
@@ -110,11 +109,7 @@ module Qiniu
|
|||||||
mime = MIME::Types.type_for local_file
|
mime = MIME::Types.type_for local_file
|
||||||
mime_type = mime.empty? ? 'application/octet-stream' : mime[0].content_type
|
mime_type = mime.empty? ? 'application/octet-stream' : mime[0].content_type
|
||||||
end
|
end
|
||||||
if fsize > Config.settings[:block_size]
|
code, data = _resumable_upload(uptoken, fh, fsize, bucket, key, mime_type, custom_meta, customer, callback_params, rotate)
|
||||||
code, data = _resumable_upload(uptoken, fh, fsize, bucket, key, mime_type, custom_meta, customer, callback_params, rotate)
|
|
||||||
else
|
|
||||||
code, data = IO.upload_with_token(uptoken, local_file, bucket, key, mime_type, custom_meta, callback_params, true, rotate)
|
|
||||||
end
|
|
||||||
[code, data]
|
[code, data]
|
||||||
ensure
|
ensure
|
||||||
ifile.close unless ifile.nil?
|
ifile.close unless ifile.nil?
|
||||||
@@ -175,7 +170,7 @@ module Qiniu
|
|||||||
_call_binary_with_token(uptoken, url, body)
|
_call_binary_with_token(uptoken, url, body)
|
||||||
end
|
end
|
||||||
|
|
||||||
def _resumable_put_block(uptoken, fh, block_index, block_size, chunk_size, progress, retry_times = 1, notifier)
|
def _resumable_put_block(uptoken, fh, block_index, block_size, chunk_size, progress, retry_times, notifier)
|
||||||
code, data = 0, {}
|
code, data = 0, {}
|
||||||
fpath = fh.path
|
fpath = fh.path
|
||||||
# this block has never been uploaded.
|
# this block has never been uploaded.
|
||||||
@@ -323,6 +318,7 @@ module Qiniu
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ module Qiniu
|
|||||||
module RS
|
module RS
|
||||||
module Version
|
module Version
|
||||||
MAJOR = 3
|
MAJOR = 3
|
||||||
MINOR = 2
|
MINOR = 4
|
||||||
PATCH = 2
|
PATCH = 6
|
||||||
# Returns a version string by joining <tt>MAJOR</tt>, <tt>MINOR</tt>, and <tt>PATCH</tt> with <tt>'.'</tt>
|
# Returns a version string by joining <tt>MAJOR</tt>, <tt>MINOR</tt>, and <tt>PATCH</tt> with <tt>'.'</tt>
|
||||||
#
|
#
|
||||||
# Example
|
# Example
|
||||||
|
|||||||
Executable
+33
@@ -0,0 +1,33 @@
|
|||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
|
require 'json'
|
||||||
|
require 'qiniu/tokens/access_token'
|
||||||
|
require 'qiniu/rs/utils'
|
||||||
|
|
||||||
|
module Qiniu
|
||||||
|
module RS
|
||||||
|
class DownloadToken < AccessToken
|
||||||
|
|
||||||
|
include Utils
|
||||||
|
|
||||||
|
attr_accessor :pattern, :expires_in
|
||||||
|
|
||||||
|
def initialize(opts = {})
|
||||||
|
@pattern = opts[:pattern]
|
||||||
|
@expires_in = opts[:expires_in] || 3600
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_signature
|
||||||
|
params = {"S" => @pattern, "E" => Time.now.to_i + @expires_in}
|
||||||
|
Utils.urlsafe_base64_encode(params.to_json)
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_token
|
||||||
|
signature = generate_signature
|
||||||
|
encoded_digest = generate_encoded_digest(signature)
|
||||||
|
%Q(#{@access_key}:#{encoded_digest}:#{signature})
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -8,6 +8,8 @@ module Qiniu
|
|||||||
module RS
|
module RS
|
||||||
class QboxToken < AccessToken
|
class QboxToken < AccessToken
|
||||||
|
|
||||||
|
include Utils
|
||||||
|
|
||||||
attr_accessor :url, :params
|
attr_accessor :url, :params
|
||||||
|
|
||||||
def initialize(opts = {})
|
def initialize(opts = {})
|
||||||
@@ -20,10 +22,10 @@ module Qiniu
|
|||||||
signature = uri.path
|
signature = uri.path
|
||||||
query_string = uri.query
|
query_string = uri.query
|
||||||
signature += '?' + query_string if !query_string.nil? && !query_string.empty?
|
signature += '?' + query_string if !query_string.nil? && !query_string.empty?
|
||||||
signature += "\n";
|
signature += "\n"
|
||||||
if @params.is_a?(Hash)
|
if @params.is_a?(Hash)
|
||||||
total_param = @params.map { |key, value| %Q(#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s).gsub('+', '%20')}) }
|
params_string = Utils.generate_query_string(@params)
|
||||||
signature += total_param.join("&")
|
signature += params_string
|
||||||
end
|
end
|
||||||
signature
|
signature
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,24 +10,32 @@ module Qiniu
|
|||||||
|
|
||||||
include Utils
|
include Utils
|
||||||
|
|
||||||
attr_accessor :scope, :expires_in, :callback_url, :callback_body_type, :customer, :escape
|
attr_accessor :scope, :expires_in, :callback_url, :callback_body, :callback_body_type, :customer, :escape, :async_options, :return_body, :return_url
|
||||||
|
|
||||||
def initialize(opts = {})
|
def initialize(opts = {})
|
||||||
@scope = opts[:scope]
|
@scope = opts[:scope]
|
||||||
@expires_in = opts[:expires_in] || 3600
|
@expires_in = opts[:expires_in] || 3600
|
||||||
@callback_url = opts[:callback_url]
|
@callback_url = opts[:callback_url]
|
||||||
|
@callback_body = opts[:callback_body]
|
||||||
@callback_body_type = opts[:callback_body_type]
|
@callback_body_type = opts[:callback_body_type]
|
||||||
@customer = opts[:customer]
|
@customer = opts[:customer]
|
||||||
@escape = opts[:escape]
|
@escape = opts[:escape]
|
||||||
|
@async_options = opts[:async_options]
|
||||||
|
@return_body = opts[:return_body]
|
||||||
|
@return_url = opts[:return_url]
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_signature
|
def generate_signature
|
||||||
params = {:scope => @scope, :deadline => Time.now.to_i + @expires_in}
|
params = {:scope => @scope, :deadline => Time.now.to_i + @expires_in}
|
||||||
params[:callbackUrl] = @callback_url if !@callback_url.nil? && !@callback_url.empty?
|
params[:callbackUrl] = @callback_url if !@callback_url.nil? && !@callback_url.empty?
|
||||||
|
params[:callbackBody] = @callback_body if !@callback_body.nil? && !@callback_body.empty?
|
||||||
params[:callbackBodyType] = @callback_body_type if !@callback_body_type.nil? && !@callback_body_type.empty?
|
params[:callbackBodyType] = @callback_body_type if !@callback_body_type.nil? && !@callback_body_type.empty?
|
||||||
params[:customer] = @customer if !@customer.nil? && !@customer.empty?
|
params[:customer] = @customer if !@customer.nil? && !@customer.empty?
|
||||||
params[:escape] = 1 if @escape == 1 || @escape == true
|
params[:escape] = 1 if @escape == 1 || @escape == true
|
||||||
urlsafe_base64_encode(params.to_json)
|
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?
|
||||||
|
Utils.urlsafe_base64_encode(params.to_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_token
|
def generate_token
|
||||||
|
|||||||
+2
-2
@@ -5,7 +5,7 @@ require File.expand_path('../lib/qiniu/rs/version', __FILE__)
|
|||||||
Gem::Specification.new do |gem|
|
Gem::Specification.new do |gem|
|
||||||
gem.authors = ["why404"]
|
gem.authors = ["why404"]
|
||||||
gem.email = ["why404@gmail.com"]
|
gem.email = ["why404@gmail.com"]
|
||||||
gem.description = %q{Qiniu Resource (Cloud) Storage SDK for Ruby. See: http://docs.qiniutek.com/v3/sdk/ruby/}
|
gem.description = %q{Qiniu Resource (Cloud) Storage SDK for Ruby. See: http://docs.qiniu.com/ruby-sdk/}
|
||||||
gem.summary = %q{Qiniu Resource (Cloud) Storage SDK for Ruby}
|
gem.summary = %q{Qiniu Resource (Cloud) Storage SDK for Ruby}
|
||||||
gem.homepage = "https://github.com/qiniu/ruby-sdk"
|
gem.homepage = "https://github.com/qiniu/ruby-sdk"
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
|
|||||||
|
|
||||||
# specify any dependencies here; for example:
|
# specify any dependencies here; for example:
|
||||||
gem.add_development_dependency "rake", ">= 0.9"
|
gem.add_development_dependency "rake", ">= 0.9"
|
||||||
gem.add_development_dependency "rspec", "~> 2.11"
|
gem.add_development_dependency "rspec", ">= 2.11"
|
||||||
gem.add_development_dependency "fakeweb", "~> 1.3"
|
gem.add_development_dependency "fakeweb", "~> 1.3"
|
||||||
gem.add_runtime_dependency "json", "~> 1.7"
|
gem.add_runtime_dependency "json", "~> 1.7"
|
||||||
gem.add_runtime_dependency "rest-client", "~> 1.6"
|
gem.add_runtime_dependency "rest-client", "~> 1.6"
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ module Qiniu
|
|||||||
describe EU do
|
describe EU do
|
||||||
|
|
||||||
before :all do
|
before :all do
|
||||||
@customer_id = "awhy.xu@gmail.com"
|
@customer_id = "why404@gmail.com"
|
||||||
@bucket = "wm_test_bucket"
|
@bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
||||||
@key = "image_logo_for_test.png"
|
@key = "image_logo_for_test.png"
|
||||||
|
|
||||||
result = Qiniu::RS.mkbucket(@bucket)
|
result = Qiniu::RS.mkbucket(@bucket)
|
||||||
@@ -35,12 +35,12 @@ module Qiniu
|
|||||||
end
|
end
|
||||||
|
|
||||||
after :all do
|
after :all do
|
||||||
@bucket = "wm_test_bucket"
|
|
||||||
result = Qiniu::RS.drop(@bucket)
|
result = Qiniu::RS.drop(@bucket)
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
result.should_not be_false
|
result.should_not be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
context ".set_watermark" do
|
context ".set_watermark" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
options = {
|
options = {
|
||||||
@@ -59,6 +59,7 @@ module Qiniu
|
|||||||
puts data.inspect
|
puts data.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
=end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ module Qiniu
|
|||||||
|
|
||||||
before :all do
|
before :all do
|
||||||
|
|
||||||
@bucket = "test_images_12345"
|
@bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
||||||
@key = "image_logo_for_test.png"
|
@key = "image_logo_for_test.png"
|
||||||
|
|
||||||
result = Qiniu::RS.mkbucket(@bucket)
|
result = Qiniu::RS.mkbucket(@bucket)
|
||||||
@@ -20,11 +20,22 @@ module Qiniu
|
|||||||
|
|
||||||
local_file = File.expand_path('../' + @key, __FILE__)
|
local_file = File.expand_path('../' + @key, __FILE__)
|
||||||
|
|
||||||
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "awhy.xu@gmail.com"}
|
upopts = {
|
||||||
|
:scope => @bucket,
|
||||||
|
:expires_in => 3600,
|
||||||
|
:customer => "why404@gmail.com",
|
||||||
|
:async_options => "imageView/1/w/120/h/120",
|
||||||
|
:return_body => '{"size":$(fsize), "hash":$(etag), "width":$(imageInfo.width), "height":$(imageInfo.height)}'
|
||||||
|
}
|
||||||
uptoken = Qiniu::RS.generate_upload_token(upopts)
|
uptoken = Qiniu::RS.generate_upload_token(upopts)
|
||||||
data = Qiniu::RS.upload_file :uptoken => uptoken, :file => local_file, :bucket => @bucket, :key => @key
|
data = Qiniu::RS.upload_file :uptoken => uptoken, :file => local_file, :bucket => @bucket, :key => @key
|
||||||
puts data.inspect
|
puts data.inspect
|
||||||
|
|
||||||
|
data["size"].should_not be_zero
|
||||||
|
data["hash"].should_not be_empty
|
||||||
|
data["width"].should_not be_zero
|
||||||
|
data["height"].should_not be_zero
|
||||||
|
|
||||||
result = Qiniu::RS.get(@bucket, @key)
|
result = Qiniu::RS.get(@bucket, @key)
|
||||||
result["url"].should_not be_empty
|
result["url"].should_not be_empty
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
@@ -42,7 +53,6 @@ module Qiniu
|
|||||||
end
|
end
|
||||||
|
|
||||||
after :all do
|
after :all do
|
||||||
@bucket = "test_images_12345"
|
|
||||||
result = Qiniu::RS.drop(@bucket)
|
result = Qiniu::RS.drop(@bucket)
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
result.should_not be_false
|
result.should_not be_false
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Utils.-*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require 'qiniu/rs/auth'
|
require 'qiniu/rs/auth'
|
||||||
@@ -10,8 +10,8 @@ module Qiniu
|
|||||||
describe IO do
|
describe IO do
|
||||||
|
|
||||||
before :all do
|
before :all do
|
||||||
@bucket = "io_test_bucket"
|
@bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
||||||
@key = Digest::SHA1.hexdigest (Time.now.to_i+rand(100)).to_s
|
@key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s)
|
||||||
|
|
||||||
result = Qiniu::RS.mkbucket(@bucket)
|
result = Qiniu::RS.mkbucket(@bucket)
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
@@ -19,7 +19,6 @@ module Qiniu
|
|||||||
end
|
end
|
||||||
|
|
||||||
after :all do
|
after :all do
|
||||||
@bucket = "io_test_bucket"
|
|
||||||
result = Qiniu::RS.drop(@bucket)
|
result = Qiniu::RS.drop(@bucket)
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
result.should_not be_false
|
result.should_not be_false
|
||||||
@@ -48,7 +47,7 @@ module Qiniu
|
|||||||
|
|
||||||
context ".upload_with_token" do
|
context ".upload_with_token" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "awhy.xu@gmail.com"}
|
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
|
||||||
uptoken = Qiniu::RS.generate_upload_token(upopts)
|
uptoken = Qiniu::RS.generate_upload_token(upopts)
|
||||||
code, data = Qiniu::RS::IO.upload_with_token(uptoken, __FILE__, @bucket, @key, nil, nil, nil, true)
|
code, data = Qiniu::RS::IO.upload_with_token(uptoken, __FILE__, @bucket, @key, nil, nil, nil, true)
|
||||||
code.should == 200
|
code.should == 200
|
||||||
|
|||||||
@@ -10,14 +10,13 @@ module Qiniu
|
|||||||
describe Pub do
|
describe Pub do
|
||||||
|
|
||||||
before :all do
|
before :all do
|
||||||
@bucket = "pub_test_bucket"
|
@bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
||||||
result = Qiniu::RS.mkbucket(@bucket)
|
result = Qiniu::RS.mkbucket(@bucket)
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
result.should_not be_false
|
result.should_not be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
after :all do
|
after :all do
|
||||||
@bucket = "pub_test_bucket"
|
|
||||||
result = Qiniu::RS.drop(@bucket)
|
result = Qiniu::RS.drop(@bucket)
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
result.should_not be_false
|
result.should_not be_false
|
||||||
|
|||||||
@@ -11,9 +11,10 @@ module Qiniu
|
|||||||
describe RS do
|
describe RS do
|
||||||
|
|
||||||
before :all do
|
before :all do
|
||||||
@bucket = "rs_test_bucket"
|
@bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
||||||
@key = Digest::SHA1.hexdigest (Time.now.to_i+rand(100)).to_s
|
@key = Digest::SHA1.hexdigest((Time.now.to_i+rand(100)).to_s)
|
||||||
@domain = 'rs-test-bucket.dn.qbox.me'
|
@key2 = @key + rand(100).to_s
|
||||||
|
#@domain = @bucket + '.dn.qbox.me'
|
||||||
|
|
||||||
code, data = Qiniu::RS::RS.mkbucket(@bucket)
|
code, data = Qiniu::RS::RS.mkbucket(@bucket)
|
||||||
puts [code, data].inspect
|
puts [code, data].inspect
|
||||||
@@ -21,7 +22,6 @@ module Qiniu
|
|||||||
end
|
end
|
||||||
|
|
||||||
after :all do
|
after :all do
|
||||||
@bucket = "rs_test_bucket"
|
|
||||||
code, data = Qiniu::RS::RS.drop(@bucket)
|
code, data = Qiniu::RS::RS.drop(@bucket)
|
||||||
puts [code, data].inspect
|
puts [code, data].inspect
|
||||||
code.should == 200
|
code.should == 200
|
||||||
@@ -90,6 +90,35 @@ module Qiniu
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context ".batch_copy" do
|
||||||
|
it "should works" do
|
||||||
|
code, data = Qiniu::RS::RS.batch_copy [@bucket, @key, @bucket, @key2]
|
||||||
|
code.should == 200
|
||||||
|
puts data.inspect
|
||||||
|
|
||||||
|
#code2, data2 = Qiniu::RS::RS.stat(@bucket, @key2)
|
||||||
|
#code2.should == 200
|
||||||
|
#puts data2.inspect
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context ".batch_move" do
|
||||||
|
it "should works" do
|
||||||
|
code, data = Qiniu::RS::RS.batch_move [@bucket, @key, @bucket, @key2]
|
||||||
|
code.should == 200
|
||||||
|
puts data.inspect
|
||||||
|
|
||||||
|
#code2, data2 = Qiniu::RS::RS.stat(@bucket, @key2)
|
||||||
|
#code2.should == 200
|
||||||
|
#puts data2.inspect
|
||||||
|
|
||||||
|
code3, data3 = Qiniu::RS::RS.batch_move [@bucket, @key2, @bucket, @key]
|
||||||
|
code3.should == 200
|
||||||
|
puts data3.inspect
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
context ".publish" do
|
context ".publish" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
code, data = Qiniu::RS::RS.publish(@domain, @bucket)
|
code, data = Qiniu::RS::RS.publish(@domain, @bucket)
|
||||||
@@ -105,6 +134,35 @@ module Qiniu
|
|||||||
puts data.inspect
|
puts data.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
=end
|
||||||
|
|
||||||
|
context ".move" do
|
||||||
|
it "should works" do
|
||||||
|
code, data = Qiniu::RS::RS.move(@bucket, @key, @bucket, @key2)
|
||||||
|
code.should == 200
|
||||||
|
puts data.inspect
|
||||||
|
|
||||||
|
code2, data2 = Qiniu::RS::RS.stat(@bucket, @key2)
|
||||||
|
code2.should == 200
|
||||||
|
puts data2.inspect
|
||||||
|
|
||||||
|
code3, data3 = Qiniu::RS::RS.move(@bucket, @key2, @bucket, @key)
|
||||||
|
code3.should == 200
|
||||||
|
puts data3.inspect
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context ".copy" do
|
||||||
|
it "should works" do
|
||||||
|
code, data = Qiniu::RS::RS.copy(@bucket, @key, @bucket, @key2)
|
||||||
|
code.should == 200
|
||||||
|
puts data.inspect
|
||||||
|
|
||||||
|
#code2, data2 = Qiniu::RS::RS.stat(@bucket, @key2)
|
||||||
|
#code2.should == 200
|
||||||
|
#puts data2.inspect
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context ".delete" do
|
context ".delete" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Utils.-*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
require 'digest/sha1'
|
require 'digest/sha1'
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
@@ -11,8 +11,8 @@ module Qiniu
|
|||||||
|
|
||||||
before :all do
|
before :all do
|
||||||
@localfile = "bigfile.txt"
|
@localfile = "bigfile.txt"
|
||||||
File.open(@localfile, "w"){|f| 5242888.times{f.write(Random.rand(9).to_s)}}
|
File.open(@localfile, "w"){|f| 5242888.times{f.write(rand(9).to_s)}}
|
||||||
@bucket = "up_test_bucket"
|
@bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
||||||
@key = Digest::SHA1.hexdigest(@localfile+Time.now.to_s)
|
@key = Digest::SHA1.hexdigest(@localfile+Time.now.to_s)
|
||||||
|
|
||||||
code, data = Qiniu::RS::RS.mkbucket(@bucket)
|
code, data = Qiniu::RS::RS.mkbucket(@bucket)
|
||||||
@@ -30,7 +30,7 @@ module Qiniu
|
|||||||
|
|
||||||
context ".upload_with_token" do
|
context ".upload_with_token" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "awhy.xu@gmail.com"}
|
upopts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
|
||||||
uptoken = Qiniu::RS.generate_upload_token(upopts)
|
uptoken = Qiniu::RS.generate_upload_token(upopts)
|
||||||
code, data = Qiniu::RS::UP.upload_with_token(uptoken, @localfile, @bucket, @key)
|
code, data = Qiniu::RS::UP.upload_with_token(uptoken, @localfile, @bucket, @key)
|
||||||
puts data.inspect
|
puts data.inspect
|
||||||
|
|||||||
+101
-15
@@ -3,19 +3,21 @@
|
|||||||
require 'digest/sha1'
|
require 'digest/sha1'
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require 'qiniu/rs'
|
require 'qiniu/rs'
|
||||||
|
require 'qiniu/rs/exceptions'
|
||||||
|
|
||||||
module Qiniu
|
module Qiniu
|
||||||
describe RS do
|
describe RS do
|
||||||
|
|
||||||
before :all do
|
before :all do
|
||||||
@bucket = 'qiniu_rs_test'
|
@bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
||||||
@key = Digest::SHA1.hexdigest Time.now.to_s
|
@key = Digest::SHA1.hexdigest Time.now.to_s
|
||||||
@domain = 'qiniu-rs-test.dn.qbox.me'
|
@key2 = @key + rand(100).to_s
|
||||||
|
#@domain = @bucket + '.dn.qbox.me'
|
||||||
|
|
||||||
result = Qiniu::RS.mkbucket(@bucket)
|
result = Qiniu::RS.mkbucket(@bucket)
|
||||||
result.should_not be_false
|
result.should_not be_false
|
||||||
|
|
||||||
@test_image_bucket = 'test_images_12345'
|
@test_image_bucket = 'RubySdkTest' + (Time.now.to_i+rand(1000)).to_s
|
||||||
result2 = Qiniu::RS.mkbucket(@test_image_bucket)
|
result2 = Qiniu::RS.mkbucket(@test_image_bucket)
|
||||||
puts result2.inspect
|
puts result2.inspect
|
||||||
result2.should be_true
|
result2.should be_true
|
||||||
@@ -23,16 +25,19 @@ module Qiniu
|
|||||||
@test_image_key = 'image_logo_for_test.png'
|
@test_image_key = 'image_logo_for_test.png'
|
||||||
local_file = File.expand_path('./rs/' + @test_image_key, File.dirname(__FILE__))
|
local_file = File.expand_path('./rs/' + @test_image_key, File.dirname(__FILE__))
|
||||||
puts local_file.inspect
|
puts local_file.inspect
|
||||||
upopts = {:scope => @test_image_bucket, :expires_in => 3600, :customer => "awhy.xu@gmail.com"}
|
upopts = {:scope => @test_image_bucket, :expires_in => 3600, :customer => "why404@gmail.com"}
|
||||||
uptoken = Qiniu::RS.generate_upload_token(upopts)
|
uptoken = Qiniu::RS.generate_upload_token(upopts)
|
||||||
data = Qiniu::RS.upload_file :uptoken => uptoken, :file => local_file, :bucket => @test_image_bucket, :key => @test_image_key
|
data = Qiniu::RS.upload_file :uptoken => uptoken, :file => local_file, :bucket => @test_image_bucket, :key => @test_image_key
|
||||||
puts data.inspect
|
puts data.inspect
|
||||||
end
|
end
|
||||||
|
|
||||||
after :all do
|
after :all do
|
||||||
result = Qiniu::RS.drop(@bucket)
|
#result = Qiniu::RS.unpublish(@domain)
|
||||||
puts result.inspect
|
#result.should_not be_false
|
||||||
result.should_not be_false
|
|
||||||
|
result1 = Qiniu::RS.drop(@bucket)
|
||||||
|
puts result1.inspect
|
||||||
|
result1.should_not be_false
|
||||||
|
|
||||||
result2 = Qiniu::RS.drop(@test_image_bucket)
|
result2 = Qiniu::RS.drop(@test_image_bucket)
|
||||||
puts result2.inspect
|
puts result2.inspect
|
||||||
@@ -79,6 +84,7 @@ module Qiniu
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
context ".set_watermark" do
|
context ".set_watermark" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
options = {
|
options = {
|
||||||
@@ -97,6 +103,7 @@ module Qiniu
|
|||||||
puts result.inspect
|
puts result.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
=end
|
||||||
|
|
||||||
context ".put_auth" do
|
context ".put_auth" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
@@ -148,16 +155,39 @@ module Qiniu
|
|||||||
result.should_not be_false
|
result.should_not be_false
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should raise MissingArgsError" do
|
||||||
|
uptoken_opts = {:scope => @bucket, :escape => 0}
|
||||||
|
upload_opts = {
|
||||||
|
:uptoken => Qiniu::RS.generate_upload_token(uptoken_opts),
|
||||||
|
:file => __FILE__,
|
||||||
|
:key => @key,
|
||||||
|
:enable_crc32_check => true
|
||||||
|
}
|
||||||
|
lambda { Qiniu::RS.upload_file(upload_opts) }.should raise_error(RS::MissingArgsError)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should raise NoSuchFileError" do
|
||||||
|
uptoken_opts = {:scope => @bucket, :escape => 0}
|
||||||
|
upload_opts = {
|
||||||
|
:uptoken => Qiniu::RS.generate_upload_token(uptoken_opts),
|
||||||
|
:file => 'no_this_file',
|
||||||
|
:bucket => @bucket,
|
||||||
|
:key => @key,
|
||||||
|
:enable_crc32_check => true
|
||||||
|
}
|
||||||
|
lambda { Qiniu::RS.upload_file(upload_opts) }.should raise_error(RS::NoSuchFileError)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context ".resumable_upload_file" do
|
context ".resumable_upload_file" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
# generate bigfile for testing
|
# generate bigfile for testing
|
||||||
localfile = "test_bigfile"
|
localfile = "test_bigfile"
|
||||||
File.open(localfile, "w"){|f| 5242888.times{f.write(Random.rand(9).to_s)}}
|
File.open(localfile, "w"){|f| 5242888.times{f.write(rand(9).to_s)}}
|
||||||
key = Digest::SHA1.hexdigest(localfile+Time.now.to_s)
|
key = Digest::SHA1.hexdigest(localfile+Time.now.to_s)
|
||||||
# generate the upload token
|
# generate the upload token
|
||||||
uptoken_opts = {:scope => @bucket, :expires_in => 3600, :customer => "awhy.xu@gmail.com", :escape => 0}
|
uptoken_opts = {:scope => @bucket, :expires_in => 3600, :customer => "why404@gmail.com", :escape => 0}
|
||||||
uptoken = Qiniu::RS.generate_upload_token(uptoken_opts)
|
uptoken = Qiniu::RS.generate_upload_token(uptoken_opts)
|
||||||
# uploading
|
# uploading
|
||||||
upload_opts = {
|
upload_opts = {
|
||||||
@@ -248,19 +278,69 @@ module Qiniu
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
=begin
|
||||||
context ".publish" do
|
context ".publish" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
result = Qiniu::RS.publish(@domain, @bucket)
|
result = Qiniu::RS.publish(@domain, @bucket)
|
||||||
result.should_not be_false
|
result.should_not be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
=end
|
||||||
|
|
||||||
|
=begin
|
||||||
context ".unpublish" do
|
context ".unpublish" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
result = Qiniu::RS.unpublish(@domain)
|
result = Qiniu::RS.unpublish(@domain)
|
||||||
result.should_not be_false
|
result.should_not be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
=end
|
||||||
|
|
||||||
|
context ".batch_copy" do
|
||||||
|
it "should works" do
|
||||||
|
result = Qiniu::RS.batch_copy [@bucket, @key, @bucket, @key2]
|
||||||
|
result.should_not be_false
|
||||||
|
|
||||||
|
#result2 = Qiniu::RS.stat(@bucket, @key2)
|
||||||
|
#result2.should_not be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context ".batch_move" do
|
||||||
|
it "should works" do
|
||||||
|
result = Qiniu::RS::RS.batch_move [@bucket, @key, @bucket, @key2]
|
||||||
|
result.should_not be_false
|
||||||
|
|
||||||
|
#result2 = Qiniu::RS.stat(@bucket, @key2)
|
||||||
|
#result2.should_not be_false
|
||||||
|
|
||||||
|
result3 = Qiniu::RS.batch_move [@bucket, @key2, @bucket, @key]
|
||||||
|
result3.should_not be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context ".move" do
|
||||||
|
it "should works" do
|
||||||
|
result = Qiniu::RS.move(@bucket, @key, @bucket, @key2)
|
||||||
|
result.should_not be_false
|
||||||
|
|
||||||
|
result2 = Qiniu::RS.stat(@bucket, @key2)
|
||||||
|
result2.should_not be_false
|
||||||
|
|
||||||
|
result3 = Qiniu::RS.move(@bucket, @key2, @bucket, @key)
|
||||||
|
result3.should_not be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context ".copy" do
|
||||||
|
it "should works" do
|
||||||
|
result = Qiniu::RS.copy(@bucket, @key, @bucket, @key2)
|
||||||
|
result.should_not be_false
|
||||||
|
|
||||||
|
#result2 = Qiniu::RS.stat(@bucket, @key2)
|
||||||
|
#result2.should_not be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context ".delete" do
|
context ".delete" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
@@ -307,10 +387,6 @@ module Qiniu
|
|||||||
data.should_not be_empty
|
data.should_not be_empty
|
||||||
puts data.inspect
|
puts data.inspect
|
||||||
|
|
||||||
dest_bucket = "test_thumbnails_bucket"
|
|
||||||
result = Qiniu::RS.mkbucket(dest_bucket)
|
|
||||||
result.should_not be_false
|
|
||||||
|
|
||||||
dest_key = "cropped-" + @test_image_key
|
dest_key = "cropped-" + @test_image_key
|
||||||
src_img_url = data["url"]
|
src_img_url = data["url"]
|
||||||
mogrify_options = {
|
mogrify_options = {
|
||||||
@@ -322,7 +398,7 @@ module Qiniu
|
|||||||
:format => "jpg",
|
:format => "jpg",
|
||||||
:auto_orient => true
|
:auto_orient => true
|
||||||
}
|
}
|
||||||
result2 = Qiniu::RS.image_mogrify_save_as(dest_bucket, dest_key, src_img_url, mogrify_options)
|
result2 = Qiniu::RS.image_mogrify_save_as(@test_image_bucket, dest_key, src_img_url, mogrify_options)
|
||||||
result2.should_not be_false
|
result2.should_not be_false
|
||||||
result2.should_not be_empty
|
result2.should_not be_empty
|
||||||
puts result2.inspect
|
puts result2.inspect
|
||||||
@@ -331,9 +407,19 @@ module Qiniu
|
|||||||
|
|
||||||
context ".generate_upload_token" do
|
context ".generate_upload_token" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
data = Qiniu::RS.generate_upload_token({:scope => 'test_bucket', :expires_in => 3600, :escape => 0})
|
data = Qiniu::RS.generate_upload_token({:scope => @bucket, :expires_in => 3600, :escape => 0})
|
||||||
data.should_not be_empty
|
data.should_not be_empty
|
||||||
puts data.inspect
|
puts data.inspect
|
||||||
|
data.split(":").length.should == 3
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context ".generate_download_token" do
|
||||||
|
it "should works" do
|
||||||
|
data = Qiniu::RS.generate_download_token({:expires_in => 1, :pattern => 'http://*.dn.qbox.me/*'})
|
||||||
|
data.should_not be_empty
|
||||||
|
puts data.inspect
|
||||||
|
data.split(":").length.should == 3
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -6,7 +6,6 @@ require 'rspec'
|
|||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.before :all do
|
config.before :all do
|
||||||
Qiniu::RS.establish_connection! :access_key => "iN7NgwM31j4-BZacMjPrOQBs34UG1maYCAQmhdCV",
|
Qiniu::RS.establish_connection! :access_key => ENV["QINIU_ACCESS_KEY"], :secret_key => ENV["QINIU_SECRET_KEY"]
|
||||||
:secret_key => "6QTOr2Jg1gcZEWDQXKOGZh5PziC2MCV5KsntT70j"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user