Method: PolylinkApi::Helper.get_response

Defined in:
lib/polylink_api/helper.rb

.get_response(method, response_body) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/polylink_api/helper.rb', line 47

def self.get_response(method, response_body){}
  response_sym = "#{method}_response".to_sym
  raise InvalidResponseError, "没有返回正确的数据" if response_body.nil? || response_body[response_sym].nil?
  result = response_body[response_sym][:out]
  code = get_response_code(result)

  if STATUS_CODES.include? code
    case code
      when "501" then raise AuthenticationError, "无法登陆远程服务器"
      when "502" then raise InvalidParameterError, "参数格式错误"
      when "510" then raise InvalidDataError, "开始时间不能大于结束时间"
      when "511" then raise InvalidDataError, "查询类型和开始结束时间不匹配"
      when "516" then raise InvalidDataError, "V2CID已存在"
      when "517" then raise InvalidDataError, "DID不存在"
      when "518" then raise InvalidDataError, "V2CID不存在"
      when "519" then raise InvalidDataError, "虚拟总机DID不存在"
      when "600" then raise InvalidResponseError, "远程服务器发生未知错误"
    end
    return get_response_data(method, result)
  else
    raise InvalidResponseError, "无法解析服务器响应"
  end
end