Class: NfseGyn::Response

Inherits:
Object show all
Defined in:
lib/nfse_gyn/response.rb

Direct Known Subclasses

ConsultarNfse::Response, GerarNfse::Response

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ Response

Returns a new instance of Response.



3
4
5
# File 'lib/nfse_gyn/response.rb', line 3

def initialize(payload)
  @payload = payload
end

Instance Method Details

#class_nameObject



7
8
9
# File 'lib/nfse_gyn/response.rb', line 7

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

#error?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/nfse_gyn/response.rb', line 34

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

#error_messageObject



38
39
40
41
42
# File 'lib/nfse_gyn/response.rb', line 38

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


15
16
17
18
19
# File 'lib/nfse_gyn/response.rb', line 15

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

#municipal_registrationObject



21
22
23
24
# File 'lib/nfse_gyn/response.rb', line 21

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

#numberObject



26
27
28
# File 'lib/nfse_gyn/response.rb', line 26

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

#outputObject



44
45
46
47
# File 'lib/nfse_gyn/response.rb', line 44

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

#successful?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/nfse_gyn/response.rb', line 11

def successful?
  !error?
end

#verification_codeObject



30
31
32
# File 'lib/nfse_gyn/response.rb', line 30

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