Sha256: 27560936f9f59f6b0b918c97c463f9dc87ae547515e46b13aed75d57e92aad97

Contents?: true

Size: 705 Bytes

Versions: 1

Compression:

Stored size: 705 Bytes

Contents

module Cesri
  class AutorizacionComprobanteResponse

    attr_reader :response, :state, :messages

    def initialize(response)
      @response = response
      @state = state_value
      @messages = []

      load_messages
    end

    def success?
      @state == 'AUTORIZADO'
    end

    private

    def state_value
      doc.xpath('//estado').first.content if doc.xpath('//estado').first
    end

    def load_messages
      doc.xpath('//mensajes//mensaje').each do |message|
        response_message = ResponseMessage.new(message)
        messages << response_message if response_message.identificador
      end
    end

    def doc
      @doc ||= Nokogiri::XML(@response.to_s)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cesri-0.1.0 lib/cesri/autorizacion_comprobante_response.rb