notifier 0.5.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ded78a65a591a7d25fc841c511ed827622fc1463
4
- data.tar.gz: db832909bd190d77d8dcdd2248a60a4098e616db
2
+ SHA256:
3
+ metadata.gz: c842629dcf6da711e4d5979dd03a395e35e4aa752271f80f3fca65f50aff3bf9
4
+ data.tar.gz: aec07ca38b8a39779dbf9e65383ea26cb140dc46b7069fb79798853ef9b3f611
5
5
  SHA512:
6
- metadata.gz: 2e26970c850341800b43a6d61865f82b95db278ed0666e8a550848d51b479cf837dbceaeb950224f0c1cceda8830f5f4ba0e69b027f2bf624a444adf08436d54
7
- data.tar.gz: 96e7619e015a14c3383ccedca1423ce638cbbc771ac5789d9f455901b1bbf34d63c5356c70d9a7ef43107fa46eaf80c19263812f3ac02d55af1289cd9dee1f80
6
+ metadata.gz: a274ece6e94cb827c710d249ec9540551a116c2f99dbfa78ff8fe6c0458e9aa0c3fbd36df587cff7bbfdde4b9d1f213d1b07c5c9e3c66c1854f9a5f49e40af8a
7
+ data.tar.gz: d741722e7fea144a2c920c4add06a7fab380cb9b591c437c095707bab9cbbb21cbfb3a929d2d315c9e19ea468d85b4214bdefb77b1cfbd6a05c3cc7aaf942242
data/.gitignore CHANGED
@@ -3,3 +3,4 @@ pkg/*
3
3
  .bundle
4
4
  .DS_Store
5
5
  *.lock
6
+ /coverage
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ ---
2
+ inherit_gem:
3
+ rubocop-fnando: .rubocop.yml
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.7
7
+ NewCops: enable
8
+ Exclude:
9
+ - vendor/**/*
10
+ - gemfiles/**/*
data/Gemfile CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "http://rubygems.org"
2
4
  gemspec
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
- require "bundler"
2
- Bundler::GemHelper.install_tasks
1
+ # frozen_string_literal: true
3
2
 
3
+ require "bundler/gem_tasks"
4
4
  require "rake/testtask"
5
- Rake::TestTask.new do |t|
6
- t.libs += %w[test lib]
7
- t.ruby_opts = %w[-rubygems]
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.verbose = true
10
+ t.warning = false
10
11
  end
12
+
13
+ RuboCop::RakeTask.new
14
+
15
+ task default: %i[test rubocop]
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Notifier
4
+ module Hud
5
+ extend self
6
+
7
+ def supported?
8
+ Notifier.os?(/darwin/) && hud?
9
+ end
10
+
11
+ def uri
12
+ URI("http://127.0.0.1:32323/hud")
13
+ end
14
+
15
+ def hud?
16
+ return @hud unless @hud.nil?
17
+
18
+ @hud = begin
19
+ response = Net::HTTP.get_response(uri)
20
+ response.code == "200"
21
+ rescue StandardError
22
+ false
23
+ end
24
+
25
+ @hud
26
+ end
27
+
28
+ def notify(options)
29
+ Thread.new do
30
+ Net::HTTP.post_form(
31
+ uri,
32
+ {
33
+ "title" => options[:title].to_s,
34
+ "message" => options[:message].to_s,
35
+ "symbolName" => options[:image].to_s
36
+ }
37
+ )
38
+ end.join
39
+ end
40
+ end
41
+ end
@@ -1,9 +1,13 @@
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)/) && `which kdialog > /dev/null` && $? == 0
8
+ Notifier.os?(/(linux|freebsd)/) &&
9
+ `which kdialog > /dev/null` &&
10
+ $CHILD_STATUS == 0
7
11
  end
8
12
 
9
13
  def notify(options)
@@ -1,16 +1,28 @@
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)/) && `ps -Al | grep dcop` && $? == 0
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
- "dcop", "knotify", "default", "notify", "eventname",
12
- options[:title].to_s, options[:message].to_s,
13
- "", "", "16", "2"
15
+ "dcop",
16
+ "knotify",
17
+ "default",
18
+ "notify",
19
+ "eventname",
20
+ options[:title].to_s,
21
+ options[:message].to_s,
22
+ "",
23
+ "",
24
+ "16",
25
+ "2"
14
26
  ]
