Sha256: b5ee04df9d6a956e9ed3853c566ffd9f7c2872b0257eb594b46cb490c9148377

Contents?: true

Size: 1.67 KB

Versions: 10

Compression:

Stored size: 1.67 KB

Contents

# coding: utf-8
module Reapal
  module Api
    module CommunicateResultHelper

      # 操作类的 api,统一返回处理
      #
      # @param request_type [Symbole] 操作类(:operate)/查询类(:query)
      # @param service [ String ] 富民的服务
      # @param params [ Hash ] 参数
      # @param post_path [ String ] post url
      # @param fail_codes [ Array ] 错误返回码
      # @param success_codes [ String ] 【业务】【明确的】正确返回码(而不是申请成功这类)
      #
      # @return [ Hash ] 结果集(见通用返回)
      #
      def operate_post(request_type, service, params, post_path, fail_codes, success_codes, version='3.0')
        response = Http.post(service, params, @config, post_path, version)

        res = Reapal::Utils.api_result(params, response)

        if :operate == request_type
          # 向服务器发送操作,超时类的都应该当 pending 处理
          return res if response.http_pending?
        elsif :query == request_type
          # 查询类 api,http 没成功都返回 pending
          return res unless response.http_success?
        else
          raise "未知的请求类型,请选择设置:操作类(:operate)/查询类(:query)"
        end

        # 确定的错误
        if fail_codes.include?(response.data[:errorCode])
          res[:result] = "F"
          return res
        end

        # 其余 api 错误不知道
        return res unless response.data[:errorCode].nil?

        # 确定的成功返回码
        if success_codes.include?(response.data[:resultCode])
          res[:result] = "S"
        end

        res
      end

    end # CommunicateResultHelper
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
reapal-0.18.0 lib/reapal/api/api_helper.rb
reapal-0.17.0 lib/reapal/api/api_helper.rb
reapal-0.16.0 lib/reapal/api/api_helper.rb
reapal-0.15.0 lib/reapal/api/api_helper.rb
reapal-0.14.0 lib/reapal/api/api_helper.rb
reapal-0.13.0 lib/reapal/api/api_helper.rb
reapal-0.12.0 lib/reapal/api/api_helper.rb
reapal-0.11.0 lib/reapal/api/api_helper.rb
reapal-0.10.1 lib/reapal/api/api_helper.rb
reapal-0.10.0 lib/reapal/api/api_helper.rb