Class: Twitter::Streaming::Client

Inherits:
Client
  • Object
show all
Defined in:
lib/twitter/streaming/client.rb

Instance Attribute Summary (collapse)

Attributes inherited from Client

#access_token, #access_token_secret, #consumer_key, #consumer_secret, #proxy, #user_agent

Instance Method Summary (collapse)

Methods inherited from Client

#credentials, #credentials?, #user_token?

Methods included from Utils

flat_pmap, pmap

Constructor Details

- (Twitter::Streaming::Client) initialize(options = {})

Initializes a new Client object

Parameters:

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :tcp_socket_class (String)

    A class that Connection will use to create a new TCP socket.

  • :ssl_socket_class (String)

    A class that Connection will use to create a new SSL socket.



20
21
22
23
# File 'lib/twitter/streaming/client.rb', line 20

def initialize(options = {})
  super
  @connection = Streaming::Connection.new(options)
end

Instance Attribute Details

- (Object) connection=(value) (writeonly)

Sets the attribute connection

Parameters:

  • value

    the value to set the attribute connection to.



11
12
13
# File 'lib/twitter/streaming/client.rb', line 11

def connection=(value)
  @connection = value
end

- (Object) ssl_socket_class

Returns the value of attribute ssl_socket_class



12
13
14
# File 'lib/twitter/streaming/client.rb', line 12

def ssl_socket_class
  @ssl_socket_class
end

- (Object) tcp_socket_class

Returns the value of attribute tcp_socket_class



12
13
14
# File 'lib/twitter/streaming/client.rb', line 12

def tcp_socket_class
  @tcp_socket_class
end

Instance Method Details

- (Object) before_request(&block)

Set a Proc to be run when connection established.



94
95
96
97
98
99
100
101
102
103
# File 'lib/twitter/streaming/client.rb', line 94

def before_request(&block)
  if block_given?
    @before_request = block
    self
  elsif instance_variable_defined?(:@before_request)
    @before_request
  else
    proc {}
  end
end

- (Object) filter(options = {}) {|Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning| ... }

Note:

At least one predicate parameter (follow, locations, or track) must be specified.

Returns public statuses that match one or more filter predicates

Parameters:

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :follow (String)

    A comma separated list of user IDs, indicating the users to return statuses for in the stream.

  • :track (String)

    Includes additional Tweets matching the specified keywords. Phrases of keywords are specified by a comma-separated list.

  • :locations (String)

    Includes additional Tweets falling within the specified bounding boxes.

Yields:

See Also:



35
36
37
# File 'lib/twitter/streaming/client.rb', line 35

def filter(options = {}, &block)
  request(:post, 'https://stream.twitter.com:443/1.1/statuses/filter.json', options, &block)
end

- (Object) firehose(options = {}) {|Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning| ... }

Note:

This endpoint requires special permission to access.

Returns all public statuses

Parameters:

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :count (Integer)

    The number of messages to backfill.

Yields:

See Also:



47
48
49
# File 'lib/twitter/streaming/client.rb', line 47

def firehose(options = {}, &block)
  request(:get, 'https://stream.twitter.com:443/1.1/statuses/firehose.json', options, &block)
end

- (Object) sample(options = {}) {|Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning| ... }

Returns a small random sample of all public statuses



56
57
58
# File 'lib/twitter/streaming/client.rb', line 56

def sample(options = {}, &block)
  request(:get, 'https://stream.twitter.com:443/1.1/statuses/sample.json', options, &block)
end

- (Object) site(*args) {|Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning| ... }

Note:

Site Streams is currently in a limited beta. Access is restricted to whitelisted accounts.

Streams messages for a set of user

Parameters:

  • follow (Enumerable<Integer, String, Twitter::User>)

    A list of user IDs, indicating the users to return statuses for in the stream.

  • options (Hash)

    A customizable set of options.

Yields:

See Also:



71
72
73
74
75
# File 'lib/twitter/streaming/client.rb', line 71

def site(*args, &block)
  arguments = Arguments.new(args)
  user_ids = collect_user_ids(arguments)
  request(:get, 'https://sitestream.twitter.com:443/1.1/site.json', arguments.options.merge(:follow => user_ids.join(',')), &block)
end

- (Object) user(options = {}) {|Twitter::Tweet, Twitter::Streaming::Event, Twitter::DirectMessage, Twitter::Streaming::FriendList, Twitter::Streaming::DeletedTweet, Twitter::Streaming::StallWarning| ... }

Streams messages for a single user

Parameters:

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :with (String)

    Specifies whether to return information for just the users specified in the follow parameter, or include messages from accounts they follow.

  • :replies (String)

    Specifies whether to return additional @replies.

  • :stall_warnings (String)

    Specifies whether stall warnings should be delivered.

  • :track (String)

    Includes additional Tweets matching the specified keywords. Phrases of keywords are specified by a comma-separated list.

  • :locations (String)

    Includes additional Tweets falling within the specified bounding boxes.

Yields:

See Also:



89
90
91
# File 'lib/twitter/streaming/client.rb', line 89

def user(options = {}, &block)
  request(:get, 'https://userstream.twitter.com:443/1.1/user.json', options, &block)
end