mirror of
https://github.com/wahyd4/ruby-sdk.git
synced 2026-08-10 21:36:41 +10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
957b537da0 | ||
|
|
4db869a53a | ||
|
|
a07b323d9d | ||
|
|
f1ed9a9783 |
@@ -16,3 +16,4 @@ spec/reports
|
|||||||
test/tmp
|
test/tmp
|
||||||
test/version_tmp
|
test/version_tmp
|
||||||
tmp
|
tmp
|
||||||
|
.idea
|
||||||
|
|||||||
+7
-4
@@ -3,7 +3,7 @@ PATH
|
|||||||
specs:
|
specs:
|
||||||
qiniu (6.5.1)
|
qiniu (6.5.1)
|
||||||
json (~> 1.8)
|
json (~> 1.8)
|
||||||
mime-types (~> 1.19)
|
mime-types (~> 2.4.3)
|
||||||
rest-client (~> 1.7.3)
|
rest-client (~> 1.7.3)
|
||||||
ruby-hmac (~> 0.4)
|
ruby-hmac (~> 0.4)
|
||||||
|
|
||||||
@@ -12,9 +12,9 @@ GEM
|
|||||||
specs:
|
specs:
|
||||||
diff-lcs (1.2.5)
|
diff-lcs (1.2.5)
|
||||||
fakeweb (1.3.0)
|
fakeweb (1.3.0)
|
||||||
json (1.8.2)
|
json (1.8.3)
|
||||||
mime-types (1.25.1)
|
mime-types (2.4.3)
|
||||||
netrc (0.10.3)
|
netrc (0.11.0)
|
||||||
rake (10.4.2)
|
rake (10.4.2)
|
||||||
rest-client (1.7.3)
|
rest-client (1.7.3)
|
||||||
mime-types (>= 1.16, < 3.0)
|
mime-types (>= 1.16, < 3.0)
|
||||||
@@ -42,3 +42,6 @@ DEPENDENCIES
|
|||||||
qiniu!
|
qiniu!
|
||||||
rake (>= 0.9)
|
rake (>= 0.9)
|
||||||
rspec (>= 2.11)
|
rspec (>= 2.11)
|
||||||
|
|
||||||
|
BUNDLED WITH
|
||||||
|
1.11.2
|
||||||
|
|||||||
@@ -117,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
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ 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",
|
||||||
|
:fetch_host => "http://iovip.qbox.me",
|
||||||
:rsf_host => "http://rsf.qbox.me",
|
:rsf_host => "http://rsf.qbox.me",
|
||||||
:up_host => "http://up.qiniu.com",
|
:up_host => "http://up.qiniu.com",
|
||||||
:pub_host => "http://pu.qbox.me:10200",
|
:pub_host => "http://pu.qbox.me:10200",
|
||||||
|
|||||||
@@ -82,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|
|
||||||
|
|||||||
+13
-4
@@ -49,13 +49,22 @@ module Qiniu
|
|||||||
key = nil,
|
key = nil,
|
||||||
x_vars = nil,
|
x_vars = nil,
|
||||||
opts = {})
|
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
|
||||||
file = File.new(local_file, 'rb')
|
|
||||||
if not opts[:content_type].nil?
|
if not opts[:content_type].nil?
|
||||||
file.define_singleton_method("content_type") do
|
file.define_singleton_method("content_type") do
|
||||||
opts[:content_type]
|
opts[:content_type]
|
||||||
@@ -63,8 +72,8 @@ module Qiniu
|
|||||||
end
|
end
|
||||||
|
|
||||||
post_data = {
|
post_data = {
|
||||||
:file => file,
|
:file => file,
|
||||||
:multipart => true,
|
:multipart => true,
|
||||||
}
|
}
|
||||||
if not uptoken.nil?
|
if not uptoken.nil?
|
||||||
post_data[:token] = uptoken
|
post_data[:token] = uptoken
|
||||||
@@ -78,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 | 语义 | 授权
|
||||||
|
|||||||
Reference in New Issue
Block a user