Class: TweetStream::Daemon

Inherits:
Client
  • Object
show all
Defined in:
lib/tweetstream/daemon.rb

Overview

A daemonized TweetStream client that will allow you to create backgroundable scripts for application specific processes. For instance, if you create a script called tracker.rb 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.

Constant Summary collapse

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

Constants inherited from Client

Client::OPTION_CALLBACKS

Instance Attribute Summary collapse

Attributes inherited from Client

#control, #control_uri, #options, #stream

Instance Method Summary collapse

Methods inherited from Client

#close_connection, #connect, #controllable?, #filter, #firehose, #follow, #links, #locations, #on, #on_anything, #on_control, #on_delete, #on_direct_message, #on_enhance_your_calm, #on_error, #on_event, #on_friends, #on_inited, #on_limit, #on_no_data_received, #on_reconnect, #on_scrub_geo, #on_stall_warning, #on_status_withheld, #on_timeline_status, #on_unauthorized, #on_user_withheld, #retweet, #sample, #sitestream, #stop, #stop_stream, #track, #userstream

Constructor Details

#initialize(name = DEFAULT_NAME, options = DEFAULT_OPTIONS) ⇒ Daemon

The daemon has an optional process name for use when querying running processes. You can also pass daemon options.



40
41
42
43
44
# File 'lib/tweetstream/daemon.rb', line 40

def initialize(name = DEFAULT_NAME, options = DEFAULT_OPTIONS)
  @app_name = name
  @daemon_options = options
  super({})
end

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



36
37
38
# File 'lib/tweetstream/daemon.rb', line 36

def app_name
  @app_name
end

#daemon_optionsObject

Returns the value of attribute daemon_options.



36
37
38
# File 'lib/tweetstream/daemon.rb', line 36

def daemon_options
  @daemon_options
end

Instance Method Details

#start(path, query_parameters = {}, &block) ⇒ Object

:nodoc:



46
47
48
49
50
# File 'lib/tweetstream/daemon.rb', line 46

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