Sha256: 2e8006c8a3665735c12f6b3228a4c848596a215cee049142f57f8d05456090a4

Contents?: true

Size: 908 Bytes

Versions: 8

Compression:

Stored size: 908 Bytes

Contents

require_relative './effect'

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 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

8 entries across 8 versions & 1 rubygems

Version Path
talon_one-0.1.1 lib/integration/event.rb
talon_one-0.1.0 lib/integration/event.rb
talon_one-0.0.10 lib/integration/event.rb
talon_one-0.0.9 lib/integration/event.rb
talon_one-0.0.8 lib/integration/event.rb
talon_one-0.0.7 lib/integration/event.rb
talon_one-0.0.6 lib/integration/event.rb
talon_one-0.0.5 lib/integration/event.rb