Sha256: d592eb54aa0825167825ac5513ce74d9b7d814ad400695b2854f42370a13b21e

Contents?: true

Size: 1.85 KB

Versions: 17

Compression:

Stored size: 1.85 KB

Contents

module Biro
  module Bacen
    class Request < BaseRequest
      include Utils::Soap

      def development_url
        'https://scr.bcb.gov.br/wsscr/ControleCliente.xml'
      end

      def production_url
        'https://scr.bcb.gov.br/wsscr/ControleCliente.xml'
      end

      def required_params
        [:username, :password]
      end

      def find(document, date)
        begin
          params = {}
          get_parameters(params, document, date)
          result = soap.call(:get_resumo_do_cliente, message: params)
        rescue => e
          Biro.log(:warn, "Unable to process Bacen request")
          raise StandardError.new("Error at Bacen request: #{e.message}")
        end

        get_response result
      end

      private

      def get_response(result)
        response = Response.new(result)
        raise DocumentNotFoundError.new("Document not found: Code => #{response.result_validation[:codigo]} and Message => #{response.result_validation[:mensagem]}") if ['55'].include?(response.result_validation[:codigo])
        raise AuthenticationError.new("Authentication Error: Code => #{response.result_validation[:codigo]} and Message => #{response.result_validation[:mensagem]}") if ['62','63','53'].include?(response.result_validation[:codigo])
        raise StandardError.new("Error at Bacen Request: Code => #{response.result_validation[:codigo]} and Message => #{response.result_validation[:mensagem]}") unless response.result_validation.blank? || ['50'].include?(response.result_validation[:codigo])

        response
      end

      def savon_options
        { basic_auth: [@username, @password], headers: { 'SOAPAction' => ''} }
      end

      def get_parameters(params, document, date)
        params['codCliente'] = document
        params['tpCliente'] = 1
        params['dataBase'] = date
        params['autorizacao'] = 'S'
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
biro-0.7.1 lib/biro/gateways/bacen/request.rb
biro-0.7.0 lib/biro/gateways/bacen/request.rb
biro-0.6.10 lib/biro/gateways/bacen/request.rb
biro-0.6.9 lib/biro/gateways/bacen/request.rb
biro-0.6.8 lib/biro/gateways/bacen/request.rb
biro-0.6.7 lib/biro/gateways/bacen/request.rb
biro-0.6.6 lib/biro/gateways/bacen/request.rb
biro-0.6.5 lib/biro/gateways/bacen/request.rb
biro-0.6.4 lib/biro/gateways/bacen/request.rb
biro-0.6.3 lib/biro/gateways/bacen/request.rb
biro-0.6.2 lib/biro/gateways/bacen/request.rb
biro-0.6.1 lib/biro/gateways/bacen/request.rb
biro-0.5.1 lib/biro/gateways/bacen/request.rb
biro-0.4.1 lib/biro/gateways/bacen/request.rb
biro-0.4.0 lib/biro/gateways/bacen/request.rb
biro-0.3.0 lib/biro/gateways/bacen/request.rb
biro-0.2.0 lib/biro/gateways/bacen/request.rb