class TencentCloud::Common::ApiRequset
common http request class
def initialize(scheme, host, port = nil, timeout = 60, proxy = nil)
def initialize(scheme, host, port = nil, timeout = 60, proxy = nil) port = 443 if scheme == 'https' if proxy.nil? @conn = Net::HTTP.new(host, port) else p = URI(proxy) @conn = Net::HTTP.new(host, port, p.host, p.port, p.user, p.pass) end @conn.use_ssl = scheme == 'https' @conn.read_timeout = timeout end
def send_request(request, keep_alive = false)
def send_request(request, keep_alive = false) uri = URI("#{request.scheme}://#{request.host}#{request.uri}") @conn.keep_alive_timeout = 20 if keep_alive @conn.start do |http| case request.method when 'GET' uri.query = request.data req = Net::HTTP::Get.new uri when 'POST' req = Net::HTTP::Post.new uri req.body = request.data else raise TencentCloudSDKException.new('ClientParamsError', 'Method only support (GET, POST)') end request.header.each do |k, v| req[k] = v end resp = http.request req BaseResponse.new(resp.code, resp.each_header.to_h, resp.read_body) end end