Sha256: ef01ae03b321c66d7d7dfaf10e865d3a328651abc4bb7065bd47fded8f4e04e4

Contents?: true

Size: 1.64 KB

Versions: 3

Compression:

Stored size: 1.64 KB

Contents

require 'daemons'

# A daemonized TweetStream client that will allow you to
# create backgroundable scripts for application specific
# processes. For instance, if you create a script called
# <tt>tracker.rb</tt> and fill it with this:
#
#     require 'rubygems'
#     require 'tweetstream'
#
#     TweetStream.configure do |config|
#       config.consumer_key = 'abcdefghijklmnopqrstuvwxyz'
#       config.consumer_secret = '0123456789'
#       config.oauth_token = 'abcdefghijklmnopqrstuvwxyz'
#       config.oauth_token_secret = '0123456789'
#       config.auth_method = :oauth
#     end
#
#     TweetStream::Daemon.new('tracker').track('intridea') do |status|
#       # do something here
#     end
#
# And then you call this from the shell:
#
#     ruby tracker.rb start
#
# A daemon process will spawn that will automatically
# run the code in the passed block whenever a new tweet
# matching your search term ('intridea' in this case)
# is posted.
#
class TweetStream::Daemon < TweetStream::Client
  # Initialize a Daemon with the credentials of the
  # Twitter account you wish to use. The daemon has
  # an optional process name for use when querying
  # running processes.
  def initialize(app_name=nil)
    @app_name = app_name
    super({})
  end

  def start(path, query_parameters = {}, &block) #:nodoc:
    # Because of a change in Ruvy 1.8.7 patchlevel 249, you cannot call anymore
    # super inside a block. So I assign to a variable the base class method before
    # the Daemons block begins.
    startmethod = super.start
    Daemons.run_proc(@app_name || 'tweetstream', :multiple => true) do
      startmethod(path, query_parameters, &block)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tweetstream-1.1.1 lib/tweetstream/daemon.rb
tweetstream-1.1.0 lib/tweetstream/daemon.rb
tweetstream-1.1.0.rc2 lib/tweetstream/daemon.rb