notification 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,9 @@
1
+ == Version 0.2
2
+
3
+ * snarl support
4
+ * popup will use snarl or growl depending on which is present on your system
5
+ * should work w/ windows
6
+
1
7
  == Version 0.1
2
8
 
3
9
  Initial version release, supports :
@@ -6,8 +6,12 @@ example.rb
6
6
  lib/gmail_notifier.rb
7
7
  lib/growl_notifier.rb
8
8
  lib/notification.rb
9
+ lib/popup_notifier.rb
9
10
  lib/sms_notifier.rb
11
+ lib/snarl_notifier.rb
10
12
  test/gmail_notifier_test.rb
11
13
  test/growl_notifier_test.rb
14
+ test/notification_test.rb
15
+ test/popup_notifier_test.rb
12
16
  test/sms_notifier_test.rb
13
17
  test/test_helper.rb
data/README CHANGED
@@ -24,6 +24,7 @@ growl, snarl, etc, and all these are exposed in a simple, uniform way.
24
24
  * GMail
25
25
  * SMS (via teleflip)
26
26
  * Growl
27
+ * Snarl
27
28
 
28
29
  == Contact
29
30
 
@@ -1,16 +1,36 @@
1
1
  require 'ruby-growl'
2
2
 
3
3
  class GrowlNotifier
4
+ #Valid options:
5
+ # :application => the name of the application sending the notifications (ruby-growl)
6
+ # :to => the hostname notifications will send to by default (localhost)
7
+ # :notifications => an array of names for the different notifications the application can send ([])
8
+ # :password => the growl network password for the given host (nil)
4
9
  def initialize(options = {})
5
10
  @application = options[:application] || 'ruby-growl'
6
- @to = options[:to]
11
+ @to = options[:to] || 'localhost'
12
+ @notifications = options[:notifications]
13
+ @password = options[:password]
7
14
  end
8
15
 
16
+ # Important warning: unless the user has enabled network notifications,
17
+ # this will throw an error. It's suggested that you catch this error
18
+ # and entreat your user to enable network notifications in an appropriate fashion.
19
+ # They probably also need to enable remote application registration.
20
+ #
21
+ # Valid options:
22
+ # :to => the hostname notifications will send to by default (localhost)
23
+ # :type => the notification type that's being sent ("@application notification")
24
+ # :password =>
9
25
  def notify(message, options = {})
10
- to = options[:to] || @to || 'localhost'
11
- notification_type = "#{@application} notification"
26
+ to = options[:to] || @to
27
+ notification_type = options[:type] || "#{@application} notification"
28
+ notifications = @notifications || [notification_type]
29
+
30
+ #ensures we never get an Unknown Notification error
31
+ notification_type = notifications.first unless notifications.include?(notification_type)
12
32
 
13
- g = Growl.new to, @application, [notification_type]
33
+ g = Growl.new to, @application, notifications, notifications, @password
14
34
  g.notify notification_type, @application, message
15
35
  end
16
36
  end
@@ -1,16 +1,23 @@
1
+ require 'rubygems'
2
+
1
3
  module Notification
2
- VERSION = "0.1"
3
- end
4
+ VERSION = "0.2"
4
5
 
5
- def safe_require file
6
- require file
7
- rescue LoadError
8
- puts "#{file} is not available"
6
+ #this is the preferred place to check if a notification system
7
+ #is available
8
+ def self.available_notifiers
9
+ @available_notifiers ||= []
10
+ end
9
11
  end
10
12
 
11
- require 'rubygems'
12
13
 
13
- safe_require 'gmail_notifier'
14
- safe_require 'sms_notifier'
15
- safe_require 'growl_notifier'
14
+ %w(gmail sms growl snarl popup).each do |type|
15
+ begin
16
+ type += "_notifier"
17
+ require type
18
+ Notification.available_notifiers << type
19
+ rescue LoadError
20
+ $stderr.puts "#{type} is not available"
21
+ end
22
+ end
16
23
 
@@ -0,0 +1,17 @@
1
+ # Generalizes the API for growl and snarl
2
+ # it should be easy to add support for more later.
3
+ class PopupNotifier
4
+ def initialize(*params)
5
+ if Notification.available_notifiers.include?("growl_notifier")
6
+ @notifier = GrowlNotifier.new(*params)
7
+ elsif Notification.available_notifiers.include?("snarl_notifier")
8
+ @notifier = SnarlNotifier.new(*params)
9
+ else
10
+ raise LoadError("No popup notification system installed\n Try 'sudo gem install ruby-growl' or 'gem install snarl-growl'")
11
+ end
12
+ end
13
+
14
+ def notify(*params)
15
+ @notifier.notify(*params)
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ require 'snarl'
2
+
3
+ class SnarlNotifier
4
+ # valid options:
5
+ # application: the name of your application
6
+ def initialize(options = {})
7
+ @application = options[:application] || 'ruby-snarl'
8
+ end
9
+
10
+ #
11
+ def notify(message, options = {})
12
+ title = options[:title] || "#{@application} notification"
13
+ Snarl.show_message(title,message,options[:icon] || nil, options[:timeout] || Snarl::DEFAULT_TIMEOUT)
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require "notification"
3
+
4
+ class NotificationTest < Test::Unit::TestCase
5
+ def test_available_notifiers
6
+ assert_equal ['gmail_notifier', 'sms_notifier', 'growl_notifier', 'popup_notifier'], Notification.available_notifiers
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+ require "notification"
3
+
4
+ class GrowlNotifierTest < Test::Unit::TestCase
5
+ def test_default_stuff
6
+ g = Object.new
7
+ Growl.expects(:new).returns(g)
8
+ g.expects(:notify)
9
+
10
+ popup = PopupNotifier.new
11
+ popup.notify('help')
12
+
13
+ g.verify
14
+ end
15
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: notification
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.1"
7
- date: 2007-03-21 00:00:00 -07:00
6
+ version: "0.2"
7
+ date: 2007-07-28 00:00:00 -07:00
8
8
  summary: Notification is a one stop shop for notification, it knows how to send messages via GMail, SMS, growl, snarl, etc, and all these are exposed in a simple, uniform way.
9
9
  require_paths:
10
10
  - lib
@@ -37,19 +37,26 @@ files:
37
37
  - lib/gmail_notifier.rb
38
38
  - lib/growl_notifier.rb
39
39
  - lib/notification.rb
40
+ - lib/popup_notifier.rb
40
41
  - lib/sms_notifier.rb
42
+ - lib/snarl_notifier.rb
41
43
  - test/gmail_notifier_test.rb
42
44
  - test/growl_notifier_test.rb
45
+ - test/notification_test.rb
46
+ - test/popup_notifier_test.rb
43
47
  - test/sms_notifier_test.rb
44
48
  - test/test_helper.rb
45
49
  test_files:
46
50
  - test/gmail_notifier_test.rb
47
51
  - test/growl_notifier_test.rb
52
+ - test/notification_test.rb
53
+ - test/popup_notifier_test.rb
48
54
  - test/sms_notifier_test.rb
49
- rdoc_options: []
50
-
51
- extra_rdoc_files: []
52
-
55
+ rdoc_options:
56
+ - --main
57
+ - README.txt
58
+ extra_rdoc_files:
59
+ - Manifest.txt
53
60
  executables: []
54
61
 
55
62
  extensions: []
@@ -91,5 +98,5 @@ dependencies:
91
98
  requirements:
92
99
  - - ">="
93
100
  - !ruby/object:Gem::Version
94
- version: 1.2.0
101
+ version: 1.2.1
95
102
  version: