Class: BrNfe::Service::Response::Default

Inherits:
ActiveModelBase show all
Defined in:
lib/br_nfe/service/response/default.rb

Instance Attribute Summary collapse

Attributes inherited from ActiveModelBase

#reference

Instance Method Summary collapse

Methods inherited from ActiveModelBase

#assign_attributes, #default_values

Constructor Details

#initialize(attributes = {}) ⇒ Default

Returns a new instance of Default.



37
38
39
40
41
# File 'lib/br_nfe/service/response/default.rb', line 37

def initialize(attributes = {})
	self.notas_fiscais  = [] # Para poder utilizar o <<
	self.error_messages = [] # Para poder utilizar o <<
	super
end

Instance Attribute Details

#error_messagesObject

Array contendo as mensagens de erros No array pode conter Hash (com :codigo, :mensagem e :correcao) mas também pode conter mensagens de texto puro

Tipo de retorno: Array



12
13
14
# File 'lib/br_nfe/service/response/default.rb', line 12

def error_messages
  @error_messages
end

#notas_fiscaisObject

Array contendo as notas fiscais encontradas no xml de retorno. Utillizado em algumas requisições onde pode ser que retorne algum XML de NFe É um Array contendo objetos da classe BrNfe::Service::Response::NotaFiscal

Tipo de retorno: Array



20
21
22
# File 'lib/br_nfe/service/response/default.rb', line 20

def notas_fiscais
  @notas_fiscais
end

#original_xmlObject

XML original da resposta Contém todo o XML Envelope da resposta SOAP

Tipo de retorno: String XML



27
28
29
# File 'lib/br_nfe/service/response/default.rb', line 27

def original_xml
  @original_xml
end

#statusObject

Status possíveis

:success, :falied, :soap_error, :http_error, :unknown_error

Tipo de retorno: Symbol



34
35
36
# File 'lib/br_nfe/service/response/default.rb', line 34

def status
  @status
end

Instance Method Details

#get_statusObject



78
79
80
# File 'lib/br_nfe/service/response/default.rb', line 78

def get_status
	error_messages.blank? ? :success : :falied
end

#message_codesObject

Retorna um array apenas com os códigos das mensagens de erro. Sempre retornar o código no formato de String.

Tipo de retorno: Array



87
88
89
# File 'lib/br_nfe/service/response/default.rb', line 87

def message_codes
	@message_codes ||= error_messages.select{|msg| msg.is_a?(Hash)}.map{|msg| msg[:code].try(:to_s) }
end

#success?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/br_nfe/service/response/default.rb', line 70

def success?
	status == :success
end

#successful_request?Boolean

Método para saber se a conexão com a prefeitura foi bem-sucedida. Caso a requisição ocorra certo e não apresente nenhuma exception irá retornar true.

Tipo de retorno: Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/br_nfe/service/response/default.rb', line 66

def successful_request?
	!unsuccessful_request?
end

#unsuccessful_request?Boolean

Método para saber se a conexão com a prefeitura foi mal-sucedida. Caso ocorra algum erro na requisição irá retornar true.

Tipo de retorno: Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/br_nfe/service/response/default.rb', line 56

def unsuccessful_request?
	status.in?([:soap_error, :http_error, :unknown_error])
end