Class: SEFAZ::Webservice::NFE::Validator
- Inherits:
-
Object
- Object
- SEFAZ::Webservice::NFE::Validator
- Defined in:
- lib/sefaz/webservice/nfe/validator.rb
Overview
Validador de XML pelo validador público da SEFAZ-RS
Instance Method Summary collapse
- #exec(openTimeout, readTimeout) ⇒ Object
-
#initialize(xml) ⇒ Validator
constructor
A new instance of Validator.
Constructor Details
#initialize(xml) ⇒ Validator
Returns a new instance of Validator.
9 10 11 |
# File 'lib/sefaz/webservice/nfe/validator.rb', line 9 def initialize(xml) @xml = xml end |
Instance Method Details
#exec(openTimeout, readTimeout) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sefaz/webservice/nfe/validator.rb', line 13 def exec(openTimeout, readTimeout) uri = URI("https://www.sefaz.rs.gov.br/NFE/NFE-VAL.aspx") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.open_timeout = openTimeout http.read_timeout = readTimeout content = Net::HTTP::Post.new(uri.request_uri) content.set_form_data(txtxml: @xml) response = http.request(content) if response.code == "200" nodes = Nokogiri::HTML(response.body.force_encoding('utf-8')).css('.tabela_resultado li').to_a mensagens = {} falhas = {} nodes[0..2].each do |node| k = get_key(node) v = (node) mensagens[k] = v falhas[k] = v if node.to_s.include?('../Imagens/erro.png') end return [:ok, mensagens, falhas] end return [:error, {}, {}] end |