Class: NfseGyn::Response

Inherits:
Object
  • 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)


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

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

#error_messageObject



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

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

#outputObject



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

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