class Baidu::Response
Attributes
error_code[R]
error_msg[R]
request_id[R]
response_params[R]
result[R]
Public Class Methods
new(http_response=nil)
click to toggle source
# File lib/baidu/response.rb, line 7 def initialize(http_response=nil) if http_response.nil? @result = false else body = JSON.parse(http_response.body) if http_response.code.to_i == 200 # success @result = true @request_id = body["request_id"] @response_params = body["response_params"] else # failed @result = false @request_id = body["request_id"] @error_code = body["error_code"] @error_msg = body["error_msg"] end end end
Public Instance Methods
to_json()
click to toggle source
@return [Hash] 返回一个Hash
# File lib/baidu/response.rb, line 30 def to_json if @result { result: @result, request_id: @request_id, response_params: @response_params } else { result: @result, request_id: @request_id, error_code: @error_code, error_msg: @error_msg } end end