Sha256: 0e8e4a8ee3b24bd766bc792d5d1c2bb89881b3be0c867c973f6acbb5eb6c7315

Contents?: true

Size: 813 Bytes

Versions: 2

Compression:

Stored size: 813 Bytes

Contents

module Workarea
  module Kount
    class EventBatch
      attr_reader :data, :xml

      delegate :errors, to: :xml

      def initialize(data)
        @data = data
        @xml = Nokogiri::XML.parse(@data)
      end

      def valid?
        errors.empty?
      end

      def process!
        events.each do |event|
          next unless %w(RISK_CHANGE_REPLY WORKFLOW_STATUS_EDIT).include?(event.name)

          event_string = event.xml.to_s.lines.map(&:strip).join
          ProcessReviewOrder.perform_async(event.order_id, event.approved?, event_string)
        end
      end

      private

        def events
          @events ||= begin
            return [] if errors.present?

            xml.xpath('events/event').map { |e| Workarea::Kount::Event.create(e) }
          end
        end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-kount-3.3.1 app/services/workarea/kount/event_batch.rb
workarea-kount-3.3.0 app/services/workarea/kount/event_batch.rb