15
27
 
16
28
  Thread.new { system(*command) }.join
@@ -1,9 +1,13 @@
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)/) && `which notify-send > /dev/null` && $? == 0
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)
@@ -1,9 +1,13 @@
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)/) && `which osd_cat > /dev/null` && $? == 0
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)
@@ -18,11 +22,11 @@ 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, stdout, stderr|
29
+ Open3.popen3(*command) do |stdin, _stdout, _stderr|
26
30
  stdin.puts options[:message]
27
31
  stdin.close
28
32
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Notifier
2
4
  module Placebo
3
5
  extend self
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Notifier
2
4
  module Snarl
3
5
  extend self
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Notifier
2
4
  module TerminalNotifier
3
5
  extend self
4
6
 
5
7
  def supported?
6
- Notifier.os?(/darwin/) && `which terminal-notifier` && $? == 0
8
+ Notifier.os?(/darwin/) && `which terminal-notifier` && $CHILD_STATUS == 0
7
9
  end
8
10
 
9
11
  def notify(options)
@@ -12,10 +14,24 @@ module Notifier
12
14
  "-group", "notifier-rubygems",
13
15
  "-title", options[:title].to_s,
14
16
  "-appIcon", options.fetch(:image, "").to_s,
15
- "-message", options[:message].to_s
17
+ "-message", options[:message].to_s,
18
+ "-subtitle", options.fetch(:subtitle, "").to_s
16
19
  ]
17
20
 
18
- Thread.new { system(*command) }.join
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
19
35
  end
20
36
  end
21
37
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Notifier
2
4
  module Version
3
- MAJOR = 0
4
- MINOR = 5
5
- PATCH = 1
5
+ MAJOR = 1
6
+ MINOR = 1
7
+ PATCH = 0
6
8
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
9
  end
8
10
  end
data/lib/notifier.rb CHANGED
@@ -1,13 +1,16 @@
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"
9
+ require "net/http"
6
10
 
7
11
  module Notifier
8
- require "notifier/growl"
9
- require "notifier/gntp"
10
12
  require "notifier/snarl"
13
+ require "notifier/hud"
11
14
  require "notifier/osd_cat"
12
15
  require "notifier/knotify"
13
16
  require "notifier/kdialog"
@@ -15,7 +18,6 @@ module Notifier
15
18
  require "notifier/placebo"
16
19
  require "notifier/terminal_notifier"
17
20
  require "notifier/version"
18
- require "notifier/adapters"
19
21
 
20
22
  extend self
21
23
 
@@ -23,6 +25,10 @@ module Notifier
23
25
  attr_accessor :default_notifier
24
26
  end
25
27
 
28
+ def skip_constants
29
+ @skip_constants ||= %w[Placebo Adapters Version]
30
+ end
31
+
26
32
  def notifier
27
33
  supported_notifier_from_name(default_notifier) || supported_notifiers.first
28
34
  end
@@ -32,32 +38,32 @@ module Notifier
32
38
  end
33
39
 
34
40
  def notifiers
35
- constants.collect do |name|
36
- const_get(name) unless %w[Placebo Adapters Version].include?(name.to_s)
37
- end.compact + [Placebo]
41
+ constants.filter_map do |name|
42
+ const_get(name) unless skip_constants.include?(name.to_s)
43
+ end + [Placebo]
38
44
  end
39
45
 
40
46
  def supported_notifiers
41
- notifiers.select {|notifier| notifier.supported?}
47
+ notifiers.select(&:supported?)
42
48
  end
43
49
 
44
50
  def from_name(name)
45
51
  const_get(classify(name.to_s))
46
- rescue Exception
52
+ rescue StandardError
47
53
  nil
48
54
  end
49
55
 
50
56
  def supported_notifier_from_name(name)
51
57
  notifier = from_name(name)
52
- notifier && notifier.supported? ? notifier : nil
58
+ notifier&.supported? ? notifier : nil
53
59
  end
54
60
 
55
61
  def os?(regex)
56
62
  RUBY_PLATFORM =~ regex || RbConfig::CONFIG["host_os"] =~ regex
57
63
  end
58
64
 
59
- private
60
- def classify(string)
61
- string.gsub(/_(.)/sm) { "#{$1.upcase}" }.gsub(/^(.)/) { "#{$1.upcase}" }
65
+ private def classify(string)
66
+ string.gsub(/_(.)/sm) { Regexp.last_match(1).upcase.to_s }
67
+ .gsub(/^(.)/) { Regexp.last_match(1).upcase.to_s }
62
68
  end
