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 | ||
|
|
417b717bc5 |
@@ -1,5 +1,28 @@
|
||||
## 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)
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
qiniu (6.2.1)
|
||||
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` 安装依赖包:
|
||||
|
||||
|
||||
+33
-3
@@ -3,6 +3,7 @@
|
||||
|
||||
require 'hmac-sha1'
|
||||
require 'uri'
|
||||
require 'cgi'
|
||||
|
||||
require 'qiniu/exceptions'
|
||||
|
||||
@@ -51,6 +52,7 @@ module Qiniu
|
||||
:callback_body => "callbackBody" ,
|
||||
:persistent_ops => "persistentOps" ,
|
||||
:persistent_notify_url => "persistentNotifyUrl" ,
|
||||
:persistent_pipeline => "persistentPipeline" ,
|
||||
|
||||
# 数值类型参数
|
||||
:deadline => "deadline" ,
|
||||
@@ -138,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
|
||||
|
||||
### 生成数字签名
|
||||
@@ -161,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]
|
||||
|
||||
+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]
|
||||
|
||||
@@ -30,6 +30,7 @@ module Qiniu
|
||||
:key => "key",
|
||||
:fops => "fops",
|
||||
:notify_url => "notifyURL",
|
||||
:pipeline => "pipeline",
|
||||
|
||||
# 数值类型参数
|
||||
:force => "force"
|
||||
|
||||
@@ -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,7 +3,7 @@
|
||||
module Qiniu
|
||||
module Version
|
||||
MAJOR = 6
|
||||
MINOR = 2
|
||||
MINOR = 3
|
||||
PATCH = 1
|
||||
# Returns a version string by joining <tt>MAJOR</tt>, <tt>MINOR</tt>, and <tt>PATCH</tt> with <tt>'.'</tt>
|
||||
#
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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