notifier 0.5.1 → 0.5.2

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
2
  SHA1:
3
- metadata.gz: ded78a65a591a7d25fc841c511ed827622fc1463
4
- data.tar.gz: db832909bd190d77d8dcdd2248a60a4098e616db
3
+ metadata.gz: ae5afe2f3c9c49b9f8e29be682424de92908dd35
4
+ data.tar.gz: 7b5c443d285fd023fb001b48ebe43ac695944d7c
5
5
  SHA512:
6
- metadata.gz: 2e26970c850341800b43a6d61865f82b95db278ed0666e8a550848d51b479cf837dbceaeb950224f0c1cceda8830f5f4ba0e69b027f2bf624a444adf08436d54
7
- data.tar.gz: 96e7619e015a14c3383ccedca1423ce638cbbc771ac5789d9f455901b1bbf34d63c5356c70d9a7ef43107fa46eaf80c19263812f3ac02d55af1289cd9dee1f80
6
+ metadata.gz: 56c4fbc80d2c33cb22990600f977d031335c6e4cc4df42ce3f8bd9d0da452d183df75127dcd405ea36121d23bd6aab1cd8f5200e5b7de8bafde03a768563d2af
7
+ data.tar.gz: a9a64939c8a7db0f0040baec682e6d078621b2a8328036d016469cb8e534a9d1faba0a56a64c1586c2c2eb378493e8fed57178de964bba7965539bc8e7d97ccf
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ cache: bundler
3
+ sudo: false
4
+ notifications:
5
+ email: false
6
+ rvm:
7
+ - 2.3.0
8
+ - '2.2'
9
+ - '2.1'
10
+ env:
11
+ global:
12
+ secure: mYd3r1SEZJcirOFNjNe75vMNjYJ/UHDLZAsEeCQQcI4Na03au53Pr02waJKPdXXV8JnakaYMDNBc4kOXnk3v0ytgINnvNXnObjPT2KUPvQKLUhXq2Q/BrWS4CFihihznZHAQFgeTVbDm/brLWH61+JwDlQ2kEo6OGSAZ8ZV/PV8=
@@ -1,4 +1,10 @@
1
- = Notifier
1
+ # Notifier
2
+
3
+ [![Travis-CI](https://travis-ci.org/fnando/notifier.png)](https://travis-ci.org/fnando/notifier)
4
+ [![Code Climate](https://codeclimate.com/github/fnando/notifier/badges/gpa.svg)](https://codeclimate.com/github/fnando/notifier)
5
+ [![Test Coverage](https://codeclimate.com/github/fnando/notifier/badges/coverage.svg)](https://codeclimate.com/github/fnando/notifier/coverage)
6
+ [![Gem](https://img.shields.io/gem/v/notifier.svg)](https://rubygems.org/gems/notifier)
7
+ [![Gem](https://img.shields.io/gem/dt/notifier.svg)](https://rubygems.org/gems/notifier)
2
8
 
3
9
  Send system notifications on several platforms with a simple and unified API. Currently supports:
4
10
 
@@ -11,85 +17,97 @@ Send system notifications on several platforms with a simple and unified API. Cu
11
17
  * Libnotify (Linux)
12
18
  * Snarl (Windows)
13
19
 
14
- == Installation
20
+ ## Installation
15
21
 
16
- gem install notifier
22
+ gem install notifier
17
23
 
18
- === Mac OS X
24
+ ### Mac OS X
19
25
 
20
- Growl:
26
+ #### Growl
21
27
 
22
28
  * Install Growl - http://growl.info/
23
29
  * Install the growlnotify script located on the "Extras" directory
24
30
  * Open the Growl Preference Panel (System > Growl) and activate "Listen for incoming notifications" and "Allow remote application registration" options on the Network tab.
25
31
 
26
- terminal-notifier:
32
+ #### terminal-notifier
27
33
 
28
34
  * Install terminal-notifier - https://github.com/alloy/terminal-notifier
29
35
 
30
- === Linux
36
+ terminal-notifier also supports two additional flags:
37
+
38
+ * `subtitle`
39
+ * `sound`
40
+
41
+ See terminal-notifier's help for additional information.
42
+
43
+ ### Linux
31
44
 
32
45
  If you're a linux guy, you can choose one of these methods:
33
46
 
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>
47
+ * Install libnotify-bin and its dependencies: `sudo aptitude install libnotify-bin`
48
+ * Install xosd-bin: `sudo aptitude install xosd-bin`
36
49
  * KDE users don't need to install anything: Test Notifier will use +knotify+ or +kdialog+.
37
50
 
38
- === Windows
51
+ ### Windows
39
52
 
40
53
  * Install Snarl: download from http://www.fullphat.net
41
- * Install ruby-snarl: <tt>gem install ruby-snarl</tt>
54
+ * Install ruby-snarl: `gem install ruby-snarl`
42
55
 
43
- == Usage
56
+ ## Usage
44
57
 
45
58
  Notifier will try to detect which notifiers are available in your system. So you can just send a message:
46
59
 
47
- Notifier.notify(
48
- :image => "image.png",
49
- :title => "Testing Notifier",
50
- :message => "Sending an important message!"
51
- )
60
+ ```ruby
61
+ Notifier.notify(
62
+ image: "image.png",
63
+ title: "Testing Notifier",
64
+ message: "Sending an important message!"
65
+ )
66
+ ```
52
67
 
53
68
  Not all notifiers support the image option, therefore it will be ignored.
54
69
 
55
70
  If your system support more than one notifier, you can specify which one you prefer:
56
71
 
57
- Notifier.default_notifier = :notify_send
72
+ ```ruby
73
+ Notifier.default_notifier = :notify_send
74
+ ```
58
75
 
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>.
76
+ The available names are `growl`, `terminal_notifier`, `kdialog`, `knotify`, `notify_send`, `osd_cat`, and `snarl`.
60
77
 
61
78
  There are several helper methods that you can use in order to retrieve notifiers.
62
79
 
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
80
+ * `Notifier.notifier`: return the first supported notifier
81
+ * `Notifier.notifiers`: return all notifiers
82
+ * `Notifier.supported_notifiers`: return only supported notifiers
83
+ * `Notifier.from_name(name)`: find notifier by its name
84
+ * `Notifier.supported_notifier_from_name(name)`: find a supported notifier by its name
68
85
 
69
- == Creating custom notifiers
86
+ ## Creating custom notifiers
70
87
 
71
- To create a new notifier, just create a module on <tt>Notifier</tt> namespace that implements the following interface:
88
+ To create a new notifier, just create a module on `Notifier` namespace that implements the following interface:
72
89
 
73
- module Notifier
74
- module MyCustomNotifier
75
- def self.supported?
76
- end
90
+ ```ruby
91
+ module Notifier
92
+ module MyCustomNotifier
93
+ def self.supported?
94
+ end
77
95
 
78
- def self.notify(options)
79
- end
96
+ def self.notify(options)
80
97
  end
81
98
  end
99
+ end
100
+ ```
82
101
 
83
- == Maintainer
102
+ ## Maintainer
84
103
 
85
- * Nando Vieira - http://nandovieira.com.br
104
+ * Nando Vieira - http://nandovieira.com
86
105
 
87
- == Contributors
106
+ ## Contributors
88
107
 
89
- * Olek Janiszewski
90
- * David Miani
108
+ https://github.com/fnando/notifier/graphs/contributors
91
109
 
92
- == License
110
+ ## License
93
111
 
94
112
  (The MIT License)
95
113
 
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require "bundler"
2
- Bundler::GemHelper.install_tasks
3
-
1
+ require "bundler/gem_tasks"
4
2
  require "rake/testtask"
5
- Rake::TestTask.new do |t|
6
- t.libs += %w[test lib]
7
- t.ruby_opts = %w[-rubygems]
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
8
6
  t.test_files = FileList["test/**/*_test.rb"]
9
- t.verbose = true
7
+ t.warning = false
10
8
  end
9
+
10
+ task default: :test
@@ -32,13 +32,13 @@ module Notifier
32
32
  end
33
33
 
34
34
  def notifiers
35
- constants.collect do |name|
35
+ constants.map do |name|
36
36
  const_get(name) unless %w[Placebo Adapters Version].include?(name.to_s)
37
37
  end.compact + [Placebo]
38
38
  end
39
39
 
40
40
  def supported_notifiers
41
- notifiers.select {|notifier| notifier.supported?}
41
+ notifiers.select {|notifier| notifier.supported? }
42
42
  end
43
43
 
44
44
  def from_name(name)
@@ -57,7 +57,9 @@ module Notifier
57
57
  end
58
58
 
59
59
  private
60
+
60
61
  def classify(string)
61
- string.gsub(/_(.)/sm) { "#{$1.upcase}" }.gsub(/^(.)/) { "#{$1.upcase}" }
62
+ string.gsub(/_(.)/sm) { "#{$1.upcase}" }
63
+ .gsub(/^(.)/) { "#{$1.upcase}" }
62
64
  end
63
65
  end
@@ -1,5 +1,5 @@
1
1
  module Notifier
2
2
  module Adapters
3
- autoload :GNTP, "notifier/adapters/gntp"
3
+ require "notifier/adapters/gntp"
4
4
  end
5
5
  end
@@ -8,7 +8,7 @@ module Notifier
8
8
 
9
9
  def initialize(options = {})
10
10
  if options.kind_of?(String)
11
- options = {:name => options}
11
+ options = {name: options}
12
12
  end
13
13
 
14
14
  @application_name = options.fetch(:name, "GNTP/Ruby")
@@ -64,9 +64,9 @@ module Notifier
64
64
  contents = File.open(path, "rb") {|f| f.read }
65
65
 
66
66
  {
67
- :identifier => Digest::MD5.hexdigest(contents),
68
- :contents => contents,
69
- :size => contents.bytesize
67
+ identifier: Digest::MD5.hexdigest(contents),
68
+ contents: contents,
69
+ size: contents.bytesize
70
70
  }
71
71
  end
72
72
 
@@ -21,16 +21,16 @@ module Notifier
21
21
 
22
22
  def notify(options)
23
23
  gntp = Adapters::GNTP.new({
24
- :name => "test_notifier",
25
- :host => host,
26
- :port => port
24
+ name: "test_notifier",
25
+ host: host,
26
+ port: port
27
27
  })
28
28
 
29
29
  gntp.notify({
30
- :name => "status",
31
- :title => options[:title],
32
- :message => options[:message],
33
- :icon => options[:image]
30
+ name: "status",
31
+ title: options[:title],
32
+ message: options[:message],
33
+ icon: options[:image]
34
34
  })
35
35
  end
36
36
  end
@@ -14,7 +14,7 @@ module Notifier
14
14
  command = [
15
15
  "growlnotify",
16
16
  "--name", "test_notifier",
17
- "--image", options.fetch(:image, '').to_s,
17
+ "--image", options.fetch(:image, "").to_s,
18
18
  "--priority", "2",
19
19
  "--message", options[:message].to_s,
20
20
  options[:title].to_s
@@ -12,9 +12,14 @@ module Notifier
12
12
  "-group", "notifier-rubygems",
13
13
  "-title", options[:title].to_s,
14
14
  "-appIcon", options.fetch(:image, "").to_s,
15
- "-message", options[:message].to_s
15
+ "-message", options[:message].to_s,
16
+ "-subtitle", options.fetch(:subtitle, "").to_s
16
17
  ]
17
18
 
19
+ # -sound with an empty string (e.g., "") will trigger the
20
+ # default sound so we need to check for it.
21
+ command.concat(["-sound", options.fetch(:sound, "default").to_s] ) if options[:sound]
22
+
18
23
  Thread.new { system(*command) }.join
19
24
  end
20
25
  end
@@ -2,7 +2,7 @@ module Notifier
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 5
5
- PATCH = 1
5
+ PATCH = 2
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -1,6 +1,4 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "notifier/version"
1
+ require "./lib/notifier/version"
4
2
 
5
3
  Gem::Specification.new do |s|
6
4
  s.name = "notifier"
@@ -19,6 +17,8 @@ Gem::Specification.new do |s|
19
17
 
20
18
  s.requirements << "Growl, terminal-notifier, Libnotify, OSD, KDE (Knotify and Kdialog) or Snarl"
21
19
 
22
- s.add_development_dependency "rspec"
20
+ s.add_development_dependency "minitest-utils"
23
21
  s.add_development_dependency "rake"
22
+ s.add_development_dependency "mocha"
23
+ s.add_development_dependency "codeclimate-test-reporter"
24
24
  end
@@ -0,0 +1,75 @@
1
+ require "test_helper"
2
+
3
+ class NotifierTest < Minitest::Test
4
+ setup do
5
+ Notifier.notifiers.each do |notifier|
6
+ notifier.stubs(:supported?).returns(false) unless notifier == Notifier::Placebo
7
+ end
8
+
9
+ Notifier.default_notifier = nil
10
+ end
11
+
12
+ test "retrieves list of supported notifiers" do
13
+ Notifier::Snarl.stubs(:supported?).returns(true)
14
+ Notifier::Knotify.stubs(:supported?).returns(true)
15
+
16
+ assert_equal 3, Notifier.supported_notifiers.size
17
+ end
18
+
19
+ test "returns first available notifier" do
20
+ Notifier::Snarl.stubs(:supported?).returns(true)
21
+ Notifier::Knotify.stubs(:supported?).returns(true)
22
+
23
+ assert_equal Notifier::Snarl, Notifier.notifier
24
+ end
25
+
26
+ test "prefers default notifier" do
27
+ Notifier::Snarl.stubs(:supported?).returns(true)
28
+ Notifier::Knotify.stubs(:supported?).returns(true)
29
+
30
+ Notifier.default_notifier = :knotify
31
+
32
+ assert_equal Notifier::Knotify, Notifier.notifier
33
+ end
34
+
35
+ test "sends notification" do
36
+ params = {
37
+ title: "Some title",
38
+ message: "Some message",
39
+ image: "image.png"
40
+ }
41
+
42
+ Notifier::Snarl.stubs(:supported?).returns(true)
43
+ Notifier::Snarl.expects(:notify).with(params)
44
+
45
+ Notifier.notify(params)
46
+ end
47
+
48
+ test "retrieves list of all notifiers" do
49
+ assert_equal 9, Notifier.notifiers.size
50
+ end
51
+
52
+ test "considers Placebo as fallback notifier" do
53
+ assert_equal Notifier::Placebo, Notifier.supported_notifiers.last
54
+ end
55
+
56
+ test "returns notifier by its name" do
57
+ assert_equal Notifier::OsdCat, Notifier.from_name(:osd_cat)
58
+ assert_equal Notifier::NotifySend, Notifier.from_name(:notify_send)
59
+ assert_equal Notifier::Growl, Notifier.from_name(:growl)
60
+ end
61
+
62
+ test "returns notifier by its name when supported" do
63
+ Notifier::Snarl.expects(:supported?).returns(true)
64
+ assert_equal Notifier::Snarl, Notifier.supported_notifier_from_name(:snarl)
65
+ end
66
+
67
+ test "returns nil when have no supported notifiers" do
68
+ assert_nil Notifier.supported_notifier_from_name(:snarl)
69
+ end
70
+
71
+ test "returns nil when an invalid notifier name is provided" do
72
+ assert_nil Notifier.from_name(:invalid)
73
+ assert_nil Notifier.supported_notifier_from_name(:invalid)
74
+ end
75
+ end
@@ -0,0 +1,9 @@
1
+ require "test_helper"
2
+
3
+ class SnarlTest < Minitest::Test
4
+ test "sends notification" do
5
+ Snarl.expects(:show_message).with("TITLE", "MESSAGE", "IMAGE")
6
+
7
+ Notifier::Snarl.notify(title: "TITLE", message: "MESSAGE", image: "IMAGE")
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
4
+ require "bundler/setup"
5
+ require "notifier"
6
+ require "minitest/utils"
7
+ require "minitest/autorun"
8
+
9
+ module Snarl
10
+ def self.show_message(*)
11
+ end
12
+ end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-20 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: minitest-utils
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mocha
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: codeclimate-test-reporter
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'
41
69
  description: Send system notifications on several platforms with a simple and unified
42
70
  API. Currently supports Growl, Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl
43
71
  email:
@@ -47,9 +75,9 @@ extensions: []
47
75
  extra_rdoc_files: []
48
76
  files:
49
77
  - ".gitignore"
50
- - ".rspec"
78
+ - ".travis.yml"
51
79
  - Gemfile
52
- - README.rdoc
80
+ - README.md
53
81
  - Rakefile
54
82
  - lib/notifier.rb
55
83
  - lib/notifier/adapters.rb
@@ -66,8 +94,9 @@ files:
66
94
  - lib/notifier/version.rb
67
95
  - notifier.gemspec
68
96
  - resources/register-growl.scpt
69
- - spec/notifier_spec.rb
70
- - spec/spec_helper.rb
97
+ - test/notifier/notifier_test.rb
98
+ - test/notifier/snarl_test.rb
99
+ - test/test_helper.rb
71
100
  homepage: http://rubygems.org/gems/notifier
72
101
  licenses: []
73
102
  metadata: {}
@@ -88,11 +117,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
117
  requirements:
89
118
  - Growl, terminal-notifier, Libnotify, OSD, KDE (Knotify and Kdialog) or Snarl
90
119
  rubyforge_project:
91
- rubygems_version: 2.4.6
120
+ rubygems_version: 2.5.1
92
121
  signing_key:
93
122
  specification_version: 4
94
123
  summary: Send system notifications on several platforms with a simple and unified
95
124
  API. Currently supports Growl, Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl
96
125
  test_files:
97
- - spec/notifier_spec.rb
98
- - spec/spec_helper.rb
126
+ - test/notifier/notifier_test.rb
127
+ - test/notifier/snarl_test.rb
128
+ - test/test_helper.rb
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
@@ -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
@@ -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