63
69
  end
data/notifier.gemspec CHANGED
@@ -1,24 +1,36 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
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.vieira@gmail.com"]
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 simple and unified API. Currently supports Growl, Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl"
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{ |f| File.basename(f) }
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 << "Growl, terminal-notifier, Libnotify, OSD, KDE (Knotify and Kdialog) or Snarl"
26
+ s.requirements << "terminal-notifier, Libnotify, OSD, KDE (Knotify and " \
27
+ "Kdialog) or Snarl"
21
28
 
22
- s.add_development_dependency "rspec"
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"
35
+ s.add_development_dependency "test_notifier"
24
36
  end
@@ -0,0 +1,83 @@
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
+ teardown do
17
+ Notifier.default_notifier = :hud
18
+ end
19
+
20
+ test "retrieves list of supported notifiers" do
21
+ Notifier::Snarl.stubs(:supported?).returns(true)
22
+ Notifier::Knotify.stubs(:supported?).returns(true)
23
+
24
+ assert_equal 3, Notifier.supported_notifiers.size
25
+ end
26
+
27
+ test "returns first available notifier" do
28
+ Notifier::Snarl.stubs(:supported?).returns(true)
29
+ Notifier::Knotify.stubs(:supported?).returns(true)
30
+
31
+ assert_equal Notifier::Snarl, Notifier.notifier
32
+ end
33
+
34
+ test "prefers default notifier" do
35
+ Notifier::Snarl.stubs(:supported?).returns(true)
36
+ Notifier::Knotify.stubs(:supported?).returns(true)
37
+
38
+ Notifier.default_notifier = :knotify
39
+
40
+ assert_equal Notifier::Knotify, Notifier.notifier
41
+ end
42
+
43
+ test "sends notification" do
44
+ params = {
45
+ title: "Some title",
46
+ message: "Some message",
47
+ image: "image.png"
48
+ }
49
+
50
+ Notifier::Snarl.stubs(:supported?).returns(true)
51
+ Notifier::Snarl.expects(:notify).with(params)
52
+
53
+ Notifier.notify(params)
54
+ end
55
+
56
+ test "retrieves list of all notifiers" do
57
+ assert_equal 8, Notifier.notifiers.size
58
+ end
59
+
60
+ test "considers Placebo as fallback notifier" do
61
+ assert_equal Notifier::Placebo, Notifier.supported_notifiers.last
62
+ end
63
+
64
+ test "returns notifier by its name" do
65
+ assert_equal Notifier::OsdCat, Notifier.from_name(:osd_cat)
66
+ assert_equal Notifier::NotifySend, Notifier.from_name(:notify_send)
67
+ assert_equal Notifier::Hud, Notifier.from_name(:hud)
68
+ end
69
+
70
+ test "returns notifier by its name when supported" do
71
+ Notifier::Snarl.expects(:supported?).returns(true)
72
+ assert_equal Notifier::Snarl, Notifier.supported_notifier_from_name(:snarl)
73
+ end
74
+
75
+ test "returns nil when have no supported notifiers" do
76
+ assert_nil Notifier.supported_notifier_from_name(:snarl)
77
+ end
78
+
79
+ test "returns nil when an invalid notifier name is provided" do
80
+ assert_nil Notifier.from_name(:invalid)
81
+ assert_nil Notifier.supported_notifier_from_name(:invalid)
82
+ end
83
+ 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
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "simplecov"
4
+ SimpleCov.start
5
+
6
+ require "bundler/setup"
7
+ require "notifier"
8
+ require "minitest/utils"
9
+ require "minitest/autorun"
10
+
11
+ Notifier.default_notifier = :hud
12
+
13
+ module Snarl
14
+ def self.show_message(*)
15
+ end
16
+ end
metadata CHANGED
@@ -1,17 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-20 00:00:00.000000000 Z
11
+ date: 2022-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: minitest-utils
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mocha
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="
@@ -38,24 +52,78 @@ dependencies:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
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
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: test_notifier
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
41
111
  description: Send system notifications on several platforms with a simple and unified
42
- API. Currently supports Growl, Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl
112
+ API. Currently supports Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl
43
113
  email:
