Class: Twitter::Streaming::Client

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

Instance Attribute Summary collapse

Attributes inherited from Client

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

Instance Method Summary collapse

Methods included from Utils

flat_pmap, pmap

Methods inherited from Client

#credentials, #credentials?, #user_token?

Constructor Details

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

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.



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

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

Instance Attribute Details

#connection=(value) ⇒ Object (writeonly)

Sets the attribute connection

Parameters:

  • value

    the value to set the attribute connection to.



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

def connection=(value)
  @connection = value
end

Instance Method Details

#before_request(&block) ⇒ Object

Set a Proc to be run when connection established.



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

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

#closeObject



108
109
110
# File 'lib/twitter/streaming/client.rb', line 108

def close
  @connection.close
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

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:



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

def filter(options = {}, &)
  request(:post, "https://stream.twitter.com:443/1.1/statuses/filter.json", options, &)
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

Parameters:

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

    A customizable set of options.

Options Hash (options):

  • :count (Integer)

    The number of messages to backfill.

Yields:

See Also:



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

def firehose(options = {}, &)
  request(:get, "https://stream.twitter.com:443/1.1/statuses/firehose.json", options, &)
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



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

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

#site(*follow, options = {}) {|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 users

Parameters:

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

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

  • 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 stall warnings should be delivered.

Yields:

See Also:



74
75
76
77
78
# File 'lib/twitter/streaming/client.rb', line 74

def site(*args, &)
  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(",")), &)
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

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:



92
93
94
# File 'lib/twitter/streaming/client.rb', line 92

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