Sha256: 910029a6d1466ee17e20162d8f95f33d3736ad3abaa9f96c57726838cca5efb8

Contents?: true

Size: 976 Bytes

Versions: 14

Compression:

Stored size: 976 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,
      ]

      TWEET_EVENTS = [
        :favorite, :unfavorite,
      ]

      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

14 entries across 14 versions & 1 rubygems

Version Path
twitter-5.11.0 lib/twitter/streaming/event.rb
twitter-5.10.0 lib/twitter/streaming/event.rb
twitter-5.9.0 lib/twitter/streaming/event.rb
twitter-5.8.0 lib/twitter/streaming/event.rb
twitter-5.7.1 lib/twitter/streaming/event.rb
twitter-5.7.0 lib/twitter/streaming/event.rb
twitter-5.6.0 lib/twitter/streaming/event.rb
twitter-5.5.1 lib/twitter/streaming/event.rb
twitter-5.5.0 lib/twitter/streaming/event.rb
twitter-5.4.1 lib/twitter/streaming/event.rb
twitter-5.4.0 lib/twitter/streaming/event.rb
twitter-5.3.1 lib/twitter/streaming/event.rb
twitter-5.3.0 lib/twitter/streaming/event.rb
twitter-5.2.0 lib/twitter/streaming/event.rb