Sha256: 970d0f31eeda5a327b05cfcaaeed5babe49669aa46437e9bea9a1cb5ffdbad20

Contents?: true

Size: 1003 Bytes

Versions: 3

Compression:

Stored size: 1003 Bytes

Contents

module Twitter
  module Streaming
    class Event
      LIST_EVENTS = [
        :list_created, :list_destroyed, :list_updated, :list_member_added,
        :list_member_added, :list_member_removed, :list_user_subscribed,
        :list_user_subscribed, :list_user_unsubscribed, :list_user_unsubscribed
      ].freeze

      TWEET_EVENTS = [
        :favorite, :unfavorite, :quoted_tweet
      ].freeze

      attr_reader :name, :source, :target, :target_object

      # @param data [Hash]
      def initialize(data)
        @name = data[:event].to_sym
        @source = Twitter::User.new(data[:source])
        @target = Twitter::User.new(data[:target])
        @target_object = target_object_factory(@name, data[:target_object])
      end

    private

      def target_object_factory(event_name, data)
        if LIST_EVENTS.include?(event_name)
          Twitter::List.new(data)
        elsif TWEET_EVENTS.include?(event_name)
          Twitter::Tweet.new(data)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
twitter-6.1.0 lib/twitter/streaming/event.rb
twitter-6.0.0 lib/twitter/streaming/event.rb
twitter-5.17.0 lib/twitter/streaming/event.rb