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

#initialize(options = {}) ⇒ Twitter::Streaming::Client

Initializes a new Client object

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.



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

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

Instance Attribute Details

#connection=(value) ⇒ Object (writeonly)

Sets the attribute connection



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

def connection=(value)
  @connection = value
end

#ssl_socket_classObject

Returns the value of attribute ssl_socket_class



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

def ssl_socket_class
  @ssl_socket_class
end

#tcp_socket_classObject

Returns the value of attribute tcp_socket_class



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

def tcp_socket_class
  @tcp_socket_class
end

Instance Method Details

#before_request(&block) ⇒ Object

Set a Proc to be run when connection established.



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

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

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

Note:

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

Returns public statuses that match one or more filter predicates

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:



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

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

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

Note:

This endpoint requires special permission to access.

Returns all public statuses



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

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

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

Returns a small random sample of all public statuses



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

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

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

Note:

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

Streams messages for a set of user



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

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

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

Streams messages for a single user

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:



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

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