去掉对过时函数的调用。

This commit is contained in:
Liang Tao
2014-04-04 14:54:15 +08:00
parent efe6b50c50
commit 1d39aeec05
3 changed files with 6 additions and 37 deletions
Regular → Executable
+2 -10
View File
@@ -1,8 +1,6 @@
# -*- encoding: utf-8 -*-
# vim: sw=2 ts=2
require 'json'
module Qiniu
module HTTP
@@ -12,12 +10,6 @@ module Qiniu
return 200 <= http_code && http_code <= 299
end # is_response_ok?
def safe_json_parse(data)
JSON.parse(data)
rescue JSON::ParserError
{}
end # safe_json_parse
def generate_query_string(params)
if params.is_a?(Hash)
total_param = params.map { |key, value| %Q(#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s).gsub('+', '%20')}) }
@@ -71,7 +63,7 @@ module Qiniu
content_type = resp_headers["content-type"][0]
if !content_type.nil? && content_type == API_RESULT_MIMETYPE then
# 如果是JSON格式,则反序列化
resp_body = safe_json_parse(resp_body)
resp_body = Utils.safe_json_parse(resp_body)
end
return resp_code, resp_body, resp_headers
@@ -119,7 +111,7 @@ module Qiniu
content_type = resp_headers["content-type"][0]
if !content_type.nil? && content_type == API_RESULT_MIMETYPE then
# 如果是JSON格式,则反序列化
resp_body = safe_json_parse(resp_body)
resp_body = Utils.safe_json_parse(resp_body)
end
return resp_code, resp_body, resp_headers
+1 -1
View File
@@ -23,7 +23,7 @@ module Qiniu
signature += '?' + query_string if !query_string.nil? && !query_string.empty?
signature += "\n"
if @params.is_a?(Hash)
params_string = Utils.generate_query_string(@params)
params_string = HTTP.generate_query_string(@params)
signature += params_string
end
signature
+3 -26
View File
@@ -31,20 +31,13 @@ module Qiniu
{}
end
def is_response_ok?(status_code)
status_code/100 == 2
end
def response_error(status_code, errmsg)
[status_code, {"error" => errmsg}]
end
def debug(msg)
if Config.settings[:enable_debug]
Log.logger.debug(msg)
end
end
### 已过时,仅作为兼容接口保留
def send_request_with url, data = nil, options = {}
options[:method] = Config.settings[:method] unless options[:method]
options[:content_type] = Config.settings[:content_type] unless options[:content_type]
@@ -69,7 +62,7 @@ module Qiniu
response = RestClient.post(url, data, header_options)
end
code = response.respond_to?(:code) ? response.code.to_i : 0
unless is_response_ok?(code)
unless HTTP.is_response_ok?(code)
raise RequestFailed.new("Request Failed", response)
else
data = {}
@@ -80,6 +73,7 @@ module Qiniu
[code, data, raw_headers]
end # send_request_with
### 已过时,仅作为兼容接口保留
def http_request url, data = nil, options = {}
retry_times = 0
begin
@@ -107,23 +101,6 @@ module Qiniu
end
end
def upload_multipart_data(url, filepath, action_string, callback_query_string = '', uptoken = nil)
post_data = {
:params => callback_query_string,
:action => action_string,
:file => File.new(filepath, 'rb'),
:multipart => true
}
post_data[:auth] = uptoken unless uptoken.nil?
http_request url, post_data
end
def generate_query_string(params)
return params if params.is_a?(String)
total_param = params.map { |key, value| %Q(#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s).gsub('+', '%20')}) }
total_param.join("&")
end
def crc32checksum(filepath)
File.open(filepath, "rb") { |f| Zlib.crc32 f.read }
end