Sha256: c80862f597fc4efe806f6139fedc575aa87dadb263e48c53b5328c099f9a4011

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

module NfseGyn
  class Response
    def initialize(payload)
      @payload = payload
    end

    def class_name
      self.class.to_s.split('::')[1]
    end

    def successful?
      !error?
    end

    def link
      <<-URL.squish
        https://www2.goiania.go.gov.br/sistemas/snfse/asp/snfse00200w0.asp?inscricao=#{municipal_registration}&nota=#{number}&verificador=#{verification_code}
      URL
    end

    def municipal_registration
      p = body['Nfse']['InfNfse']['DeclaracaoPrestacaoServico']['Prestador']
      p['IdentificacaoPrestador']['InscricaoMunicipal'] if successful?
    end

    def number
      body['Nfse']['InfNfse']['Numero'] if successful?
    end

    def verification_code
      body['Nfse']['InfNfse']['CodigoVerificacao'] if successful?
    end

    def error?
      content['ListaMensagemRetorno'].present?
    end

    def error_message
      if error? && content['ListaMensagemRetorno']['MensagemRetorno'].present?
        content['ListaMensagemRetorno']['MensagemRetorno']['Correcao'].try(:strip)
      end
    end

    def output
      response = @payload.body.try(:values).try(:first)
      @output ||= Nori.new.parse(response.try(:values).try(:first) || response)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nfse_gyn-0.3.0 lib/nfse_gyn/response.rb
nfse_gyn-0.2.0 lib/nfse_gyn/response.rb
nfse_gyn-0.1.2 lib/nfse_gyn/response.rb