44
- - fnando.vieira@gmail.com
114
+ - me@fnando.com
45
115
  executables: []
46
116
  extensions: []
47
117
  extra_rdoc_files: []
48
118
  files:
49
119
  - ".gitignore"
50
- - ".rspec"
120
+ - ".rubocop.yml"
51
121
  - Gemfile
52
- - README.rdoc
122
+ - LICENSE.md
123
+ - README.md
53
124
  - Rakefile
54
125
  - lib/notifier.rb
55
- - lib/notifier/adapters.rb
56
- - lib/notifier/adapters/gntp.rb
57
- - lib/notifier/gntp.rb
58
- - lib/notifier/growl.rb
126
+ - lib/notifier/hud.rb
59
127
  - lib/notifier/kdialog.rb
60
128
  - lib/notifier/knotify.rb
61
129
  - lib/notifier/notify_send.rb
@@ -65,13 +133,14 @@ files:
65
133
  - lib/notifier/terminal_notifier.rb
66
134
  - lib/notifier/version.rb
67
135
  - notifier.gemspec
68
- - resources/register-growl.scpt
69
- - spec/notifier_spec.rb
70
- - spec/spec_helper.rb
136
+ - test/notifier/notifier_test.rb
137
+ - test/notifier/snarl_test.rb
138
+ - test/test_helper.rb
71
139
  homepage: http://rubygems.org/gems/notifier
72
140
  licenses: []
73
- metadata: {}
74
- post_install_message:
141
+ metadata:
142
+ rubygems_mfa_required: 'true'
143
+ post_install_message:
75
144
  rdoc_options: []
76
145
  require_paths:
77
146
  - lib
@@ -79,20 +148,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
148
  requirements:
80
149
  - - ">="
81
150
  - !ruby/object:Gem::Version
82
- version: '0'
151
+ version: '2.7'
83
152
  required_rubygems_version: !ruby/object:Gem::Requirement
84
153
  requirements:
85
154
  - - ">="
86
155
  - !ruby/object:Gem::Version
87
156
  version: '0'
88
157
  requirements:
89
- - Growl, terminal-notifier, Libnotify, OSD, KDE (Knotify and Kdialog) or Snarl
90
- rubyforge_project:
91
- rubygems_version: 2.4.6
92
- signing_key:
158
+ - terminal-notifier, Libnotify, OSD, KDE (Knotify and Kdialog) or Snarl
159
+ rubygems_version: 3.3.7
160
+ signing_key:
93
161
  specification_version: 4
94
162
  summary: Send system notifications on several platforms with a simple and unified
95
- API. Currently supports Growl, Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl
163
+ API. Currently supports Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl
96
164
  test_files:
