Class | TweetStream::Client |
In: |
lib/tweetstream/client.rb
|
Parent: | Object |
Provides simple access to the Twitter Streaming API (apiwiki.twitter.com/Streaming-API-Documentation) for Ruby scripts that need to create a long connection to Twitter for tracking and other purposes.
Basic usage of the library is to call one of the provided methods and provide a block that will perform actions on a yielded TweetStream::Status. For example:
TweetStream::Client.new('user','pass').track('fail') do |status| puts "[#{status.user.screen_name}] #{status.text}" end
For information about a daemonized TweetStream client, view the TweetStream::Daemon class.
parser | [R] | |
password | [RW] | |
username | [RW] |
Create a new client with the Twitter credentials of the account you want to be using its API quota. You may also set the JSON parsing library as specified in the parser= setter.
Make a call to the statuses/filter method of the Streaming API, you may provide :follow, :track or both as options to follow the tweets of specified users or track keywords. This method is provided separately for cases when it would conserve the number of HTTP connections to combine track and follow.
Returns all public statuses. The Firehose is not a generally available resource. Few applications require this level of access. Creative use of a combination of other resources and various access levels can satisfy nearly every application use case.
Returns public statuses from or in reply to a set of users. Mentions ("Hello @user!") and implicit replies ("@user Hello!" created without pressing the reply "swoosh") are not matched. Requires integer user IDs, not screen names. Query parameters may be passed as the last argument.
Set a Proc to be run when a deletion notice is received from the Twitter stream. For example:
@client = TweetStream::Client.new('user','pass') @client.on_delete do |status_id, user_id| Tweet.delete(status_id) end
Block must take two arguments: the status id and the user id. If no block is given, it will return the currently set deletion proc. When a block is given, the TweetStream::Client object is returned to allow for chaining.
Set a Proc to be run when an HTTP error is encountered in the processing of the stream. Note that TweetStream will automatically try to reconnect, this is for reference only. Don‘t panic!
@client = TweetStream::Client.new('user','pass') @client.on_error do |message| # Make note of error message end
Block must take one argument: the error message. If no block is given, it will return the currently set error proc. When a block is given, the TweetStream::Client object is returned to allow for chaining.
Set a Proc to be run when a rate limit notice is received from the Twitter stream. For example:
@client = TweetStream::Client.new('user','pass') @client.on_limit do |discarded_count| # Make note of discarded count end
Block must take one argument: the number of discarded tweets. If no block is given, it will return the currently set limit proc. When a block is given, the TweetStream::Client object is returned to allow for chaining.
Set the JSON Parser for this client. Acceptable options are:
:json_gem: | Parse using the JSON gem. |
:json_pure: | Parse using the pure-ruby implementation of the JSON gem. |
:active_support: | Parse using ActiveSupport::JSON.decode |
:yajl: | Parse using yajl-ruby. |
You may also pass a class that will return a hash with symbolized keys when YourClass.parse is called with a JSON string.
Returns all retweets. The retweet stream is not a generally available resource. Few applications require this level of access. Creative use of a combination of other resources and various access levels can satisfy nearly every application use case. As of 9/11/2009, the site-wide retweet feature has not yet launched, so there are currently few, if any, retweets on this stream.
Specify keywords to track. Queries are subject to Track Limitations, described in Track Limiting and subject to access roles, described in the statuses/filter method. Track keywords are case-insensitive logical ORs. Terms are exact-matched, and also exact-matched ignoring punctuation. Phrases, keywords with spaces, are not supported. Keywords containing punctuation will only exact match tokens. Query parameters may be passed as the last argument.