class RockFintech::Http::Response

Attributes

data[RW]
data_valid[RW]
flow_id[RW]
http_response[RW]
raw_body[RW]
service[RW]

Public Class Methods

new(params) click to toggle source
# File lib/rock_fintech/http/response.rb, line 10
def initialize(params)
  self.data_valid = true

  params.each do |key, value|
    self.instance_variable_set("@#{key}", value)
  end

  self.data = {} if self.data.nil? # 默认一定要有

  unless self.data_valid
    self.data[:code] = 'sign_valid_fail'
    self.data[:msg] = '数据签名错误'
  end

end

Public Instance Methods

[](key) click to toggle source
# File lib/rock_fintech/http/response.rb, line 26
def [] key
  instance_variable_get("#{key}")
end
http_fail?() click to toggle source
# File lib/rock_fintech/http/response.rb, line 43
def http_fail?
  # 而 400 错误一般都是地址不存在或者没有权限,都当成错误处理
  http_response && http_response.code.to_s == '404'
end
http_pending?() click to toggle source
# File lib/rock_fintech/http/response.rb, line 48
def http_pending?
  # nil 的时候是超时,非 404 的其他错误都是 pending
  http_response.nil? || (!http_success? && !http_fail?)
end
http_success?() click to toggle source
# File lib/rock_fintech/http/response.rb, line 39
def http_success?
  http_response && /^2/ =~ http_response.code.to_s
end
to_s() click to toggle source
# File lib/rock_fintech/http/response.rb, line 30
def to_s
  arr = ["{"]
  self.instance_variables.map{ |value|
    arr << "\t#{value.to_s} => #{self[value.to_sym]}"
  }
  arr << ["}"]
  arr.join("\n")
end