mirror of
https://github.com/wahyd4/ruby-sdk.git
synced 2026-08-09 21:06:19 +10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17f69da758 | ||
|
|
7280ca139a | ||
|
|
bc30779647 | ||
|
|
b6ab98b238 | ||
|
|
db62d9bcd3 | ||
|
|
089ebb2354 | ||
|
|
e97582e370 | ||
|
|
c01a43f3d9 | ||
|
|
4142c0182a | ||
|
|
3d9d50c3c5 | ||
|
|
e0c4a14e20 | ||
|
|
67c4d63a05 | ||
|
|
5ffe9daf58 | ||
|
|
a6debbec49 | ||
|
|
58dfe18328 | ||
|
|
1222559c71 | ||
|
|
31cbf3a6fd | ||
|
|
3504d39cd0 | ||
|
|
2322bbcd9c | ||
|
|
1ece11ea89 | ||
|
|
48abc7f7c1 | ||
|
|
4aca5af37e | ||
|
|
35661ebcbf | ||
|
|
c87b75d3cf | ||
|
|
328306814a | ||
|
|
e2d8a07882 | ||
|
|
8f11a43123 | ||
|
|
9d8f684eec | ||
|
|
244735a3f2 | ||
|
|
53d5f1bb4b | ||
|
|
de31e33460 | ||
|
|
01711a6fd4 | ||
|
|
5735dce6e9 | ||
|
|
788e21720b | ||
|
|
1f6e9ba47b | ||
|
|
a424c79dd6 | ||
|
|
7e66297bf9 | ||
|
|
ba91ee2377 | ||
|
|
417b717bc5 | ||
|
|
5d07bc517c | ||
|
|
ad579f402b | ||
|
|
34fc65bd99 | ||
|
|
ecbeb51339 | ||
|
|
ef0d79eb17 | ||
|
|
edc86e230e | ||
|
|
5718b720df | ||
|
|
5cc4db2231 |
@@ -1,13 +1,9 @@
|
||||
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
|
||||
|
||||
@@ -1,5 +1,32 @@
|
||||
## CHANGE LOG
|
||||
|
||||
### 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空间,原授权凭证生成类维持不变。
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
qiniu (6.2.0)
|
||||
qiniu (6.3.1)
|
||||
json (~> 1.7)
|
||||
mime-types (~> 1.19)
|
||||
rest-client (~> 1.6)
|
||||
|
||||
@@ -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.3.1'
|
||||
|
||||
然后,在应用程序所在的目录下,可以运行 `bundle` 安装依赖包:
|
||||
|
||||
|
||||
@@ -156,16 +156,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
|
||||
|
||||
@@ -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
|
||||
+35
-7
@@ -3,6 +3,7 @@
|
||||
|
||||
require 'hmac-sha1'
|
||||
require 'uri'
|
||||
require 'cgi'
|
||||
|
||||
require 'qiniu/exceptions'
|
||||
|
||||
@@ -51,15 +52,14 @@ module Qiniu
|
||||
:callback_body => "callbackBody" ,
|
||||
:persistent_ops => "persistentOps" ,
|
||||
:persistent_notify_url => "persistentNotifyUrl" ,
|
||||
:transform => "transform" ,
|
||||
:persistent_pipeline => "persistentPipeline" ,
|
||||
|
||||
# 数值类型参数
|
||||
:deadline => "deadline" ,
|
||||
:insert_only => "insertOnly" ,
|
||||
:fsize_limit => "fsizeLimit" ,
|
||||
:detect_mime => "detectMime" ,
|
||||
:mime_limit => "mimeLimit" ,
|
||||
:fop_timeout => "fopTimeout"
|
||||
:mime_limit => "mimeLimit"
|
||||
} # PARAMS
|
||||
|
||||
public
|
||||
@@ -140,16 +140,29 @@ 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
|
||||
|
||||
### 生成数字签名
|
||||
@@ -163,6 +176,21 @@ module Qiniu
|
||||
return "#{download_url}&token=#{dntoken}"
|
||||
end # authorize_download_url
|
||||
|
||||
### 对包含中文或其它 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(url, body = '')
|
||||
### 提取AK/SK信息
|
||||
access_key = Config.settings[:access_key]
|
||||
@@ -184,7 +212,7 @@ module Qiniu
|
||||
# 如果有Body,则也加上
|
||||
# (仅限于mime == "application/x-www-form-urlencoded"的情况)
|
||||
if body.is_a?(String) && !body.empty?
|
||||
signing_str += body
|
||||
signing_str += body
|
||||
end
|
||||
|
||||
### 生成数字签名
|
||||
|
||||
+3
-5
@@ -15,16 +15,14 @@ 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",
|
||||
:up_host => "http://up.qiniu.com",
|
||||
:up_host => "http://upload.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,7 +30,7 @@ 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]
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
require 'qiniu/image'
|
||||
require 'qiniu/pfop'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -60,18 +60,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)
|
||||
|
||||
Executable
+124
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -4,6 +4,8 @@ require 'hmac-sha1'
|
||||
require 'qiniu/config'
|
||||
require 'qiniu/utils'
|
||||
|
||||
### AccessToken 类已经过时,请改用 Qiniu::Auth.generate_acctoken 方法 ###
|
||||
|
||||
module Qiniu
|
||||
class AccessToken
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
module Qiniu
|
||||
module Version
|
||||
MAJOR = 6
|
||||
MINOR = 2
|
||||
PATCH = 0
|
||||
MINOR = 3
|
||||
PATCH = 1
|
||||
# Returns a version string by joining <tt>MAJOR</tt>, <tt>MINOR</tt>, and <tt>PATCH</tt> with <tt>'.'</tt>
|
||||
#
|
||||
# Example
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# vim: sw=2 ts=2
|
||||
|
||||
require 'spec_helper'
|
||||
require 'qiniu/auth'
|
||||
@@ -56,7 +57,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)
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
# -*- 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
|
||||
### 复用RubySDK-Test-Storage空间
|
||||
@bucket = 'RubySDK-Test-Storage'
|
||||
@bucket = make_unique_bucket(@bucket)
|
||||
|
||||
### 尝试创建空间
|
||||
code, data, headers = Qiniu::Storage.make_a_public_bucket(@bucket)
|
||||
puts code.inspect
|
||||
puts data.inspect
|
||||
puts headers.inspect
|
||||
|
||||
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
|
||||
### 不删除Bucket以备下次使用
|
||||
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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user