Class: Baidu::Response
- Inherits:
-
Object
- Object
- Baidu::Response
- Defined in:
- lib/baidu/response.rb
Instance Attribute Summary collapse
-
#error_code ⇒ Object
readonly
Returns the value of attribute error_code.
-
#error_msg ⇒ Object
readonly
Returns the value of attribute error_msg.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#response_params ⇒ Object
readonly
Returns the value of attribute response_params.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#initialize(http_response = nil) ⇒ Response
constructor
A new instance of Response.
-
#to_json ⇒ Hash
to_json.
Constructor Details
#initialize(http_response = nil) ⇒ Response
Returns a new instance of Response.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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 |
Instance Attribute Details
#error_code ⇒ Object (readonly)
Returns the value of attribute error_code.
5 6 7 |
# File 'lib/baidu/response.rb', line 5 def error_code @error_code end |
#error_msg ⇒ Object (readonly)
Returns the value of attribute error_msg.
5 6 7 |
# File 'lib/baidu/response.rb', line 5 def error_msg @error_msg end |
#request_id ⇒ Object (readonly)
Returns the value of attribute request_id.
5 6 7 |
# File 'lib/baidu/response.rb', line 5 def request_id @request_id end |
#response_params ⇒ Object (readonly)
Returns the value of attribute response_params.
5 6 7 |
# File 'lib/baidu/response.rb', line 5 def response_params @response_params end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
5 6 7 |
# File 'lib/baidu/response.rb', line 5 def result @result end |
Instance Method Details
#to_json ⇒ Hash
to_json
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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 |