Module: Tweet
- Defined in:
- lib/tweet.rb
Overview
Tweet
Synopsis
A generalized notification daemon. Can be petitioned by an arbitrary application to activate a notification. Notifications can be customized by the user via a plugin architecture. Examples include a GTK2 popup dialog, a syslog entry, or an email alert.
Can also be required in a ruby script to access a running Tweet daemon (see Tweet.notify, Tweet.message, Tweet.running?, Tweet.stop).
The website is here: tweet.rubyforge.org/
Installation
gem install tweet
or maybe:
sudo gem install tweet
Usage
tweetd []
Requirements
-
Ruby 1.8
-
daemons library
-
pidify library
Examples
To start the daemon:
tweetd -d
To contact the daemon from the shell:
tweet "hello world"
To contact the daemon from ruby:
require 'tweet'
Tweet.("hello world")
Author
Payton Swick, 2006
License Creative Commons GPL license.
Defined Under Namespace
Classes: Monitor, Note, Notifier
Constant Summary collapse
- VERSION =
'0.6'
- PRI =
{ 'CRITICAL' => 1, 'WARNING' => 2, 'INFO' => 3, 'LOW' => 4, 'DEBUG' => 5 }
- PORT =
The TCP port to listen on.
9128
- USE_SYSLOG =
Enable using syslog for tweetd events (this is different from the syslog notifier plugin, as it does not log notifications. This logs only tweetd activity, eg: stopping and starting.)
true
- USE_GTK_TRAY_ICON =
Experimental GTK Tray icon.
true
Class Method Summary collapse
-
.message(message, duration = 0) ⇒ Object
Given a String, this will try to contact a running tweet instance and send the String as a notification from the calling application with a duration of a number of seconds (the default is a duration of 0 (permanent)).
-
.message_with_notifiers(message, notifiers = [], duration = 0) ⇒ Object
Just like Tweet.message, but allows specifying an array of notifier plugins to use as requested notifiers on the server.
-
.notify(note) ⇒ Object
Given an instance of Note, this will try to contact a running tweet instance and send a notification.
-
.running? ⇒ Boolean
Returns true if an instance of tweetd is running (or appears to be running).
- .start ⇒ Object
-
.stop ⇒ Object
Stops a running instance of tweetd.
-
.where_am_i? ⇒ Boolean
Returns the path location to the library file.
Class Method Details
.message(message, duration = 0) ⇒ Object
Given a String, this will try to contact a running tweet instance and send the String as a notification from the calling application with a duration of a number of seconds (the default is a duration of 0 (permanent)). This is a simple form of Tweet::notify.
Example:
require 'tweet'
Tweet. "Hello World!"
121 122 123 |
# File 'lib/tweet.rb', line 121 def (, duration=0) notify(Note.info(, , duration, $0)) end |
.message_with_notifiers(message, notifiers = [], duration = 0) ⇒ Object
Just like Tweet.message, but allows specifying an array of notifier plugins to use as requested notifiers on the server. See Monitor for more information.
128 129 130 |
# File 'lib/tweet.rb', line 128 def (, notifiers=[], duration=0) notify(Note.new(, , duration, Tweet::PRI['INFO'], $0, notifiers)) end |
.notify(note) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/tweet.rb', line 97 def notify(note) require 'net/telnet' = 'app "'+note.application.to_s+'";priority "'+note.priority.to_s+'";duration "'+note.duration.to_s+'";notifier "'+note.requested_notifiers.join(' ')+'";title "'+note.title.to_s+'";message "'+note..to_s+'"' begin conn = Net::Telnet.new({'Host' => 'localhost', 'Port' => PORT, 'Telnet mode' => false }) rescue raise "Connection to tweet failed. Maybe tweetd is not running?" end out = conn.recv(128) raise "While trying to connect to tweetd, server replied: '#{out.chomp}'" if out !~ /^2/ conn.write(+"\n") out = conn.recv(128) raise "While trying to send this: '#{}', tweetd replied: '#{out.chomp}'" if out !~ /^2/ conn.close end |
.running? ⇒ Boolean
Returns true if an instance of tweetd is running (or appears to be running).
139 140 141 |
# File 'lib/tweet.rb', line 139 def running? Pidify.running? end |
.start ⇒ Object
148 149 150 |
# File 'lib/tweet.rb', line 148 def start Pidify.start end |
.stop ⇒ Object
Stops a running instance of tweetd.
144 145 146 |
# File 'lib/tweet.rb', line 144 def stop Pidify.stop end |
.where_am_i? ⇒ Boolean
Returns the path location to the library file.
133 134 135 |
# File 'lib/tweet.rb', line 133 def where_am_i? File.dirname(__FILE__)+'/..' end |