notifier 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/README.rdoc +67 -0
- data/Rakefile +10 -0
- data/lib/notifier.rb +49 -0
- data/lib/notifier/growl.rb +23 -0
- data/lib/notifier/kdialog.rb +15 -0
- data/lib/notifier/knotify.rb +15 -0
- data/lib/notifier/notify_send.rb +15 -0
- data/lib/notifier/osd_cat.rb +25 -0
- data/lib/notifier/placebo.rb +12 -0
- data/lib/notifier/snarl.rb +20 -0
- data/lib/notifier/version.rb +8 -0
- data/notifier.gemspec +24 -0
- data/test/notifier_test.rb +73 -0
- data/test/test_helper.rb +14 -0
- metadata +106 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
= Notifier
|
2
|
+
|
3
|
+
Send system notifications on several platforms with a simple and unified API. Currently supports:
|
4
|
+
|
5
|
+
* Growl (Mac OS X)
|
6
|
+
* Kdialog (Linux/KDE)
|
7
|
+
* Knotify (Linux/KDE)
|
8
|
+
* OSD Cat (Linux)
|
9
|
+
* Libnotify (Linux)
|
10
|
+
* Snarl (Windows)
|
11
|
+
|
12
|
+
== Installation
|
13
|
+
|
14
|
+
gem install notifier
|
15
|
+
|
16
|
+
== Usage
|
17
|
+
|
18
|
+
Notifier will try to detect which notifiers are available in your system. So you can just send a message:
|
19
|
+
|
20
|
+
Notifier.notify(
|
21
|
+
:image => "image.png",
|
22
|
+
:title => "Testing Notifier",
|
23
|
+
:message => "Sending an important message!"
|
24
|
+
)
|
25
|
+
|
26
|
+
Not all notifiers support the image option, therefore it will be ignored.
|
27
|
+
|
28
|
+
If your system support more than one notifier, you can specify which one you prefer:
|
29
|
+
|
30
|
+
Notifier.default_notifier = :notify_send
|
31
|
+
|
32
|
+
The available names are <tt>growl</tt>, <tt>kdialog</tt>, <tt>knotify</tt>, <tt>notify_send</tt>, <tt>osd_cat</tt>, and <tt>snarl</tt>.
|
33
|
+
|
34
|
+
There are several helper methods that you can use in order to retrieve notifiers.
|
35
|
+
|
36
|
+
* <tt>Notifier.notifier</tt>: return the first supported notifier
|
37
|
+
* <tt>Notifier.notifiers</tt>: return all notifiers
|
38
|
+
* <tt>Notifier.supported_notifiers</tt>: return only supported notifiers
|
39
|
+
* <tt>Notifier.from_name(name)</tt>: find notifier by its name
|
40
|
+
* <tt>Notifier.supported_notifier_from_name(name)</tt>: find a supported notifier by its name
|
41
|
+
|
42
|
+
== Maintainer
|
43
|
+
|
44
|
+
* Nando Vieira - http://nandovieira.com.br
|
45
|
+
|
46
|
+
== License
|
47
|
+
|
48
|
+
(The MIT License)
|
49
|
+
|
50
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
51
|
+
a copy of this software and associated documentation files (the
|
52
|
+
'Software'), to deal in the Software without restriction, including
|
53
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
54
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
55
|
+
permit persons to whom the Software is furnished to do so, subject to
|
56
|
+
the following conditions:
|
57
|
+
|
58
|
+
The above copyright notice and this permission notice shall be
|
59
|
+
included in all copies or substantial portions of the Software.
|
60
|
+
|
61
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
62
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
63
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
64
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
65
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
66
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
67
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/lib/notifier.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module Notifier
|
2
|
+
autoload :Growl, "notifier/growl"
|
3
|
+
autoload :Snarl, "notifier/snarl"
|
4
|
+
autoload :OsdCat, "notifier/osd_cat"
|
5
|
+
autoload :Knotify, "notifier/knotify"
|
6
|
+
autoload :Kdialog, "notifier/kdialog"
|
7
|
+
autoload :NotifySend, "notifier/notify_send"
|
8
|
+
autoload :Placebo, "notifier/placebo"
|
9
|
+
|
10
|
+
extend self
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_accessor :default_notifier
|
14
|
+
end
|
15
|
+
|
16
|
+
def notifier
|
17
|
+
supported_notifier_from_name(default_notifier) || supported_notifiers.first
|
18
|
+
end
|
19
|
+
|
20
|
+
def notify(options)
|
21
|
+
notifier.notify(options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def notifiers
|
25
|
+
constants.collect do |name|
|
26
|
+
const_get(name) unless name.to_s == "Placebo"
|
27
|
+
end.compact + [Placebo]
|
28
|
+
end
|
29
|
+
|
30
|
+
def supported_notifiers
|
31
|
+
notifiers.select {|notifier| notifier.supported?}
|
32
|
+
end
|
33
|
+
|
34
|
+
def from_name(name)
|
35
|
+
notifier = const_get(classify(name.to_s))
|
36
|
+
rescue Exception
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def supported_notifier_from_name(name)
|
41
|
+
notifier = from_name(name)
|
42
|
+
notifier && notifier.supported? ? notifier : nil
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def classify(string)
|
47
|
+
string.gsub(/_(.)/sm) { "#{$1.upcase}" }.gsub(/^(.)/) { "#{$1.upcase}" }
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Notifier
|
2
|
+
module Growl
|
3
|
+
extend self
|
4
|
+
|
5
|
+
SCRIPT = File.dirname(__FILE__) + "/../../../resources/register-growl.scpt"
|
6
|
+
FILE = File.expand_path("~/.test_notifier-growl")
|
7
|
+
|
8
|
+
def supported?
|
9
|
+
RUBY_PLATFORM =~ /darwin/ && `ps -Al | grep GrowlHelper` && `which growlnotify` && $? == 0
|
10
|
+
end
|
11
|
+
|
12
|
+
def notify(options)
|
13
|
+
Thread.new do
|
14
|
+
`growlnotify -n test_notifier --image #{options[:image]} -p 2 -m '#{options[:message]}' -t '#{options[:title]}'`
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def register
|
19
|
+
return if File.file?(FILE)
|
20
|
+
system "osascript #{SCRIPT} > #{FILE}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Notifier
|
2
|
+
module Kdialog
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def supported?
|
6
|
+
RUBY_PLATFORM =~ /(linux|freebsd)/ && `which kdialog > /dev/null` && $? == 0
|
7
|
+
end
|
8
|
+
|
9
|
+
def notify(options)
|
10
|
+
Thread.new do
|
11
|
+
`kdialog --title #{options[:title]} --passivepopup \"#{options[:message]}\" 5`
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Notifier
|
2
|
+
module Knotify
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def supported?
|
6
|
+
RUBY_PLATFORM =~ /(linux|freebsd)/ && `ps -Al | grep dcop` && $? == 0
|
7
|
+
end
|
8
|
+
|
9
|
+
def notify(options)
|
10
|
+
Thread.new do
|
11
|
+
`dcop knotify default notify eventname \'#{options[:title]}\' \'#{options[:message]}\' '' '' 16 2`
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Notifier
|
2
|
+
module NotifySend
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def supported?
|
6
|
+
RUBY_PLATFORM =~ /(linux|freebsd)/ && `which notify-send > /dev/null` && $? == 0
|
7
|
+
end
|
8
|
+
|
9
|
+
def notify(options)
|
10
|
+
Thread.new do
|
11
|
+
`notify-send -i #{options[:image]} #{options[:title]} \"#{options[:message]}\"`
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Notifier
|
2
|
+
module OsdCat
|
3
|
+
extend self
|
4
|
+
|
5
|
+
FONT = "-bitstream-charter-bold-r-normal--33-240-100-100-p-206-iso8859-1"
|
6
|
+
POSITION = "top"
|
7
|
+
POSITION_OFFSET = "0"
|
8
|
+
ALIGN = "center"
|
9
|
+
COLORS = {
|
10
|
+
:fail => "orange",
|
11
|
+
:success => "green",
|
12
|
+
:error => "red"
|
13
|
+
}
|
14
|
+
|
15
|
+
def supported?
|
16
|
+
RUBY_PLATFORM =~ /(linux|freebsd)/ && `which osd_cat > /dev/null` && $? == 0
|
17
|
+
end
|
18
|
+
|
19
|
+
def notify(options)
|
20
|
+
Thread.new do
|
21
|
+
`echo #{options[:message].inspect} | osd_cat --font=#{FONT} --shadow=0 --pos=#{POSITION} -o #{POSITION_OFFSET} --delay=4 --outline=4 --align=#{ALIGN} -c #{COLORS[options[:status]]}`
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Notifier
|
2
|
+
module Snarl
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def supported?
|
6
|
+
return false unless RUBY_PLATFORM =~ /(mswin|mingw)/
|
7
|
+
|
8
|
+
begin
|
9
|
+
require "snarl" unless defined?(::Snarl)
|
10
|
+
true
|
11
|
+
rescue LoadError
|
12
|
+
false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def notify(options)
|
17
|
+
::Snarl.show_message(options[:title], options[:message], options[:image])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/notifier.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "notifier/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "notifier"
|
7
|
+
s.version = Notifier::Version::STRING
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Nando Vieira"]
|
10
|
+
s.email = ["fnando.vieira@gmail.com"]
|
11
|
+
s.homepage = "http://rubygems.org/gems/notifier"
|
12
|
+
s.summary = "Send system notifications on several platforms with a simple and unified API. Currently supports Growl, Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl"
|
13
|
+
s.description = "Send system notifications on several platforms with a simple and unified API. Currently supports Growl, Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.requirements << "Growl, Libnotify, OSD, KDE (Knotify and Kdialog) or Snarl"
|
21
|
+
|
22
|
+
s.add_development_dependency "test-unit"
|
23
|
+
s.add_development_dependency "mocha"
|
24
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class NotifierTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
unsupport_all_notifiers
|
6
|
+
Notifier.default_notifier = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
test "retrieve list of supported notifiers" do
|
10
|
+
Notifier::Snarl.expects(:supported?).returns(true)
|
11
|
+
Notifier::Knotify.expects(:supported?).returns(true)
|
12
|
+
|
13
|
+
assert_equal 3, Notifier.supported_notifiers.size
|
14
|
+
end
|
15
|
+
|
16
|
+
test "return first available notifier" do
|
17
|
+
Notifier::Snarl.expects(:supported?).returns(true)
|
18
|
+
Notifier::Knotify.expects(:supported?).returns(true)
|
19
|
+
|
20
|
+
assert_equal Notifier::Snarl, Notifier.notifier
|
21
|
+
end
|
22
|
+
|
23
|
+
test "prefer default notifier" do
|
24
|
+
Notifier::Snarl.stubs(:supported?).returns(true)
|
25
|
+
Notifier::Knotify.expects(:supported?).returns(true)
|
26
|
+
|
27
|
+
Notifier.default_notifier = :knotify
|
28
|
+
|
29
|
+
assert_equal Notifier::Knotify, Notifier.notifier
|
30
|
+
end
|
31
|
+
|
32
|
+
test "send notification" do
|
33
|
+
params = {
|
34
|
+
:title => "Some title",
|
35
|
+
:message => "Some message",
|
36
|
+
:image => "image.png"
|
37
|
+
}
|
38
|
+
|
39
|
+
Notifier::Snarl.expects(:supported?).returns(true)
|
40
|
+
Notifier::Snarl.expects(:notify).with(params)
|
41
|
+
|
42
|
+
Notifier.notify(params)
|
43
|
+
end
|
44
|
+
|
45
|
+
test "retrieve list of all notifiers" do
|
46
|
+
assert_equal 7, Notifier.notifiers.size
|
47
|
+
end
|
48
|
+
|
49
|
+
test "consider Placebo as fallback notifier" do
|
50
|
+
assert_equal Notifier::Placebo, Notifier.supported_notifiers.last
|
51
|
+
end
|
52
|
+
|
53
|
+
test "return notifier by its name" do
|
54
|
+
assert_equal Notifier::OsdCat, Notifier.from_name(:osd_cat)
|
55
|
+
assert_equal Notifier::NotifySend, Notifier.from_name(:notify_send)
|
56
|
+
assert_equal Notifier::Growl, Notifier.from_name(:growl)
|
57
|
+
end
|
58
|
+
|
59
|
+
test "return notifier by its name when supported" do
|
60
|
+
Notifier::Snarl.expects(:supported?).returns(true)
|
61
|
+
|
62
|
+
assert_equal Notifier::Snarl, Notifier.supported_notifier_from_name(:snarl)
|
63
|
+
end
|
64
|
+
|
65
|
+
test "return nil when have no supported notifiers" do
|
66
|
+
assert_nil Notifier.supported_notifier_from_name(:snarl)
|
67
|
+
end
|
68
|
+
|
69
|
+
test "return nil when an invalid notifier name is provided" do
|
70
|
+
assert_nil Notifier.from_name(:invalid)
|
71
|
+
assert_nil Notifier.supported_notifier_from_name(:invalid)
|
72
|
+
end
|
73
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
gem "test-unit"
|
2
|
+
require "test/unit"
|
3
|
+
require "mocha"
|
4
|
+
|
5
|
+
require "notifier"
|
6
|
+
|
7
|
+
class Test::Unit::TestCase
|
8
|
+
private
|
9
|
+
def unsupport_all_notifiers
|
10
|
+
Notifier.notifiers.each do |notifier|
|
11
|
+
notifier.stubs(:supported?).returns(false) unless notifier == Notifier::Placebo
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: notifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Nando Vieira
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-11-12 00:00:00 -02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: test-unit
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: mocha
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :development
|
45
|
+
version_requirements: *id002
|
46
|
+
description: Send system notifications on several platforms with a simple and unified API. Currently supports Growl, Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl
|
47
|
+
email:
|
48
|
+
- fnando.vieira@gmail.com
|
49
|
+
executables: []
|
50
|
+
|
51
|
+
extensions: []
|
52
|
+
|
53
|
+
extra_rdoc_files: []
|
54
|
+
|
55
|
+
files:
|
56
|
+
- .gitignore
|
57
|
+
- Gemfile
|
58
|
+
- README.rdoc
|
59
|
+
- Rakefile
|
60
|
+
- lib/notifier.rb
|
61
|
+
- lib/notifier/growl.rb
|
62
|
+
- lib/notifier/kdialog.rb
|
63
|
+
- lib/notifier/knotify.rb
|
64
|
+
- lib/notifier/notify_send.rb
|
65
|
+
- lib/notifier/osd_cat.rb
|
66
|
+
- lib/notifier/placebo.rb
|
67
|
+
- lib/notifier/snarl.rb
|
68
|
+
- lib/notifier/version.rb
|
69
|
+
- notifier.gemspec
|
70
|
+
- test/notifier_test.rb
|
71
|
+
- test/test_helper.rb
|
72
|
+
has_rdoc: true
|
73
|
+
homepage: http://rubygems.org/gems/notifier
|
74
|
+
licenses: []
|
75
|
+
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
requirements:
|
98
|
+
- Growl, Libnotify, OSD, KDE (Knotify and Kdialog) or Snarl
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.3.7
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: Send system notifications on several platforms with a simple and unified API. Currently supports Growl, Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl
|
104
|
+
test_files:
|
105
|
+
- test/notifier_test.rb
|
106
|
+
- test/test_helper.rb
|