Sha256: e67c664a890bfaf62cde40d06fc7a29d7ad871a3380696d72ee11bd1349ccbe1

Contents?: true

Size: 918 Bytes

Versions: 1

Compression:

Stored size: 918 Bytes

Contents

module Cieloz
  class Requisicao
    class Resposta
      include ActiveModel::Serializers::Xml
      include Helpers

      STATUSES = {
        "0" => :criada,
        "1" => :em_andamento,
        "2" => :autenticada,
        "3" => :nao_autenticada,
        "4" => :autorizada,
        "5" => :nao_autorizada,
        "6" => :capturada,
        "9" => :cancelada,
        "10" => :em_autenticacao,
        "12" => :em_cancelamento
      }

      attr_reader :xml

      def self.from xml
        obj = new
        begin
          obj = obj.from_xml xml
        rescue
          # makes it resilient to bad responses,
          # allowing them to be logged
        end
        obj.instance_variable_set :@xml, xml
        obj
      end

      STATUSES.each do |_, status_type|
        define_method "#{status_type}?" do
          success? and STATUSES[status] == status_type
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cieloz-0.0.3 lib/cieloz/requisicao/resposta.rb