mirror of
https://github.com/wahyd4/ruby-sdk.git
synced 2026-08-10 05:18:37 +10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
957b537da0 | ||
|
|
4db869a53a | ||
|
|
a07b323d9d | ||
|
|
785d960ac0 | ||
|
|
e308ce1cfd | ||
|
|
1248008642 | ||
|
|
57d522ce39 | ||
|
|
c2b72befb9 | ||
|
|
2912ed9eea | ||
|
|
52057ff062 | ||
|
|
69c5eadede | ||
|
|
9969818797 | ||
|
|
44dcf0b622 | ||
|
|
6bf653f116 | ||
|
|
1b0491a2c9 | ||
|
|
f53dec3242 | ||
|
|
821d2363b3 | ||
|
|
e8fb64e7ec | ||
|
|
adb20cd815 | ||
|
|
fb9eb56bc0 | ||
|
|
813f57241d | ||
|
|
4a86397b3d | ||
|
|
fbea6bd019 | ||
|
|
ed6525a35e | ||
|
|
9d4316650d | ||
|
|
5713ad93e4 | ||
|
|
63a89b57ae | ||
|
|
65d71d12ae | ||
|
|
f1ed9a9783 | ||
|
|
5332645665 | ||
|
|
946442f782 | ||
|
|
8e4805cf68 | ||
|
|
78147d76f8 | ||
|
|
2bb0514df4 | ||
|
|
0bca27457a | ||
|
|
b21833779e | ||
|
|
a64fb3a63e | ||
|
|
0d2f2f23dd | ||
|
|
d0b4fb7412 | ||
|
|
40bf2cfbbb | ||
|
|
4e80a5ec98 | ||
|
|
4fbfdbf472 | ||
|
|
d14fe23e45 | ||
|
|
3d0578cb88 | ||
|
|
09b8921d20 | ||
|
|
7d65b22e2e | ||
|
|
8b000c0a98 | ||
|
|
f93e50c838 | ||
|
|
b8f43a1ded | ||
|
|
804fa4d5b6 | ||
|
|
0f2466d4c2 | ||
|
|
93c3cb8dea | ||
|
|
3cccf69b61 | ||
|
|
a70b6f5313 |
@@ -16,3 +16,4 @@ spec/reports
|
|||||||
test/tmp
|
test/tmp
|
||||||
test/version_tmp
|
test/version_tmp
|
||||||
tmp
|
tmp
|
||||||
|
.idea
|
||||||
|
|||||||
@@ -7,3 +7,6 @@ rvm:
|
|||||||
before_script:
|
before_script:
|
||||||
- export QINIU_ACCESS_KEY=QWYn5TFQsLLU1pL5MFEmX3s5DmHdUThav9WyOWOm
|
- export QINIU_ACCESS_KEY=QWYn5TFQsLLU1pL5MFEmX3s5DmHdUThav9WyOWOm
|
||||||
- export QINIU_SECRET_KEY=Bxckh6FA-Fbs9Yt3i3cbKVK22UPBmAOHJcL95pGz
|
- export QINIU_SECRET_KEY=Bxckh6FA-Fbs9Yt3i3cbKVK22UPBmAOHJcL95pGz
|
||||||
|
gemfile:
|
||||||
|
- Gemfile
|
||||||
|
- rails3/Gemfile
|
||||||
|
|||||||
+27
-1
@@ -1,5 +1,31 @@
|
|||||||
## CHANGE LOG
|
## 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
|
### 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/98](https://github.com/qiniu/ruby-sdk/pull/98)
|
||||||
@@ -21,7 +47,7 @@
|
|||||||
### v6.2.2
|
### v6.2.2
|
||||||
|
|
||||||
- 为/pfop接口添加`pipeline`参数,用于指明使用哪个命名转码队列。 [https://github.com/qiniu/ruby-sdk/pull/92](https://github.com/qiniu/ruby-sdk/pull/92)
|
- 为/pfop接口添加`pipeline`参数,用于指明使用哪个命名转码队列。 [https://github.com/qiniu/ruby-sdk/pull/92](https://github.com/qiniu/ruby-sdk/pull/92)
|
||||||
- 为authorize_download_url()添加`:fop`参数,用于生成含数据处理指令的授权下载URL。
|
- 为authorize_download_url()添加`:fop`参数,用于生成含数据处理指令的授权下载URL。
|
||||||
|
|
||||||
### v6.2.1
|
### v6.2.1
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
# Specify your gem's dependencies in qiniu-s3.gemspec
|
# Specify your gem's dependencies in qiniu.gemspec
|
||||||
gemspec
|
gemspec :name => 'qiniu'
|
||||||
|
|
||||||
# platforms :jruby do
|
# platforms :jruby do
|
||||||
# gem "jruby-openssl"
|
# gem "jruby-openssl"
|
||||||
|
|||||||
+28
-18
@@ -1,30 +1,37 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
qiniu (6.3.1)
|
qiniu (6.5.1)
|
||||||
json (~> 1.7)
|
json (~> 1.8)
|
||||||
mime-types (~> 1.19)
|
mime-types (~> 2.4.3)
|
||||||
rest-client (~> 1.6)
|
rest-client (~> 1.7.3)
|
||||||
ruby-hmac (~> 0.4)
|
ruby-hmac (~> 0.4)
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
diff-lcs (1.1.3)
|
diff-lcs (1.2.5)
|
||||||
fakeweb (1.3.0)
|
fakeweb (1.3.0)
|
||||||
json (1.8.1)
|
json (1.8.3)
|
||||||
mime-types (1.23)
|
mime-types (2.4.3)
|
||||||
rake (10.0.3)
|
netrc (0.11.0)
|
||||||
rest-client (1.6.7)
|
rake (10.4.2)
|
||||||
mime-types (>= 1.16)
|
rest-client (1.7.3)
|
||||||
rspec (2.12.0)
|
mime-types (>= 1.16, < 3.0)
|
||||||
rspec-core (~> 2.12.0)
|
netrc (~> 0.7)
|
||||||
rspec-expectations (~> 2.12.0)
|
rspec (3.2.0)
|
||||||
rspec-mocks (~> 2.12.0)
|
rspec-core (~> 3.2.0)
|
||||||
rspec-core (2.12.2)
|
rspec-expectations (~> 3.2.0)
|
||||||
rspec-expectations (2.12.1)
|
rspec-mocks (~> 3.2.0)
|
||||||
diff-lcs (~> 1.1.3)
|
rspec-core (3.2.2)
|
||||||
rspec-mocks (2.12.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)
|
ruby-hmac (0.4.0)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
@@ -35,3 +42,6 @@ DEPENDENCIES
|
|||||||
qiniu!
|
qiniu!
|
||||||
rake (>= 0.9)
|
rake (>= 0.9)
|
||||||
rspec (>= 2.11)
|
rspec (>= 2.11)
|
||||||
|
|
||||||
|
BUNDLED WITH
|
||||||
|
1.11.2
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
在您 Ruby 应用程序的 `Gemfile` 文件中,添加如下一行代码:
|
在您 Ruby 应用程序的 `Gemfile` 文件中,添加如下一行代码:
|
||||||
|
|
||||||
gem 'qiniu', '~> 6.3.1'
|
gem 'qiniu', '~> 6.4.1'
|
||||||
|
|
||||||
然后,在应用程序所在的目录下,可以运行 `bundle` 安装依赖包:
|
然后,在应用程序所在的目录下,可以运行 `bundle` 安装依赖包:
|
||||||
|
|
||||||
|
|||||||
+6
-2
@@ -64,12 +64,11 @@ module Qiniu
|
|||||||
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, raw_headers = Storage.upload_with_token(opts[:uptoken],
|
code, data, raw_headers = Storage.resumable_upload_with_token(opts[:uptoken],
|
||||||
opts[:file],
|
opts[:file],
|
||||||
opts[:bucket],
|
opts[:bucket],
|
||||||
opts[:key],
|
opts[:key],
|
||||||
opts[:mime_type],
|
opts[:mime_type],
|
||||||
opts[:note],
|
|
||||||
opts[:customer],
|
opts[:customer],
|
||||||
opts[:callback_params],
|
opts[:callback_params],
|
||||||
opts[:rotate])
|
opts[:rotate])
|
||||||
@@ -118,6 +117,11 @@ module Qiniu
|
|||||||
code == StatusOK
|
code == StatusOK
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fetch(bucket, target_url, key)
|
||||||
|
code, data = Storage.fetch(bucket, target_url, key)
|
||||||
|
code == StatusOK
|
||||||
|
end
|
||||||
|
|
||||||
def batch(command, bucket, keys)
|
def batch(command, bucket, keys)
|
||||||
code, data = Storage.batch(command, bucket, keys)
|
code, data = Storage.batch(command, bucket, keys)
|
||||||
code == StatusOK ? data : false
|
code == StatusOK ? data : false
|
||||||
|
|||||||
+49
-14
@@ -25,6 +25,18 @@ module Qiniu
|
|||||||
# 默认授权期1小时
|
# 默认授权期1小时
|
||||||
return Time.now.to_i + DEFAULT_AUTH_SECONDS
|
return Time.now.to_i + DEFAULT_AUTH_SECONDS
|
||||||
end # calculate_deadline
|
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
|
end # class << self
|
||||||
|
|
||||||
class PutPolicy
|
class PutPolicy
|
||||||
@@ -49,7 +61,9 @@ module Qiniu
|
|||||||
:return_url => "returnUrl" ,
|
:return_url => "returnUrl" ,
|
||||||
:return_body => "returnBody" ,
|
:return_body => "returnBody" ,
|
||||||
:callback_url => "callbackUrl" ,
|
:callback_url => "callbackUrl" ,
|
||||||
|
:callback_host => "callbackHost" ,
|
||||||
:callback_body => "callbackBody" ,
|
:callback_body => "callbackBody" ,
|
||||||
|
:callback_body_type => "callbackBodyType" ,
|
||||||
:persistent_ops => "persistentOps" ,
|
:persistent_ops => "persistentOps" ,
|
||||||
:persistent_notify_url => "persistentNotifyUrl" ,
|
:persistent_notify_url => "persistentNotifyUrl" ,
|
||||||
:persistent_pipeline => "persistentPipeline" ,
|
:persistent_pipeline => "persistentPipeline" ,
|
||||||
@@ -58,6 +72,7 @@ module Qiniu
|
|||||||
:deadline => "deadline" ,
|
:deadline => "deadline" ,
|
||||||
:insert_only => "insertOnly" ,
|
:insert_only => "insertOnly" ,
|
||||||
:fsize_limit => "fsizeLimit" ,
|
:fsize_limit => "fsizeLimit" ,
|
||||||
|
:callback_fetch_key => "callbackFetchKey" ,
|
||||||
:detect_mime => "detectMime" ,
|
:detect_mime => "detectMime" ,
|
||||||
:mime_limit => "mimeLimit"
|
:mime_limit => "mimeLimit"
|
||||||
} # PARAMS
|
} # PARAMS
|
||||||
@@ -166,7 +181,7 @@ module Qiniu
|
|||||||
end
|
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)
|
encoded_sign = Utils.urlsafe_base64_encode(sign)
|
||||||
|
|
||||||
### 生成下载授权凭证
|
### 生成下载授权凭证
|
||||||
@@ -191,11 +206,7 @@ module Qiniu
|
|||||||
return authorize_download_url(download_url, args)
|
return authorize_download_url(download_url, args)
|
||||||
end # authorize_download_url_2
|
end # authorize_download_url_2
|
||||||
|
|
||||||
def generate_acctoken(url, body = '')
|
def generate_acctoken_sign_with_mac(access_key, secret_key, url, body)
|
||||||
### 提取AK/SK信息
|
|
||||||
access_key = Config.settings[:access_key]
|
|
||||||
secret_key = Config.settings[:secret_key]
|
|
||||||
|
|
||||||
### 解析URL,生成待签名字符串
|
### 解析URL,生成待签名字符串
|
||||||
uri = URI.parse(url)
|
uri = URI.parse(url)
|
||||||
signing_str = uri.path
|
signing_str = uri.path
|
||||||
@@ -216,14 +227,13 @@ module Qiniu
|
|||||||
end
|
end
|
||||||
|
|
||||||
### 生成数字签名
|
### 生成数字签名
|
||||||
sign = HMAC::SHA1.new(secret_key).update(signing_str).digest
|
sign = calculate_hmac_sha1_digest(secret_key, signing_str)
|
||||||
encoded_sign = Utils.urlsafe_base64_encode(sign)
|
return Utils.urlsafe_base64_encode(sign)
|
||||||
|
end # generate_acctoken_sign_with_mac
|
||||||
|
|
||||||
### 生成管理授权凭证
|
def generate_acctoken(url, body = '')
|
||||||
acctoken = "#{access_key}:#{encoded_sign}"
|
encoded_sign = generate_acctoken_sign_with_mac(Config.settings[:access_key], Config.settings[:secret_key], url, body)
|
||||||
|
return "#{Config.settings[:access_key]}:#{encoded_sign}"
|
||||||
### 返回管理授权凭证
|
|
||||||
return acctoken
|
|
||||||
end # generate_acctoken
|
end # generate_acctoken
|
||||||
|
|
||||||
def generate_uptoken(put_policy)
|
def generate_uptoken(put_policy)
|
||||||
@@ -235,7 +245,7 @@ module Qiniu
|
|||||||
encoded_put_policy = Utils.urlsafe_base64_encode(put_policy.to_json)
|
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)
|
encoded_sign = Utils.urlsafe_base64_encode(sign)
|
||||||
|
|
||||||
### 生成上传授权凭证
|
### 生成上传授权凭证
|
||||||
@@ -244,6 +254,31 @@ module Qiniu
|
|||||||
### 返回上传授权凭证
|
### 返回上传授权凭证
|
||||||
return uptoken
|
return uptoken
|
||||||
end # generate_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 # class << self
|
||||||
|
|
||||||
end # module Auth
|
end # module Auth
|
||||||
|
|||||||
+6
-3
@@ -20,7 +20,9 @@ module Qiniu
|
|||||||
:content_type => 'application/x-www-form-urlencoded',
|
:content_type => 'application/x-www-form-urlencoded',
|
||||||
:auth_url => "https://acc.qbox.me/oauth2/token",
|
:auth_url => "https://acc.qbox.me/oauth2/token",
|
||||||
:rs_host => "http://rs.qiniu.com",
|
:rs_host => "http://rs.qiniu.com",
|
||||||
:up_host => "http://upload.qiniu.com",
|
:fetch_host => "http://iovip.qbox.me",
|
||||||
|
:rsf_host => "http://rsf.qbox.me",
|
||||||
|
:up_host => "http://up.qiniu.com",
|
||||||
:pub_host => "http://pu.qbox.me:10200",
|
:pub_host => "http://pu.qbox.me:10200",
|
||||||
:eu_host => "http://eu.qbox.me",
|
:eu_host => "http://eu.qbox.me",
|
||||||
:access_key => "",
|
:access_key => "",
|
||||||
@@ -33,13 +35,14 @@ module Qiniu
|
|||||||
:tmpdir => Dir.tmpdir + File::SEPARATOR + 'QiniuRuby'
|
: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
|
attr_reader :settings, :default_params
|
||||||
|
|
||||||
def load config_file
|
def load config_file
|
||||||
if File.exist?(config_file)
|
if File.exist?(config_file)
|
||||||
config_options = YAML.load_file(config_file)
|
config_options = YAML.load_file(config_file)
|
||||||
|
config_options.symbolize_keys!
|
||||||
initialize_connect(config_options)
|
initialize_connect(config_options)
|
||||||
else
|
else
|
||||||
raise MissingConfError, config_file
|
raise MissingConfError, config_file
|
||||||
@@ -47,7 +50,7 @@ module Qiniu
|
|||||||
end
|
end
|
||||||
|
|
||||||
def initialize_connect options = {}
|
def initialize_connect options = {}
|
||||||
@settings = DEFAULT_OPTIONS.merge(options)
|
@settings = DEFAULT_OPTIONS.merge!(options)
|
||||||
REQUIRED_OPTION_KEYS.each do |opt|
|
REQUIRED_OPTION_KEYS.each do |opt|
|
||||||
raise MissingArgsError, [opt] unless @settings.has_key?(opt)
|
raise MissingArgsError, [opt] unless @settings.has_key?(opt)
|
||||||
end
|
end
|
||||||
|
|||||||
+2
-2
@@ -65,7 +65,7 @@ module Qiniu
|
|||||||
end
|
end
|
||||||
|
|
||||||
content_type = resp_headers["content-type"][0]
|
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格式,则反序列化
|
# 如果是JSON格式,则反序列化
|
||||||
resp_body = Utils.safe_json_parse(resp_body)
|
resp_body = Utils.safe_json_parse(resp_body)
|
||||||
end
|
end
|
||||||
@@ -117,7 +117,7 @@ module Qiniu
|
|||||||
end
|
end
|
||||||
|
|
||||||
content_type = resp_headers["content-type"][0]
|
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格式,则反序列化
|
# 如果是JSON格式,则反序列化
|
||||||
resp_body = Utils.safe_json_parse(resp_body)
|
resp_body = Utils.safe_json_parse(resp_body)
|
||||||
end
|
end
|
||||||
|
|||||||
+65
-1
@@ -1,10 +1,48 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
# vim: sw=2 ts=2
|
# vim: sw=2 ts=2
|
||||||
|
|
||||||
|
require 'qiniu/adt'
|
||||||
require 'qiniu/http'
|
require 'qiniu/http'
|
||||||
|
|
||||||
module Qiniu
|
module Qiniu
|
||||||
module Storage
|
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
|
class << self
|
||||||
include Utils
|
include Utils
|
||||||
|
|
||||||
@@ -44,6 +82,11 @@ module Qiniu
|
|||||||
return HTTP.management_post(url)
|
return HTTP.management_post(url)
|
||||||
end # delete
|
end # delete
|
||||||
|
|
||||||
|
def fetch(bucket, target_url, key)
|
||||||
|
url = Config.settings[:fetch_host] + '/fetch/' + Utils.urlsafe_base64_encode(target_url) + '/to/' + encode_entry_uri(bucket, key)
|
||||||
|
return HTTP.management_post(url)
|
||||||
|
end # fetch
|
||||||
|
|
||||||
def batch(command, bucket, keys)
|
def batch(command, bucket, keys)
|
||||||
execs = []
|
execs = []
|
||||||
keys.each do |key|
|
keys.each do |key|
|
||||||
@@ -86,6 +129,26 @@ module Qiniu
|
|||||||
save_as(bucket, key, source_image_url, mogrify_params_string)
|
save_as(bucket, key, source_image_url, mogrify_params_string)
|
||||||
end # image_mogrify_save_as
|
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
|
private
|
||||||
|
|
||||||
def _generate_cp_or_mv_opstr(command, source_bucket, source_key, target_bucket, target_key)
|
def _generate_cp_or_mv_opstr(command, source_bucket, source_key, target_bucket, target_key)
|
||||||
@@ -102,6 +165,7 @@ module Qiniu
|
|||||||
url = Config.settings[:rs_host] + "/batch"
|
url = Config.settings[:rs_host] + "/batch"
|
||||||
return HTTP.management_post(url, execs.join("&"))
|
return HTTP.management_post(url, execs.join("&"))
|
||||||
end # _batch_cp_or_mv
|
end # _batch_cp_or_mv
|
||||||
end
|
|
||||||
|
end # class << self
|
||||||
end # module Storage
|
end # module Storage
|
||||||
end # module Qiniu
|
end # module Qiniu
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
|
require 'qiniu/http'
|
||||||
|
|
||||||
module Qiniu
|
module Qiniu
|
||||||
module Misc
|
module Misc
|
||||||
class << self
|
class << self
|
||||||
|
|||||||
Executable → Regular
+24
-6
@@ -47,16 +47,33 @@ module Qiniu
|
|||||||
def upload_with_token_2(uptoken,
|
def upload_with_token_2(uptoken,
|
||||||
local_file,
|
local_file,
|
||||||
key = nil,
|
key = nil,
|
||||||
x_vars = nil)
|
x_vars = nil,
|
||||||
|
opts = {})
|
||||||
|
|
||||||
|
file = File.new(local_file, 'rb')
|
||||||
|
return upload_with_token_2_file_stream(uptoken, file, key, x_vars, opts)
|
||||||
|
end # upload_with_token_2
|
||||||
|
|
||||||
|
def upload_with_token_2_file_stream(uptoken,
|
||||||
|
file,
|
||||||
|
key = nil,
|
||||||
|
x_vars = nil,
|
||||||
|
opts = {})
|
||||||
### 构造URL
|
### 构造URL
|
||||||
url = Config.settings[:up_host]
|
url = Config.settings[:up_host]
|
||||||
url[/\/*$/] = ''
|
url[/\/*$/] = ''
|
||||||
url += '/'
|
url += '/'
|
||||||
|
|
||||||
### 构造HTTP Body
|
### 构造HTTP Body
|
||||||
|
if not opts[:content_type].nil?
|
||||||
|
file.define_singleton_method("content_type") do
|
||||||
|
opts[:content_type]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
post_data = {
|
post_data = {
|
||||||
:file => File.new(local_file, 'rb'),
|
:file => file,
|
||||||
:multipart => true,
|
:multipart => true,
|
||||||
}
|
}
|
||||||
if not uptoken.nil?
|
if not uptoken.nil?
|
||||||
post_data[:token] = uptoken
|
post_data[:token] = uptoken
|
||||||
@@ -70,7 +87,7 @@ module Qiniu
|
|||||||
|
|
||||||
### 发送请求
|
### 发送请求
|
||||||
HTTP.api_post(url, post_data)
|
HTTP.api_post(url, post_data)
|
||||||
end # upload_with_token_2
|
end
|
||||||
|
|
||||||
### 授权举例
|
### 授权举例
|
||||||
# put_policy.bucket | put_policy.key | key | 语义 | 授权
|
# put_policy.bucket | put_policy.key | key | 语义 | 授权
|
||||||
@@ -84,13 +101,14 @@ module Qiniu
|
|||||||
def upload_with_put_policy(put_policy,
|
def upload_with_put_policy(put_policy,
|
||||||
local_file,
|
local_file,
|
||||||
key = nil,
|
key = nil,
|
||||||
x_vars = nil)
|
x_vars = nil,
|
||||||
|
opts = {})
|
||||||
uptoken = Auth.generate_uptoken(put_policy)
|
uptoken = Auth.generate_uptoken(put_policy)
|
||||||
if key.nil? then
|
if key.nil? then
|
||||||
key = put_policy.key
|
key = put_policy.key
|
||||||
end
|
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
|
end # upload_with_put_policy
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
module Qiniu
|
module Qiniu
|
||||||
module Version
|
module Version
|
||||||
MAJOR = 6
|
MAJOR = 6
|
||||||
MINOR = 3
|
MINOR = 5
|
||||||
PATCH = 1
|
PATCH = 1
|
||||||
# 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>
|
||||||
#
|
#
|
||||||
|
|||||||
+3
-3
@@ -21,9 +21,9 @@ Gem::Specification.new do |gem|
|
|||||||
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.8"
|
||||||
gem.add_runtime_dependency "rest-client", "~> 1.6"
|
gem.add_runtime_dependency "rest-client", "~> 1.7.3"
|
||||||
gem.add_runtime_dependency "mime-types", "~> 1.19"
|
gem.add_runtime_dependency "mime-types", "~> 2.4.3"
|
||||||
gem.add_runtime_dependency "ruby-hmac", "~> 0.4"
|
gem.add_runtime_dependency "ruby-hmac", "~> 0.4"
|
||||||
gem.add_runtime_dependency "jruby-openssl", "~> 0.7" if RUBY_PLATFORM == "java"
|
gem.add_runtime_dependency "jruby-openssl", "~> 0.7" if RUBY_PLATFORM == "java"
|
||||||
end
|
end
|
||||||
|
|||||||
Executable
+4
@@ -0,0 +1,4 @@
|
|||||||
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
|
# Specify your gem's dependencies in rails3/qiniu.gemspec
|
||||||
|
gemspec :name => 'qiniu'
|
||||||
Executable
+29
@@ -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
|
||||||
+56
-2
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require 'qiniu/auth'
|
require 'qiniu/auth'
|
||||||
|
require 'qiniu/config'
|
||||||
require 'qiniu/storage'
|
require 'qiniu/storage'
|
||||||
require 'digest/sha1'
|
require 'digest/sha1'
|
||||||
|
|
||||||
@@ -68,7 +69,60 @@ module Qiniu
|
|||||||
puts data.inspect
|
puts data.inspect
|
||||||
end
|
end
|
||||||
end
|
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
|
end # module Qiniu
|
||||||
|
|||||||
@@ -59,14 +59,18 @@ module Qiniu
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
=begin
|
|
||||||
context ".exif" do
|
context ".exif" do
|
||||||
it "should works" 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 data.inspect
|
||||||
|
puts headers.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
=end
|
|
||||||
|
|
||||||
context ".mogrify_preview_url" do
|
context ".mogrify_preview_url" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
|
|||||||
+26
-38
@@ -34,7 +34,7 @@ module Qiniu
|
|||||||
context ".buckets" do
|
context ".buckets" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
result = Qiniu.buckets
|
result = Qiniu.buckets
|
||||||
result.should_not be_false
|
expect(result).to_not be_empty
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -42,7 +42,7 @@ module Qiniu
|
|||||||
context ".set_protected" do
|
context ".set_protected" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
result = Qiniu.set_protected(@bucket, 1)
|
result = Qiniu.set_protected(@bucket, 1)
|
||||||
result.should_not be_false
|
expect(result).to eq(true)
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -50,7 +50,7 @@ module Qiniu
|
|||||||
context ".set_separator" do
|
context ".set_separator" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
result = Qiniu.set_separator(@bucket, "-")
|
result = Qiniu.set_separator(@bucket, "-")
|
||||||
result.should_not be_false
|
expect(result).to eq(true)
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -58,7 +58,7 @@ module Qiniu
|
|||||||
context ".set_style" do
|
context ".set_style" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
result = Qiniu.set_style(@bucket, "small.jpg", "imageMogr/auto-orient/thumbnail/!120x120r/gravity/center/crop/!120x120/quality/80")
|
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
|
puts result.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -66,7 +66,7 @@ module Qiniu
|
|||||||
context ".unset_style" do
|
context ".unset_style" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
result = Qiniu.unset_style(@bucket, "small.jpg")
|
result = Qiniu.unset_style(@bucket, "small.jpg")
|
||||||
result.should_not be_false
|
expect(result).to eq(true)
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -82,7 +82,7 @@ module Qiniu
|
|||||||
:enable_crc32_check => true
|
:enable_crc32_check => true
|
||||||
}
|
}
|
||||||
result = Qiniu.upload_file(upload_opts)
|
result = Qiniu.upload_file(upload_opts)
|
||||||
result.should_not be_false
|
expect(result).to_not be_empty
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -132,24 +132,22 @@ module Qiniu
|
|||||||
File.unlink(localfile) if File.exists?(localfile)
|
File.unlink(localfile) if File.exists?(localfile)
|
||||||
#expect
|
#expect
|
||||||
puts result1.inspect
|
puts result1.inspect
|
||||||
result1.should_not be_false
|
expect(result1).to_not be_empty
|
||||||
result1.should_not be_empty
|
|
||||||
#stat
|
#stat
|
||||||
result2 = Qiniu.stat(@bucket, key)
|
result2 = Qiniu.stat(@bucket, key)
|
||||||
puts result2.inspect
|
puts result2.inspect
|
||||||
result2.should_not be_false
|
expect(result2).to_not be_empty
|
||||||
#delete
|
#delete
|
||||||
result3 = Qiniu.delete(@bucket, key)
|
result3 = Qiniu.delete(@bucket, key)
|
||||||
puts result3.inspect
|
puts result3.inspect
|
||||||
result3.should_not be_false
|
expect(result3).to eq(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context ".stat" do
|
context ".stat" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
result = Qiniu.stat(@bucket, @key)
|
result = Qiniu.stat(@bucket, @key)
|
||||||
result.should_not be_false
|
expect(result).to_not be_empty
|
||||||
result.should_not be_empty
|
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -157,8 +155,7 @@ module Qiniu
|
|||||||
context ".get" do
|
context ".get" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
result = Qiniu.get(@bucket, @key, "qiniu_spec.rb", 10)
|
result = Qiniu.get(@bucket, @key, "qiniu_spec.rb", 10)
|
||||||
result.should_not be_false
|
expect(result).to_not be_empty
|
||||||
result.should_not be_empty
|
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -166,8 +163,7 @@ module Qiniu
|
|||||||
context ".download" do
|
context ".download" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
result = Qiniu.download(@bucket, @key, "rs_spec.rb", 10)
|
result = Qiniu.download(@bucket, @key, "rs_spec.rb", 10)
|
||||||
result.should_not be_false
|
expect(result).to_not be_empty
|
||||||
result.should_not be_empty
|
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -175,8 +171,7 @@ module Qiniu
|
|||||||
context ".batch" do
|
context ".batch" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
result = Qiniu.batch("stat", @bucket, [@key])
|
result = Qiniu.batch("stat", @bucket, [@key])
|
||||||
result.should_not be_false
|
expect(result).to_not be_empty
|
||||||
result.should_not be_empty
|
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -184,8 +179,7 @@ module Qiniu
|
|||||||
context ".batch_stat" do
|
context ".batch_stat" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
result = Qiniu.batch_stat(@bucket, [@key])
|
result = Qiniu.batch_stat(@bucket, [@key])
|
||||||
result.should_not be_false
|
expect(result).to_not be_empty
|
||||||
result.should_not be_empty
|
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -193,8 +187,7 @@ module Qiniu
|
|||||||
context ".batch_get" do
|
context ".batch_get" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
result = Qiniu.batch_get(@bucket, [@key])
|
result = Qiniu.batch_get(@bucket, [@key])
|
||||||
result.should_not be_false
|
expect(result).to_not be_empty
|
||||||
result.should_not be_empty
|
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -202,8 +195,7 @@ module Qiniu
|
|||||||
context ".batch_download" do
|
context ".batch_download" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
result = Qiniu.batch_download(@bucket, [@key])
|
result = Qiniu.batch_download(@bucket, [@key])
|
||||||
result.should_not be_false
|
expect(result).to_not be_empty
|
||||||
result.should_not be_empty
|
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -236,42 +228,40 @@ module Qiniu
|
|||||||
context ".move" do
|
context ".move" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
result = Qiniu.move(@bucket, @key, @bucket, @key2)
|
result = Qiniu.move(@bucket, @key, @bucket, @key2)
|
||||||
result.should_not be_false
|
expect(result).to eq(true)
|
||||||
|
|
||||||
result2 = Qiniu.stat(@bucket, @key2)
|
result2 = Qiniu.stat(@bucket, @key2)
|
||||||
result2.should_not be_false
|
expect(result2).to_not be_empty
|
||||||
|
|
||||||
result3 = Qiniu.move(@bucket, @key2, @bucket, @key)
|
result3 = Qiniu.move(@bucket, @key2, @bucket, @key)
|
||||||
result3.should_not be_false
|
expect(result3).to eq(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context ".copy" do
|
context ".copy" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
result = Qiniu.copy(@bucket, @key, @bucket, @key2)
|
result = Qiniu.copy(@bucket, @key, @bucket, @key2)
|
||||||
result.should_not be_false
|
expect(result).to eq(true)
|
||||||
|
|
||||||
result3 = Qiniu.delete(@bucket, @key2)
|
result3 = Qiniu.delete(@bucket, @key2)
|
||||||
result3.should_not be_false
|
expect(result3).to eq(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context ".delete" do
|
context ".delete" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
result = Qiniu.delete(@bucket, @key)
|
result = Qiniu.delete(@bucket, @key)
|
||||||
result.should_not be_false
|
expect(result).to eq(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context ".image_info" do
|
context ".image_info" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
data = Qiniu.get(@test_image_bucket, @test_image_key)
|
data = Qiniu.get(@test_image_bucket, @test_image_key)
|
||||||
data.should_not be_false
|
expect(data).to_not be_empty
|
||||||
data.should_not be_empty
|
|
||||||
puts data.inspect
|
puts data.inspect
|
||||||
result = Qiniu.image_info(data["url"])
|
result = Qiniu.image_info(data["url"])
|
||||||
result.should_not be_false
|
expect(result).to_not be_empty
|
||||||
result.should_not be_empty
|
|
||||||
puts result.inspect
|
puts result.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -279,8 +269,7 @@ module Qiniu
|
|||||||
context ".image_mogrify_save_as" do
|
context ".image_mogrify_save_as" do
|
||||||
it "should works" do
|
it "should works" do
|
||||||
data = Qiniu.get(@test_image_bucket, @test_image_key)
|
data = Qiniu.get(@test_image_bucket, @test_image_key)
|
||||||
data.should_not be_false
|
expect(data).to_not be_empty
|
||||||
data.should_not be_empty
|
|
||||||
puts data.inspect
|
puts data.inspect
|
||||||
|
|
||||||
dest_key = "cropped-" + @test_image_key
|
dest_key = "cropped-" + @test_image_key
|
||||||
@@ -295,8 +284,7 @@ module Qiniu
|
|||||||
:auto_orient => true
|
:auto_orient => true
|
||||||
}
|
}
|
||||||
result2 = Qiniu.image_mogrify_save_as(@test_image_bucket, dest_key, src_img_url, mogrify_options)
|
result2 = Qiniu.image_mogrify_save_as(@test_image_bucket, dest_key, src_img_url, mogrify_options)
|
||||||
result2.should_not be_false
|
expect(result2).to_not be_empty
|
||||||
result2.should_not be_empty
|
|
||||||
puts result2.inspect
|
puts result2.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ RSpec.configure do |config|
|
|||||||
config.before :all do
|
config.before :all do
|
||||||
Qiniu.establish_connection! :access_key => ENV["QINIU_ACCESS_KEY"], :secret_key => ENV["QINIU_SECRET_KEY"]
|
Qiniu.establish_connection! :access_key => ENV["QINIU_ACCESS_KEY"], :secret_key => ENV["QINIU_SECRET_KEY"]
|
||||||
end
|
end
|
||||||
|
config.before :each, :not_set_ak_sk => true do
|
||||||
|
Qiniu.establish_connection! :access_key => nil, :secret_key => nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_unique_bucket (bucket)
|
def make_unique_bucket (bucket)
|
||||||
|
|||||||
Reference in New Issue
Block a user