notifier 0.4.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -1
- data/.rubocop.yml +10 -0
- data/Gemfile +3 -1
- data/LICENSE.md +20 -0
- data/README.md +128 -0
- data/Rakefile +11 -6
- data/lib/notifier/kdialog.rb +9 -4
- data/lib/notifier/knotify.rb +7 -3
- data/lib/notifier/notify_send.rb +9 -5
- data/lib/notifier/osd_cat.rb +9 -5
- data/lib/notifier/placebo.rb +2 -0
- data/lib/notifier/snarl.rb +2 -0
- data/lib/notifier/terminal_notifier.rb +37 -0
- data/lib/notifier/version.rb +5 -3
- data/lib/notifier.rb +24 -19
- data/notifier.gemspec +19 -8
- data/test/notifier/notifier_test.rb +78 -0
- data/test/notifier/snarl_test.rb +11 -0
- data/test/test_helper.rb +14 -0
- metadata +89 -39
- data/.rspec +0 -1
- data/Gemfile.lock +0 -26
- data/README.rdoc +0 -106
- data/lib/notifier/adapters/gntp.rb +0 -89
- data/lib/notifier/adapters.rb +0 -5
- data/lib/notifier/gntp.rb +0 -37
- data/lib/notifier/growl.rb +0 -31
- data/resources/register-growl.scpt +0 -0
- data/spec/notifier_spec.rb +0 -72
- data/spec/spec_helper.rb +0 -13
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4e8f22ae020099416927c4342232f8e37631292454b51036ee75a80227da2152
|
4
|
+
data.tar.gz: bed78ad310c8577665578bc763e1e3f20f100e368d66c9f13fd460b38486bb2a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2bca083c02fb0ee73772a8f3604ca2749b6e9cee6e6f75bff623afc948b0032aee87af722b3e071391731043749a0f1d9470b472c23f405e719b78df62183b9c
|
7
|
+
data.tar.gz: a082e4f102062da75d76e21253848bf1cf56a08780a3fac4c7f2e032310e5c9c45cf7005700e84ce7d336632aa7b7ace9dd8c5493196074350c4bc6fa9dfb79e
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Nando Vieira
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the 'Software'), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
# Notifier
|
2
|
+
|
3
|
+
[![Gem](https://img.shields.io/gem/v/notifier.svg)](https://rubygems.org/gems/notifier)
|
4
|
+
[![Gem](https://img.shields.io/gem/dt/notifier.svg)](https://rubygems.org/gems/notifier)
|
5
|
+
|
6
|
+
Send system notifications on several platforms with a simple and unified API.
|
7
|
+
Currently supports:
|
8
|
+
|
9
|
+
- terminal-notifier (Notification Center wrapper for Mac OS X)
|
10
|
+
- GNTP Protocol (Growl, with Vagrant support)
|
11
|
+
- Kdialog (Linux/KDE)
|
12
|
+
- Knotify (Linux/KDE)
|
13
|
+
- OSD Cat (Linux)
|
14
|
+
- Libnotify (Linux)
|
15
|
+
- Snarl (Windows)
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
gem install notifier
|
20
|
+
|
21
|
+
### Mac OS X
|
22
|
+
|
23
|
+
#### terminal-notifier
|
24
|
+
|
25
|
+
- Install terminal-notifier - https://github.com/alloy/terminal-notifier
|
26
|
+
|
27
|
+
terminal-notifier also supports two additional flags:
|
28
|
+
|
29
|
+
- `subtitle`
|
30
|
+
- `sound`
|
31
|
+
|
32
|
+
See terminal-notifier's help for additional information.
|
33
|
+
|
34
|
+
### Linux
|
35
|
+
|
36
|
+
If you're a linux guy, you can choose one of these methods:
|
37
|
+
|
38
|
+
- Install libnotify-bin and its dependencies:
|
39
|
+
`sudo aptitude install libnotify-bin`
|
40
|
+
- Install xosd-bin: `sudo aptitude install xosd-bin`
|
41
|
+
- KDE users don't need to install anything: Test Notifier will use +knotify+ or
|
42
|
+
+kdialog+.
|
43
|
+
|
44
|
+
### Windows
|
45
|
+
|
46
|
+
- Install Snarl: download from http://www.fullphat.net
|
47
|
+
- Install ruby-snarl: `gem install ruby-snarl`
|
48
|
+
|
49
|
+
## Usage
|
50
|
+
|
51
|
+
Notifier will try to detect which notifiers are available in your system. So you
|
52
|
+
can just send a message:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
Notifier.notify(
|
56
|
+
image: "image.png",
|
57
|
+
title: "Testing Notifier",
|
58
|
+
message: "Sending an important message!"
|
59
|
+
)
|
60
|
+
```
|
61
|
+
|
62
|
+
Not all notifiers support the image option, therefore it will be ignored.
|
63
|
+
|
64
|
+
If your system support more than one notifier, you can specify which one you
|
65
|
+
prefer:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
Notifier.default_notifier = :notify_send
|
69
|
+
```
|
70
|
+
|
71
|
+
The available names are `terminal_notifier`, `kdialog`, `knotify`,
|
72
|
+
`notify_send`, `osd_cat`, and `snarl`.
|
73
|
+
|
74
|
+
There are several helper methods that you can use in order to retrieve
|
75
|
+
notifiers.
|
76
|
+
|
77
|
+
- `Notifier.notifier`: return the first supported notifier
|
78
|
+
- `Notifier.notifiers`: return all notifiers
|
79
|
+
- `Notifier.supported_notifiers`: return only supported notifiers
|
80
|
+
- `Notifier.from_name(name)`: find notifier by its name
|
81
|
+
- `Notifier.supported_notifier_from_name(name)`: find a supported notifier by
|
82
|
+
its name
|
83
|
+
|
84
|
+
## Creating custom notifiers
|
85
|
+
|
86
|
+
To create a new notifier, just create a module on `Notifier` namespace that
|
87
|
+
implements the following interface:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
module Notifier
|
91
|
+
module MyCustomNotifier
|
92
|
+
def self.supported?
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.notify(options)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
## Maintainer
|
102
|
+
|
103
|
+
- Nando Vieira - https://nandovieira.com
|
104
|
+
|
105
|
+
## Contributors
|
106
|
+
|
107
|
+
https://github.com/fnando/notifier/graphs/contributors
|
108
|
+
|
109
|
+
## License
|
110
|
+
|
111
|
+
(The MIT License)
|
112
|
+
|
113
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
114
|
+
this software and associated documentation files (the 'Software'), to deal in
|
115
|
+
the Software without restriction, including without limitation the rights to
|
116
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
117
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
118
|
+
subject to the following conditions:
|
119
|
+
|
120
|
+
The above copyright notice and this permission notice shall be included in all
|
121
|
+
copies or substantial portions of the Software.
|
122
|
+
|
123
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
124
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
125
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
126
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
127
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
128
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
-
|
2
|
-
Bundler::GemHelper.install_tasks
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
3
|
+
require "bundler/gem_tasks"
|
4
4
|
require "rake/testtask"
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
require "rubocop/rake_task"
|
6
|
+
|
7
|
+
Rake::TestTask.new(:test) do |t|
|
8
|
+
t.libs << "test"
|
8
9
|
t.test_files = FileList["test/**/*_test.rb"]
|
9
|
-
t.
|
10
|
+
t.warning = false
|
10
11
|
end
|
12
|
+
|
13
|
+
RuboCop::RakeTask.new
|
14
|
+
|
15
|
+
task default: %i[test rubocop]
|
data/lib/notifier/kdialog.rb
CHANGED
@@ -1,19 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Notifier
|
2
4
|
module Kdialog
|
3
5
|
extend self
|
4
6
|
|
5
7
|
def supported?
|
6
|
-
Notifier.os?(/(linux|freebsd)/) &&
|
8
|
+
Notifier.os?(/(linux|freebsd)/) &&
|
9
|
+
`which kdialog > /dev/null` &&
|
10
|
+
$CHILD_STATUS == 0
|
7
11
|
end
|
8
12
|
|
9
13
|
def notify(options)
|
10
14
|
command = [
|
11
15
|
"kdialog",
|
12
|
-
"--title", options[:title],
|
13
|
-
"--passivepopup", options[:message],
|
16
|
+
"--title", options[:title].to_s,
|
17
|
+
"--passivepopup", options[:message].to_s,
|
18
|
+
"5"
|
14
19
|
]
|
15
20
|
|
16
|
-
Thread.new { system(*command) }
|
21
|
+
Thread.new { system(*command) }.join
|
17
22
|
end
|
18
23
|
end
|
19
24
|
end
|
data/lib/notifier/knotify.rb
CHANGED
@@ -1,19 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Notifier
|
2
4
|
module Knotify
|
3
5
|
extend self
|
4
6
|
|
5
7
|
def supported?
|
6
|
-
Notifier.os?(/(linux|freebsd)/) &&
|
8
|
+
Notifier.os?(/(linux|freebsd)/) &&
|
9
|
+
`ps -Al | grep dcop` &&
|
10
|
+
$CHILD_STATUS == 0
|
7
11
|
end
|
8
12
|
|
9
13
|
def notify(options)
|
10
14
|
command = [
|
11
15
|
"dcop", "knotify", "default", "notify", "eventname",
|
12
|
-
options[:title], options[:message],
|
16
|
+
options[:title].to_s, options[:message].to_s,
|
13
17
|
"", "", "16", "2"
|
14
18
|
]
|
15
19
|
|
16
|
-
Thread.new { system(*command) }
|
20
|
+
Thread.new { system(*command) }.join
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
data/lib/notifier/notify_send.rb
CHANGED
@@ -1,20 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Notifier
|
2
4
|
module NotifySend
|
3
5
|
extend self
|
4
6
|
|
5
7
|
def supported?
|
6
|
-
Notifier.os?(/(linux|freebsd)/) &&
|
8
|
+
Notifier.os?(/(linux|freebsd)/) &&
|
9
|
+
`which notify-send > /dev/null` &&
|
10
|
+
$CHILD_STATUS == 0
|
7
11
|
end
|
8
12
|
|
9
13
|
def notify(options)
|
10
14
|
command = [
|
11
15
|
"notify-send", "-i",
|
12
|
-
options[:image],
|
13
|
-
options[:title],
|
14
|
-
options[:message]
|
16
|
+
options[:image].to_s,
|
17
|
+
options[:title].to_s,
|
18
|
+
options[:message].to_s
|
15
19
|
]
|
16
20
|
|
17
|
-
Thread.new { system(*command) }
|
21
|
+
Thread.new { system(*command) }.join
|
18
22
|
end
|
19
23
|
end
|
20
24
|
end
|
data/lib/notifier/osd_cat.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Notifier
|
2
4
|
module OsdCat
|
3
5
|
extend self
|
4
6
|
|
5
7
|
def supported?
|
6
|
-
Notifier.os?(/(linux|freebsd)/) &&
|
8
|
+
Notifier.os?(/(linux|freebsd)/) &&
|
9
|
+
`which osd_cat > /dev/null` &&
|
10
|
+
$CHILD_STATUS == 0
|
7
11
|
end
|
8
12
|
|
9
13
|
def notify(options)
|
10
|
-
color = options.fetch(:color, "white")
|
14
|
+
color = options.fetch(:color, "white").to_s
|
11
15
|
|
12
16
|
command = [
|
13
17
|
"osd_cat",
|
@@ -18,15 +22,15 @@ module Notifier
|
|
18
22
|
"--align", "center",
|
19
23
|
"--font", "-bitstream-bitstream charter-bold-r-*-*-*-350-*-*-*-*-*-*",
|
20
24
|
"--delay", "5",
|
21
|
-
"--outline", "4"
|
25
|
+
"--outline", "4"
|
22
26
|
]
|
23
27
|
|
24
28
|
Thread.new do
|
25
|
-
Open3.popen3(*command) do |stdin,
|
29
|
+
Open3.popen3(*command) do |stdin, _stdout, _stderr|
|
26
30
|
stdin.puts options[:message]
|
27
31
|
stdin.close
|
28
32
|
end
|
29
|
-
end
|
33
|
+
end.join
|
30
34
|
end
|
31
35
|
end
|
32
36
|
end
|
data/lib/notifier/placebo.rb
CHANGED
data/lib/notifier/snarl.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Notifier
|
4
|
+
module TerminalNotifier
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def supported?
|
8
|
+
Notifier.os?(/darwin/) && `which terminal-notifier` && $CHILD_STATUS == 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def notify(options)
|
12
|
+
command = [
|
13
|
+
"terminal-notifier",
|
14
|
+
"-group", "notifier-rubygems",
|
15
|
+
"-title", options[:title].to_s,
|
16
|
+
"-appIcon", options.fetch(:image, "").to_s,
|
17
|
+
"-message", options[:message].to_s,
|
18
|
+
"-subtitle", options.fetch(:subtitle, "").to_s
|
19
|
+
]
|
20
|
+
|
21
|
+
# -sound with an empty string (e.g., "") will trigger the
|
22
|
+
# default sound so we need to check for it.
|
23
|
+
if options[:sound]
|
24
|
+
command.concat([
|
25
|
+
"-sound",
|
26
|
+
options.fetch(:sound, "default").to_s
|
27
|
+
])
|
28
|
+
end
|
29
|
+
|
30
|
+
Thread.new do
|
31
|
+
Open3.popen3(*command) do |_stdin, _stdout, _stderr|
|
32
|
+
# noop
|
33
|
+
end
|
34
|
+
end.join
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/notifier/version.rb
CHANGED
data/lib/notifier.rb
CHANGED
@@ -1,20 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "open3"
|
2
4
|
require "socket"
|
3
5
|
require "digest/md5"
|
4
6
|
require "timeout"
|
5
7
|
require "rbconfig"
|
8
|
+
require "English"
|
6
9
|
|
7
10
|
module Notifier
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
autoload :Version, "notifier/version"
|
17
|
-
autoload :Adapters, "notifier/adapters"
|
11
|
+
require "notifier/snarl"
|
12
|
+
require "notifier/osd_cat"
|
13
|
+
require "notifier/knotify"
|
14
|
+
require "notifier/kdialog"
|
15
|
+
require "notifier/notify_send"
|
16
|
+
require "notifier/placebo"
|
17
|
+
require "notifier/terminal_notifier"
|
18
|
+
require "notifier/version"
|
18
19
|
|
19
20
|
extend self
|
20
21
|
|
@@ -22,6 +23,10 @@ module Notifier
|
|
22
23
|
attr_accessor :default_notifier
|
23
24
|
end
|
24
25
|
|
26
|
+
def skip_constants
|
27
|
+
@skip_constants ||= %w[Placebo Adapters Version]
|
28
|
+
end
|
29
|
+
|
25
30
|
def notifier
|
26
31
|
supported_notifier_from_name(default_notifier) || supported_notifiers.first
|
27
32
|
end
|
@@ -31,32 +36,32 @@ module Notifier
|
|
31
36
|
end
|
32
37
|
|
33
38
|
def notifiers
|
34
|
-
constants.
|
35
|
-
const_get(name) unless
|
36
|
-
end
|
39
|
+
constants.filter_map do |name|
|
40
|
+
const_get(name) unless skip_constants.include?(name.to_s)
|
41
|
+
end + [Placebo]
|
37
42
|
end
|
38
43
|
|
39
44
|
def supported_notifiers
|
40
|
-
notifiers.select
|
45
|
+
notifiers.select(&:supported?)
|
41
46
|
end
|
42
47
|
|
43
48
|
def from_name(name)
|
44
49
|
const_get(classify(name.to_s))
|
45
|
-
rescue
|
50
|
+
rescue StandardError
|
46
51
|
nil
|
47
52
|
end
|
48
53
|
|
49
54
|
def supported_notifier_from_name(name)
|
50
55
|
notifier = from_name(name)
|
51
|
-
notifier
|
56
|
+
notifier&.supported? ? notifier : nil
|
52
57
|
end
|
53
58
|
|
54
59
|
def os?(regex)
|
55
60
|
RUBY_PLATFORM =~ regex || RbConfig::CONFIG["host_os"] =~ regex
|
56
61
|
end
|
57
62
|
|
58
|
-
private
|
59
|
-
|
60
|
-
|
63
|
+
private def classify(string)
|
64
|
+
string.gsub(/_(.)/sm) { Regexp.last_match(1).upcase.to_s }
|
65
|
+
.gsub(/^(.)/) { Regexp.last_match(1).upcase.to_s }
|
61
66
|
end
|
62
67
|
end
|
data/notifier.gemspec
CHANGED
@@ -1,24 +1,35 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
require "notifier/version"
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "./lib/notifier/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "notifier"
|
7
7
|
s.version = Notifier::Version::STRING
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["Nando Vieira"]
|
10
|
-
s.email = ["fnando.
|
10
|
+
s.email = ["me@fnando.com"]
|
11
11
|
s.homepage = "http://rubygems.org/gems/notifier"
|
12
|
-
s.summary = "Send system notifications on several platforms with a
|
12
|
+
s.summary = "Send system notifications on several platforms with a " \
|
13
|
+
"simple and unified API. Currently supports Libnotify, " \
|
14
|
+
"OSD, KDE (Knotify and Kdialog) and Snarl"
|
13
15
|
s.description = s.summary
|
16
|
+
s.required_ruby_version = ">= 2.7"
|
17
|
+
s.metadata["rubygems_mfa_required"] = "true"
|
14
18
|
|
15
19
|
s.files = `git ls-files`.split("\n")
|
16
20
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map do |f|
|
22
|
+
File.basename(f)
|
23
|
+
end
|
18
24
|
s.require_paths = ["lib"]
|
19
25
|
|
20
|
-
s.requirements << "
|
26
|
+
s.requirements << "terminal-notifier, Libnotify, OSD, KDE (Knotify and " \
|
27
|
+
"Kdialog) or Snarl"
|
21
28
|
|
22
|
-
s.add_development_dependency "
|
29
|
+
s.add_development_dependency "minitest-utils"
|
30
|
+
s.add_development_dependency "mocha"
|
23
31
|
s.add_development_dependency "rake"
|
32
|
+
s.add_development_dependency "rubocop"
|
33
|
+
s.add_development_dependency "rubocop-fnando"
|
34
|
+
s.add_development_dependency "simplecov"
|
24
35
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
class NotifierTest < Minitest::Test
|
6
|
+
setup do
|
7
|
+
Notifier.notifiers.each do |notifier|
|
8
|
+
unless notifier == Notifier::Placebo
|
9
|
+
notifier.stubs(:supported?).returns(false)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Notifier.default_notifier = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
test "retrieves list of supported notifiers" do
|
17
|
+
Notifier::Snarl.stubs(:supported?).returns(true)
|
18
|
+
Notifier::Knotify.stubs(:supported?).returns(true)
|
19
|
+
|
20
|
+
assert_equal 3, Notifier.supported_notifiers.size
|
21
|
+
end
|
22
|
+
|
23
|
+
test "returns first available notifier" do
|
24
|
+
Notifier::Snarl.stubs(:supported?).returns(true)
|
25
|
+
Notifier::Knotify.stubs(:supported?).returns(true)
|
26
|
+
|
27
|
+
assert_equal Notifier::Snarl, Notifier.notifier
|
28
|
+
end
|
29
|
+
|
30
|
+
test "prefers default notifier" do
|
31
|
+
Notifier::Snarl.stubs(:supported?).returns(true)
|
32
|
+
Notifier::Knotify.stubs(:supported?).returns(true)
|
33
|
+
|
34
|
+
Notifier.default_notifier = :knotify
|
35
|
+
|
36
|
+
assert_equal Notifier::Knotify, Notifier.notifier
|
37
|
+
end
|
38
|
+
|
39
|
+
test "sends notification" do
|
40
|
+
params = {
|
41
|
+
title: "Some title",
|
42
|
+
message: "Some message",
|
43
|
+
image: "image.png"
|
44
|
+
}
|
45
|
+
|
46
|
+
Notifier::Snarl.stubs(:supported?).returns(true)
|
47
|
+
Notifier::Snarl.expects(:notify).with(params)
|
48
|
+
|
49
|
+
Notifier.notify(params)
|
50
|
+
end
|
51
|
+
|
52
|
+
test "retrieves list of all notifiers" do
|
53
|
+
assert_equal 7, Notifier.notifiers.size
|
54
|
+
end
|
55
|
+
|
56
|
+
test "considers Placebo as fallback notifier" do
|
57
|
+
assert_equal Notifier::Placebo, Notifier.supported_notifiers.last
|
58
|
+
end
|
59
|
+
|
60
|
+
test "returns notifier by its name" do
|
61
|
+
assert_equal Notifier::OsdCat, Notifier.from_name(:osd_cat)
|
62
|
+
assert_equal Notifier::NotifySend, Notifier.from_name(:notify_send)
|
63
|
+
end
|
64
|
+
|
65
|
+
test "returns notifier by its name when supported" do
|
66
|
+
Notifier::Snarl.expects(:supported?).returns(true)
|
67
|
+
assert_equal Notifier::Snarl, Notifier.supported_notifier_from_name(:snarl)
|
68
|
+
end
|
69
|
+
|
70
|
+
test "returns nil when have no supported notifiers" do
|
71
|
+
assert_nil Notifier.supported_notifier_from_name(:snarl)
|
72
|
+
end
|
73
|
+
|
74
|
+
test "returns nil when an invalid notifier name is provided" do
|
75
|
+
assert_nil Notifier.from_name(:invalid)
|
76
|
+
assert_nil Notifier.supported_notifier_from_name(:invalid)
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
class SnarlTest < Minitest::Test
|
6
|
+
test "sends notification" do
|
7
|
+
Snarl.expects(:show_message).with("TITLE", "MESSAGE", "IMAGE")
|
8
|
+
|
9
|
+
Notifier::Snarl.notify(title: "TITLE", message: "MESSAGE", image: "IMAGE")
|
10
|
+
end
|
11
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,102 +1,152 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nando Vieira
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2022-02-20 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
14
|
+
name: minitest-utils
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mocha
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
28
39
|
- !ruby/object:Gem::Version
|
29
40
|
version: '0'
|
30
41
|
- !ruby/object:Gem::Dependency
|
31
42
|
name: rake
|
32
43
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
44
|
requirements:
|
35
|
-
- -
|
45
|
+
- - ">="
|
36
46
|
- !ruby/object:Gem::Version
|
37
47
|
version: '0'
|
38
48
|
type: :development
|
39
49
|
prerelease: false
|
40
50
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
51
|
requirements:
|
43
|
-
- -
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-fnando
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
44
95
|
- !ruby/object:Gem::Version
|
45
96
|
version: '0'
|
46
97
|
description: Send system notifications on several platforms with a simple and unified
|
47
|
-
API. Currently supports
|
98
|
+
API. Currently supports Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl
|
48
99
|
email:
|
49
|
-
- fnando.
|
100
|
+
- me@fnando.com
|
50
101
|
executables: []
|
51
102
|
extensions: []
|
52
103
|
extra_rdoc_files: []
|
53
104
|
files:
|
54
|
-
- .gitignore
|
55
|
-
- .
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rubocop.yml"
|
56
107
|
- Gemfile
|
57
|
-
-
|
58
|
-
- README.
|
108
|
+
- LICENSE.md
|
109
|
+
- README.md
|
59
110
|
- Rakefile
|
60
111
|
- lib/notifier.rb
|
61
|
-
- lib/notifier/adapters.rb
|
62
|
-
- lib/notifier/adapters/gntp.rb
|
63
|
-
- lib/notifier/gntp.rb
|
64
|
-
- lib/notifier/growl.rb
|
65
112
|
- lib/notifier/kdialog.rb
|
66
113
|
- lib/notifier/knotify.rb
|
67
114
|
- lib/notifier/notify_send.rb
|
68
115
|
- lib/notifier/osd_cat.rb
|
69
116
|
- lib/notifier/placebo.rb
|
70
117
|
- lib/notifier/snarl.rb
|
118
|
+
- lib/notifier/terminal_notifier.rb
|
71
119
|
- lib/notifier/version.rb
|
72
120
|
- notifier.gemspec
|
73
|
-
-
|
74
|
-
-
|
75
|
-
-
|
121
|
+
- test/notifier/notifier_test.rb
|
122
|
+
- test/notifier/snarl_test.rb
|
123
|
+
- test/test_helper.rb
|
76
124
|
homepage: http://rubygems.org/gems/notifier
|
77
125
|
licenses: []
|
78
|
-
|
126
|
+
metadata:
|
127
|
+
rubygems_mfa_required: 'true'
|
128
|
+
post_install_message:
|
79
129
|
rdoc_options: []
|
80
130
|
require_paths:
|
81
131
|
- lib
|
82
132
|
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
-
none: false
|
84
133
|
requirements:
|
85
|
-
- -
|
134
|
+
- - ">="
|
86
135
|
- !ruby/object:Gem::Version
|
87
|
-
version: '
|
136
|
+
version: '2.7'
|
88
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
138
|
requirements:
|
91
|
-
- -
|
139
|
+
- - ">="
|
92
140
|
- !ruby/object:Gem::Version
|
93
141
|
version: '0'
|
94
142
|
requirements:
|
95
|
-
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
specification_version: 3
|
143
|
+
- terminal-notifier, Libnotify, OSD, KDE (Knotify and Kdialog) or Snarl
|
144
|
+
rubygems_version: 3.3.7
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
100
147
|
summary: Send system notifications on several platforms with a simple and unified
|
101
|
-
API. Currently supports
|
102
|
-
test_files:
|
148
|
+
API. Currently supports Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl
|
149
|
+
test_files:
|
150
|
+
- test/notifier/notifier_test.rb
|
151
|
+
- test/notifier/snarl_test.rb
|
152
|
+
- test/test_helper.rb
|
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color --format documentation
|
data/Gemfile.lock
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
notifier (0.4.1)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: http://rubygems.org/
|
8
|
-
specs:
|
9
|
-
diff-lcs (1.1.3)
|
10
|
-
rake (0.9.2.2)
|
11
|
-
rspec (2.11.0)
|
12
|
-
rspec-core (~> 2.11.0)
|
13
|
-
rspec-expectations (~> 2.11.0)
|
14
|
-
rspec-mocks (~> 2.11.0)
|
15
|
-
rspec-core (2.11.1)
|
16
|
-
rspec-expectations (2.11.3)
|
17
|
-
diff-lcs (~> 1.1.3)
|
18
|
-
rspec-mocks (2.11.2)
|
19
|
-
|
20
|
-
PLATFORMS
|
21
|
-
ruby
|
22
|
-
|
23
|
-
DEPENDENCIES
|
24
|
-
notifier!
|
25
|
-
rake
|
26
|
-
rspec
|
data/README.rdoc
DELETED
@@ -1,106 +0,0 @@
|
|
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
|
-
* GNTP Protocol (Growl, with Vagrant support)
|
7
|
-
* Kdialog (Linux/KDE)
|
8
|
-
* Knotify (Linux/KDE)
|
9
|
-
* OSD Cat (Linux)
|
10
|
-
* Libnotify (Linux)
|
11
|
-
* Snarl (Windows)
|
12
|
-
|
13
|
-
== Installation
|
14
|
-
|
15
|
-
gem install notifier
|
16
|
-
|
17
|
-
=== Mac OS X
|
18
|
-
|
19
|
-
* Install Growl - http://growl.info/
|
20
|
-
* Install the growlnotify script located on the "Extras" directory
|
21
|
-
* Open the Growl Preference Panel (System > Growl) and activate "Listen for incoming notifications" and "Allow remote application registration" options on the Network tab.
|
22
|
-
|
23
|
-
=== Linux
|
24
|
-
|
25
|
-
If you're a linux guy, you can choose one of these methods:
|
26
|
-
|
27
|
-
* Install libnotify-bin and its dependencies: <tt>sudo aptitude install libnotify-bin</tt>
|
28
|
-
* Install xosd-bin: <tt>sudo aptitude install xosd-bin</tt>
|
29
|
-
* KDE users don't need to install anything: Test Notifier will use +knotify+ or +kdialog+.
|
30
|
-
|
31
|
-
=== Windows
|
32
|
-
|
33
|
-
* Install Snarl: download from http://www.fullphat.net
|
34
|
-
* Install ruby-snarl: <tt>gem install ruby-snarl</tt>
|
35
|
-
|
36
|
-
== Usage
|
37
|
-
|
38
|
-
Notifier will try to detect which notifiers are available in your system. So you can just send a message:
|
39
|
-
|
40
|
-
Notifier.notify(
|
41
|
-
:image => "image.png",
|
42
|
-
:title => "Testing Notifier",
|
43
|
-
:message => "Sending an important message!"
|
44
|
-
)
|
45
|
-
|
46
|
-
Not all notifiers support the image option, therefore it will be ignored.
|
47
|
-
|
48
|
-
If your system support more than one notifier, you can specify which one you prefer:
|
49
|
-
|
50
|
-
Notifier.default_notifier = :notify_send
|
51
|
-
|
52
|
-
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>.
|
53
|
-
|
54
|
-
There are several helper methods that you can use in order to retrieve notifiers.
|
55
|
-
|
56
|
-
* <tt>Notifier.notifier</tt>: return the first supported notifier
|
57
|
-
* <tt>Notifier.notifiers</tt>: return all notifiers
|
58
|
-
* <tt>Notifier.supported_notifiers</tt>: return only supported notifiers
|
59
|
-
* <tt>Notifier.from_name(name)</tt>: find notifier by its name
|
60
|
-
* <tt>Notifier.supported_notifier_from_name(name)</tt>: find a supported notifier by its name
|
61
|
-
|
62
|
-
== Creating custom notifiers
|
63
|
-
|
64
|
-
To create a new notifier, just create a module on <tt>Notifier</tt> namespace that implements the following interface:
|
65
|
-
|
66
|
-
module Notifier
|
67
|
-
module MyCustomNotifier
|
68
|
-
def self.supported?
|
69
|
-
end
|
70
|
-
|
71
|
-
def self.notify(options)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
== Maintainer
|
77
|
-
|
78
|
-
* Nando Vieira - http://nandovieira.com.br
|
79
|
-
|
80
|
-
== Contributors
|
81
|
-
|
82
|
-
* Olek Janiszewski
|
83
|
-
* David Miani
|
84
|
-
|
85
|
-
== License
|
86
|
-
|
87
|
-
(The MIT License)
|
88
|
-
|
89
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
90
|
-
a copy of this software and associated documentation files (the
|
91
|
-
'Software'), to deal in the Software without restriction, including
|
92
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
93
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
94
|
-
permit persons to whom the Software is furnished to do so, subject to
|
95
|
-
the following conditions:
|
96
|
-
|
97
|
-
The above copyright notice and this permission notice shall be
|
98
|
-
included in all copies or substantial portions of the Software.
|
99
|
-
|
100
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
101
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
102
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
103
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
104
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
105
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
106
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,89 +0,0 @@
|
|
1
|
-
module Notifier
|
2
|
-
module Adapters
|
3
|
-
class GNTP
|
4
|
-
attr_accessor :application_name
|
5
|
-
attr_accessor :host
|
6
|
-
attr_accessor :port
|
7
|
-
attr_accessor :password
|
8
|
-
|
9
|
-
def initialize(options = {})
|
10
|
-
if options.kind_of?(String)
|
11
|
-
options = {:name => options}
|
12
|
-
end
|
13
|
-
|
14
|
-
@application_name = options.fetch(:name, "GNTP/Ruby")
|
15
|
-
@host = options.fetch(:host, "127.0.0.1")
|
16
|
-
@port = options.fetch(:port, 23053)
|
17
|
-
@password = options.fetch(:password, nil)
|
18
|
-
end
|
19
|
-
|
20
|
-
def line_break(number = 1)
|
21
|
-
"\r\n" * number
|
22
|
-
end
|
23
|
-
|
24
|
-
def write(*contents)
|
25
|
-
contents.map! do |content|
|
26
|
-
content.force_encoding("utf-8") rescue content
|
27
|
-
end
|
28
|
-
|
29
|
-
socket = TCPSocket.open(host, port)
|
30
|
-
message = [*contents, line_break(2)].join(line_break)
|
31
|
-
socket.write(message)
|
32
|
-
|
33
|
-
"".tap do |response|
|
34
|
-
while chunk = socket.gets
|
35
|
-
break if chunk == line_break
|
36
|
-
response << chunk
|
37
|
-
end
|
38
|
-
|
39
|
-
socket.close
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def notify(options)
|
44
|
-
name = options.fetch(:name, "notification")
|
45
|
-
register(name)
|
46
|
-
|
47
|
-
icon = fetch_icon(options[:icon])
|
48
|
-
|
49
|
-
result = write "GNTP/1.0 NOTIFY NONE",
|
50
|
-
"Application-Name: #{application_name}",
|
51
|
-
"Notification-Name: #{name}",
|
52
|
-
"Notification-Title: #{options[:title]}",
|
53
|
-
"Notification-Text: #{options[:message]}",
|
54
|
-
"Notification-Icon: x-growl-resource://#{icon[:identifier]}",
|
55
|
-
"Notification-Sticky: #{bool options[:sticky]}",
|
56
|
-
nil,
|
57
|
-
"Identifier: #{icon[:identifier]}",
|
58
|
-
"Length: #{icon[:size]}",
|
59
|
-
nil,
|
60
|
-
icon[:contents]
|
61
|
-
end
|
62
|
-
|
63
|
-
def fetch_icon(path)
|
64
|
-
contents = File.open(path, "rb") {|f| f.read }
|
65
|
-
|
66
|
-
{
|
67
|
-
:identifier => Digest::MD5.hexdigest(contents),
|
68
|
-
:contents => contents,
|
69
|
-
:size => contents.bytesize
|
70
|
-
}
|
71
|
-
end
|
72
|
-
|
73
|
-
def bool(boolean)
|
74
|
-
{true => "Yes", false => "No"}[boolean]
|
75
|
-
end
|
76
|
-
|
77
|
-
def register(name)
|
78
|
-
result = write(
|
79
|
-
"GNTP/1.0 REGISTER NONE",
|
80
|
-
"Application-Name: #{application_name}",
|
81
|
-
"Notifications-count: 1",
|
82
|
-
nil,
|
83
|
-
"Notification-Name: #{name}",
|
84
|
-
"Notification-Enabled: True"
|
85
|
-
)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
data/lib/notifier/adapters.rb
DELETED
data/lib/notifier/gntp.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
module Notifier
|
2
|
-
module GNTP extend self
|
3
|
-
def supported?
|
4
|
-
Timeout.timeout(1) { TCPSocket.new(host, port).close }
|
5
|
-
true
|
6
|
-
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Timeout::Error
|
7
|
-
false
|
8
|
-
end
|
9
|
-
|
10
|
-
def port
|
11
|
-
ENV.fetch("GNTP_PORT", 23053)
|
12
|
-
end
|
13
|
-
|
14
|
-
def host
|
15
|
-
ENV["GNTP_HOST"] || ssh_connection || "127.0.0.1"
|
16
|
-
end
|
17
|
-
|
18
|
-
def ssh_connection
|
19
|
-
ENV["SSH_CONNECTION"][/^([^ ]+)/, 1] if ENV["SSH_CONNECTION"]
|
20
|
-
end
|
21
|
-
|
22
|
-
def notify(options)
|
23
|
-
gntp = Adapters::GNTP.new({
|
24
|
-
:name => "test_notifier",
|
25
|
-
:host => host,
|
26
|
-
:port => port
|
27
|
-
})
|
28
|
-
|
29
|
-
gntp.notify({
|
30
|
-
:name => "status",
|
31
|
-
:title => options[:title],
|
32
|
-
:message => options[:message],
|
33
|
-
:icon => options[:image]
|
34
|
-
})
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/lib/notifier/growl.rb
DELETED
@@ -1,31 +0,0 @@
|
|
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
|
-
Notifier.os?(/darwin/) && `which growlnotify` && $? == 0
|
10
|
-
end
|
11
|
-
|
12
|
-
def notify(options)
|
13
|
-
register
|
14
|
-
command = [
|
15
|
-
"growlnotify",
|
16
|
-
"--name", "test_notifier",
|
17
|
-
"--image", options.fetch(:image, ''),
|
18
|
-
"--priority", "2",
|
19
|
-
"--message", options[:message],
|
20
|
-
options[:title]
|
21
|
-
]
|
22
|
-
|
23
|
-
Thread.new { system(*command) }
|
24
|
-
end
|
25
|
-
|
26
|
-
def register
|
27
|
-
return if File.file?(FILE)
|
28
|
-
system "osascript #{SCRIPT} > #{FILE}"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
Binary file
|
data/spec/notifier_spec.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Notifier do
|
4
|
-
before do
|
5
|
-
unsupport_all_notifiers
|
6
|
-
Notifier.default_notifier = nil
|
7
|
-
end
|
8
|
-
|
9
|
-
it "retrieves list of supported notifiers" do
|
10
|
-
Notifier::Snarl.stub :supported? => true
|
11
|
-
Notifier::Knotify.stub :supported? => true
|
12
|
-
|
13
|
-
expect(Notifier.supported_notifiers.size).to eql(3)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "returns first available notifier" do
|
17
|
-
Notifier::Snarl.stub :supported? => true
|
18
|
-
Notifier::Knotify.stub :supported? => true
|
19
|
-
|
20
|
-
expect(Notifier.notifier).to eql(Notifier::Snarl)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "prefers default notifier" do
|
24
|
-
Notifier::Snarl.stub :supported? => true
|
25
|
-
Notifier::Knotify.stub :supported? => true
|
26
|
-
|
27
|
-
Notifier.default_notifier = :knotify
|
28
|
-
|
29
|
-
expect(Notifier.notifier).to eql(Notifier::Knotify)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "sends notification" do
|
33
|
-
params = {
|
34
|
-
:title => "Some title",
|
35
|
-
:message => "Some message",
|
36
|
-
:image => "image.png"
|
37
|
-
}
|
38
|
-
|
39
|
-
Notifier::Snarl.stub :supported? => true
|
40
|
-
Notifier::Snarl.should_receive(:notify).with(params)
|
41
|
-
|
42
|
-
Notifier.notify(params)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "retrieves list of all notifiers" do
|
46
|
-
expect(Notifier.notifiers.size).to eql(8)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "considers Placebo as fallback notifier" do
|
50
|
-
expect(Notifier.supported_notifiers.last).to eql(Notifier::Placebo)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "returns notifier by its name" do
|
54
|
-
expect(Notifier.from_name(:osd_cat)).to eql(Notifier::OsdCat)
|
55
|
-
expect(Notifier.from_name(:notify_send)).to eql(Notifier::NotifySend)
|
56
|
-
expect(Notifier.from_name(:growl)).to eql(Notifier::Growl)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "returns notifier by its name when supported" do
|
60
|
-
Notifier::Snarl.stub :supported? => true
|
61
|
-
expect(Notifier.supported_notifier_from_name(:snarl)).to eql(Notifier::Snarl)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "returns nil when have no supported notifiers" do
|
65
|
-
expect(Notifier.supported_notifier_from_name(:snarl)).to be_nil
|
66
|
-
end
|
67
|
-
|
68
|
-
it "returns nil when an invalid notifier name is provided" do
|
69
|
-
expect(Notifier.from_name(:invalid)).to be_nil
|
70
|
-
expect(Notifier.supported_notifier_from_name(:invalid)).to be_nil
|
71
|
-
end
|
72
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require "notifier"
|
2
|
-
|
3
|
-
module SpecHelpers
|
4
|
-
def unsupport_all_notifiers
|
5
|
-
Notifier.notifiers.each do |notifier|
|
6
|
-
notifier.stub :supported? => false unless notifier == Notifier::Placebo
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
RSpec.configure do |config|
|
12
|
-
config.include SpecHelpers
|
13
|
-
end
|