Sha256: 7e5cae34de48ed98818c0936cbc11e88e44778203041bf4df6d6c8ec2c6e9519

Contents?: true

Size: 1.53 KB

Versions: 13

Compression:

Stored size: 1.53 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

  DEFAULT_NAME = 'tweetstream'.freeze
  DEFAULT_OPTIONS = { :multiple => true }

  attr_accessor :app_name, :daemon_options

  # The daemon has an optional process name for use when querying
  # running processes.  You can also pass daemon options.
  def initialize(name = DEFAULT_NAME, options = DEFAULT_OPTIONS)
    @app_name = name
    @daemon_options = options
    super({})
  end

  def start(path, query_parameters = {}, &block) #:nodoc:
    Daemons.run_proc(@app_name, @daemon_options) do
      super(path, query_parameters, &block)
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
tweetstream-2.6.0 lib/tweetstream/daemon.rb
jls-tweetstream-2.5.0 lib/tweetstream/daemon.rb
tweetstream-2.5.0 lib/tweetstream/daemon.rb
tweetstream-2.4.0 lib/tweetstream/daemon.rb
tweetstream-2.3.0 lib/tweetstream/daemon.rb
tweetstream-2.2.0 lib/tweetstream/daemon.rb
tweetstream-2.1.0 lib/tweetstream/daemon.rb
tweetstream-2.0.1 lib/tweetstream/daemon.rb
tweetstream-2.0.0 lib/tweetstream/daemon.rb
tweetstream-1.1.5 lib/tweetstream/daemon.rb
tweetstream-1.1.4 lib/tweetstream/daemon.rb
tweetstream-1.1.3 lib/tweetstream/daemon.rb
tweetstream-1.1.2 lib/tweetstream/daemon.rb