mirror of
https://github.com/wahyd4/ruby-sdk.git
synced 2026-08-09 21:06:19 +10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
abadfe65ba | ||
|
|
006df109a7 |
+2
-2
@@ -1,7 +1,7 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
qiniu-rs (2.3.0)
|
||||
qiniu-rs (2.3.1)
|
||||
json (~> 1.7.3)
|
||||
mime-types (~> 1.19)
|
||||
rest-client (~> 1.6.7)
|
||||
@@ -12,7 +12,7 @@ GEM
|
||||
specs:
|
||||
diff-lcs (1.1.3)
|
||||
fakeweb (1.3.0)
|
||||
json (1.7.3)
|
||||
json (1.7.4)
|
||||
mime-types (1.19)
|
||||
rake (0.9.2.2)
|
||||
rest-client (1.6.7)
|
||||
|
||||
@@ -58,17 +58,17 @@ module Qiniu
|
||||
[code, data]
|
||||
end
|
||||
|
||||
def call_with_signature(url, data, retry_times = 0)
|
||||
code, data = http_request url, data, {:qbox_signature_token => generate_qbox_signature(url, data)}
|
||||
def call_with_signature(url, data, retry_times = 0, options = {})
|
||||
code, data = http_request url, data, options.merge!({:qbox_signature_token => generate_qbox_signature(url, data)})
|
||||
[code, data]
|
||||
end
|
||||
|
||||
def request(url, data = nil)
|
||||
def request(url, data = nil, options = {})
|
||||
begin
|
||||
if Config.settings[:access_key].empty? || Config.settings[:secret_key].empty?
|
||||
code, data = Auth.call_with_logged_in(url, data)
|
||||
else
|
||||
code, data = Auth.call_with_signature(url, data)
|
||||
code, data = Auth.call_with_signature(url, data, options)
|
||||
end
|
||||
rescue [MissingAccessToken, MissingRefreshToken, MissingUsernameOrPassword] => e
|
||||
Log.logger.error e
|
||||
|
||||
+2
-3
@@ -30,9 +30,8 @@ module Qiniu
|
||||
def put_file(local_file, bucket, key = nil, mime_type = nil, custom_meta = nil, enable_crc32_check = false)
|
||||
action_params = _generate_action_params(local_file, bucket, key, mime_type, custom_meta, enable_crc32_check)
|
||||
url = Config.settings[:io_host] + action_params
|
||||
post_data = {:file => File.new(local_file, 'rb'), :multipart => true}
|
||||
options = {:qbox_signature_token => Utils.generate_qbox_signature(url, nil)}
|
||||
Utils.send_multipart_request url, post_data, options
|
||||
options = {:content_type => 'application/octet-stream'}
|
||||
Auth.request url, ::IO.read(local_file), options
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
+2
-37
@@ -91,49 +91,14 @@ module Qiniu
|
||||
end
|
||||
end
|
||||
|
||||
def send_multipart_request(url, post_data, options = {})
|
||||
code, data = 0, {}
|
||||
begin
|
||||
header_options = {
|
||||
:accept => :json,
|
||||
:user_agent => Config.settings[:user_agent]
|
||||
}
|
||||
auth_token = nil
|
||||
if !options[:qbox_signature_token].nil? && !options[:qbox_signature_token].empty?
|
||||
auth_token = 'QBox ' + options[:qbox_signature_token]
|
||||
#elsif !options[:upload_signature_token].nil? && !options[:upload_signature_token].empty?
|
||||
#auth_token = 'UpToken ' + options[:upload_signature_token]
|
||||
elsif options[:access_token]
|
||||
auth_token = 'Bearer ' + options[:access_token]
|
||||
end
|
||||
header_options.merge!('Authorization' => auth_token) unless auth_token.nil?
|
||||
response = RestClient.post url, post_data, header_options
|
||||
body = response.respond_to?(:body) ? response.body : ""
|
||||
data = safe_json_parse(body) unless body.empty?
|
||||
code = response.code.to_i if response.respond_to?(:code)
|
||||
rescue Errno::ECONNRESET => err
|
||||
Log.logger.error err
|
||||
rescue => e
|
||||
Log.logger.warn "#{e.message} => Utils.http_request('#{url}')"
|
||||
res = e.response
|
||||
if e.respond_to? :response
|
||||
res = e.response
|
||||
code = res.code.to_i if res.respond_to? :code
|
||||
body = res.respond_to?(:body) ? res.body : ""
|
||||
data = safe_json_parse(body) unless body.empty?
|
||||
end
|
||||
end
|
||||
[code, data]
|
||||
end
|
||||
|
||||
def upload_multipart_data(url, filepath, action_string, callback_query_string = '')
|
||||
post_data = {
|
||||
:file => File.new(filepath, 'rb'),
|
||||
:params => callback_query_string,
|
||||
:action => action_string,
|
||||
:file => File.new(filepath, 'rb'),
|
||||
:multipart => true
|
||||
}
|
||||
send_multipart_request(url, post_data)
|
||||
http_request url, post_data
|
||||
end
|
||||
|
||||
def generate_query_string(params)
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
module Qiniu
|
||||
module RS
|
||||
VERSION = "2.3.0"
|
||||
VERSION = "2.3.1"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user