Class: Reapal::Http::Response
- Inherits:
-
Object
- Object
- Reapal::Http::Response
- Defined in:
- lib/reapal/http/response.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#data_valid ⇒ Object
Returns the value of attribute data_valid.
-
#flow_id ⇒ Object
Returns the value of attribute flow_id.
-
#http_response ⇒ Object
Returns the value of attribute http_response.
-
#raw_body ⇒ Object
Returns the value of attribute raw_body.
-
#service ⇒ Object
Returns the value of attribute service.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #http_fail? ⇒ Boolean
- #http_pending? ⇒ Boolean
- #http_success? ⇒ Boolean
-
#initialize(params) ⇒ Response
constructor
A new instance of Response.
- #to_s ⇒ Object
Constructor Details
#initialize(params) ⇒ Response
Returns a new instance of Response.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/reapal/http/response.rb', line 10 def initialize(params) self.data_valid = true params.each do |key, value| instance_variable_set("@#{key}", value) end self.data = {} if self.data.nil? # 默认一定要有 unless self.data_valid self.data[:errorCode] = 'sign_valid_fail' self.data[:errorMsg] = '数据签名错误' end end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
8 9 10 |
# File 'lib/reapal/http/response.rb', line 8 def data @data end |
#data_valid ⇒ Object
Returns the value of attribute data_valid.
8 9 10 |
# File 'lib/reapal/http/response.rb', line 8 def data_valid @data_valid end |
#flow_id ⇒ Object
Returns the value of attribute flow_id.
6 7 8 |
# File 'lib/reapal/http/response.rb', line 6 def flow_id @flow_id end |
#http_response ⇒ Object
Returns the value of attribute http_response.
7 8 9 |
# File 'lib/reapal/http/response.rb', line 7 def http_response @http_response end |
#raw_body ⇒ Object
Returns the value of attribute raw_body.
7 8 9 |
# File 'lib/reapal/http/response.rb', line 7 def raw_body @raw_body end |
#service ⇒ Object
Returns the value of attribute service.
6 7 8 |
# File 'lib/reapal/http/response.rb', line 6 def service @service end |
Instance Method Details
#[](key) ⇒ Object
25 26 27 |
# File 'lib/reapal/http/response.rb', line 25 def [] key instance_variable_get("#{key}") end |
#http_fail? ⇒ Boolean
42 43 44 45 |
# File 'lib/reapal/http/response.rb', line 42 def http_fail? # 而 400 错误一般都是地址不存在或者没有权限,都当成错误处理 http_response && http_response.code.to_s == '404' end |
#http_pending? ⇒ Boolean
47 48 49 50 |
# File 'lib/reapal/http/response.rb', line 47 def http_pending? # nil 的时候是超时,非 404 的其他错误都是 pending http_response.nil? || (!http_success? && !http_fail?) end |
#http_success? ⇒ Boolean
38 39 40 |
# File 'lib/reapal/http/response.rb', line 38 def http_success? http_response && http_response.is_a?(Net::HTTPSuccess) end |
#to_s ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/reapal/http/response.rb', line 29 def to_s arr = ["{"] self.instance_variables.map{ |value| arr << "\t#{value.to_s} => #{self[value.to_sym]}" } arr << ["}"] arr.join("\n") end |