Sha256: 64f1632d3f8dd5705ed526cb264bf0cc3790e0ff436dfc500f7a3b14cf7d4242

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

require_relative './effect'
require_relative "./meta_data"

module TalonOne
  module Integration
    class Event
      def initialize(raw_data)
        @raw = raw_data
      end

      def type
        @raw["type"]
      end

      def session_id
        @raw["sessionId"]
      end

      def attributes
        @raw["attributes"]
      end

      def effects
        @effects ||= @raw["effects"].map do |raw_array|
          TalonOne::Integration::Effect.new raw_array
        end
      end

      def meta
        @meta ||= TalonOne::Integration::MetaData.new @raw["meta"]
      end

      def accepted_coupon?
        effects.any? {|e| e.function == "acceptCoupon"}
      end

      def rejected_coupon?
        !accepted_coupon? && effects.any? {|e| e.function == "rejectCoupon"}
      end

      def accepted_referral?
        effects.any? {|e| e.function == "acceptReferral"}
      end

      def rejected_referral?
        !accepted_referral? && effects.any? {|e| e.function == "rejectReferral"}
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
talon_one-0.1.3 lib/integration/event.rb
talon_one-0.1.2 lib/integration/event.rb