Sha256: bebe8fc18dfc21d0c7cfe7921dcf4002269fce1e3648be5d6c1e2adbc80a3767
Contents?: true
Size: 1.85 KB
Versions: 17
Compression:
Stored size: 1.85 KB
Contents
module Biro module Spc class Request < BaseRequest include Utils::Soap SCORE_3_MONTHS = 77 SCORE_12_MONTHS = 78 def development_url 'https://treina.spc.org.br/spc/remoting/ws/consulta/consultaWebService?wsdl' end def production_url 'https://servicos.spc.org.br/spc/remoting/ws/consulta/consultaWebService?wsdl' end def required_params [:username, :password] end def find(document, options = {}) begin params = {} add_basic_info(params, document, options[:kind] || 'F', options[:product_code]) add_score_info(params) if options[:include_score] response = soap.call(:consultar, message: params) Response.new(response) rescue => e Biro.log(:warn, "Unable to process SPC request") raise AuthenticationError.new("Error at SPC request: #{e.message}") if e.message.include?("CS_AUT") raise DocumentNotFoundError.new("Error at SPC request: #{e.message}") if e.message.include?("CPF inválido") || e.message.include?("(7)") raise StandardError.new("Error at SPC request: #{e.message}") end end def display_products response = soap.call(:listar_produtos, xml: '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header /><soapenv:Body /></soapenv:Envelope>') response.body end private def savon_options { basic_auth: [@username, @password] } end def add_basic_info(params, document, kind, product_code) params['codigo-produto'] = product_code params['tipo-consumidor'] = kind params['documento-consumidor'] = document end def add_score_info(request) request['codigo-insumo-opcional'] = [SCORE_3_MONTHS, SCORE_12_MONTHS] end end end end
Version data entries
17 entries across 17 versions & 1 rubygems