97
- - spec/notifier_spec.rb
98
- - spec/spec_helper.rb
165
+ - test/notifier/notifier_test.rb
166
+ - test/notifier/snarl_test.rb
167
+ - test/test_helper.rb
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
data/README.rdoc DELETED
@@ -1,113 +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
- * terminal-notifier (Notification Center wrapper for Mac OS X)
7
- * GNTP Protocol (Growl, with Vagrant support)
8
- * Kdialog (Linux/KDE)
9
- * Knotify (Linux/KDE)
10
- * OSD Cat (Linux)
11
- * Libnotify (Linux)
12
- * Snarl (Windows)
13
-
14
- == Installation
15
-
16
- gem install notifier
17
-
18
- === Mac OS X
19
-
20
- Growl:
21
-
22
- * Install Growl - http://growl.info/
23
- * Install the growlnotify script located on the "Extras" directory
24
- * Open the Growl Preference Panel (System > Growl) and activate "Listen for incoming notifications" and "Allow remote application registration" options on the Network tab.
25
-
26
- terminal-notifier:
27
-
28
- * Install terminal-notifier - https://github.com/alloy/terminal-notifier
29
-
30
- === Linux
31
-
32
- If you're a linux guy, you can choose one of these methods:
33
-
34
- * Install libnotify-bin and its dependencies: <tt>sudo aptitude install libnotify-bin</tt>
35
- * Install xosd-bin: <tt>sudo aptitude install xosd-bin</tt>
36
- * KDE users don't need to install anything: Test Notifier will use +knotify+ or +kdialog+.
37
-
38
- === Windows
39
-
40
- * Install Snarl: download from http://www.fullphat.net
41
- * Install ruby-snarl: <tt>gem install ruby-snarl</tt>
42
-
43
- == Usage
44
-
45
- Notifier will try to detect which notifiers are available in your system. So you can just send a message:
46
-
47
- Notifier.notify(
48
- :image => "image.png",
49
- :title => "Testing Notifier",
50
- :message => "Sending an important message!"
51
- )
52
-
53
- Not all notifiers support the image option, therefore it will be ignored.
54
-
55
- If your system support more than one notifier, you can specify which one you prefer:
56
-
57
- Notifier.default_notifier = :notify_send
58
-
59
- The available names are <tt>growl</tt>, <tt>terminal_notifier</tt>, <tt>kdialog</tt>, <tt>knotify</tt>, <tt>notify_send</tt>, <tt>osd_cat</tt>, and <tt>snarl</tt>.
60
-
61
- There are several helper methods that you can use in order to retrieve notifiers.
62
-
63
- * <tt>Notifier.notifier</tt>: return the first supported notifier
64
- * <tt>Notifier.notifiers</tt>: return all notifiers
65
- * <tt>Notifier.supported_notifiers</tt>: return only supported notifiers
66
- * <tt>Notifier.from_name(name)</tt>: find notifier by its name
67
- * <tt>Notifier.supported_notifier_from_name(name)</tt>: find a supported notifier by its name
68
-
69
- == Creating custom notifiers
70
-
71
- To create a new notifier, just create a module on <tt>Notifier</tt> namespace that implements the following interface:
72
-
73
- module Notifier
74
- module MyCustomNotifier
75
- def self.supported?
76
- end
77
-
78
- def self.notify(options)
79
- end
80
- end
81
- end
82
-
83
- == Maintainer
84
-
85
- * Nando Vieira - http://nandovieira.com.br
86
-
87
- == Contributors
88
-
89
- * Olek Janiszewski
90
- * David Miani
91
-
92
- == License
93
-
94
- (The MIT License)
95
-
96
- Permission is hereby granted, free of charge, to any person obtaining
97
- a copy of this software and associated documentation files (the
98
- 'Software'), to deal in the Software without restriction, including
99
- without limitation the rights to use, copy, modify, merge, publish,
100
- distribute, sublicense, and/or sell copies of the Software, and to
101
- permit persons to whom the Software is furnished to do so, subject to
102
- the following conditions:
103
-
104
- The above copyright notice and this permission notice shall be
105
- included in all copies or substantial portions of the Software.
106
-
107
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
108
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
109
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
110
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
111
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
112
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
113
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,87 +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
- 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
- write "GNTP/1.0 REGISTER NONE",
79
- "Application-Name: #{application_name}",
80
- "Notifications-count: 1",
81
- nil,
82
- "Notification-Name: #{name}",
83
- "Notification-Enabled: True"
84
- end
85
- end
86
- end
87
- end
@@ -1,5 +0,0 @@
1
- module Notifier
2
- module Adapters
3
- autoload :GNTP, "notifier/adapters/gntp"
4
- end
5
- end
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
@@ -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, '').to_s,
18
- "--priority", "2",
19
- "--message", options[:message].to_s,
20
- options[:title].to_s
21
- ]
22
-
23
- Thread.new { system(*command) }.join
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
@@ -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
- allow(Notifier::Snarl).to receive_messages :supported? => true
11
- allow(Notifier::Knotify).to receive_messages :supported? => true
12
-
13
- expect(Notifier.supported_notifiers.size).to eql(3)
14
- end
15
-
16
- it "returns first available notifier" do
17
- allow(Notifier::Snarl).to receive_messages :supported? => true
18
- allow(Notifier::Knotify).to receive_messages :supported? => true
19
-
20
- expect(Notifier.notifier).to eql(Notifier::Snarl)
21
- end
22
-
23
- it "prefers default notifier" do
24
- allow(Notifier::Snarl).to receive_messages :supported? => true
25
- allow(Notifier::Knotify).to receive_messages :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
- allow(Notifier::Snarl).to receive_messages :supported? => true
40
- expect(Notifier::Snarl).to 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(9)
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
- allow(Notifier::Snarl).to receive_messages :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
- allow(notifier).to receive_messages(:supported? => false) unless notifier == Notifier::Placebo
7
- end
8
- end
9
- end
10
-
11
- RSpec.configure do |config|
12
- config.include SpecHelpers
13
- end