ruby-notify-send 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 15905833105615e17847972a14f052c40070ba3c
4
+ data.tar.gz: 7a7bd9692f365101326dd8619bf584ef753bd8e9
5
+ SHA512:
6
+ metadata.gz: f58597dfd5d83aa06e4d8692c03c9debb4ebcf116c062e499bfe14b8da3ab31f7d9efac9130dadd55eceeca48c8730107a5a753fe62b4bf1a57d7f9a8ca71e75
7
+ data.tar.gz: 1437eb9f6dded4942f1983145ffd3e986b425aa6aa351ae14cdd9ad281dd54c93e777aca03ce334ae3bf722092b5c9ffdf2c42e5824b26e5d6bd6b78a7f43826
@@ -0,0 +1,41 @@
1
+ NotifySend for Ruby
2
+ -------
3
+
4
+ This gem allows you to generate desktop notifications from your Ruby script.
5
+
6
+ It replicates the functionality of `notify-send`, but actually bypasses it completely and goes direct to `dbus`.
7
+
8
+ Installation
9
+ -------
10
+
11
+ `gem install ruby-notify-send`
12
+
13
+ Usage
14
+ -------
15
+
16
+ ```
17
+ require 'notify-send'
18
+
19
+ # With positional parameters:
20
+ NotifySend.send "Long running process just completed"
21
+ NotifySend.send "Title", "some extra text"
22
+ NotifySend.send "Title", "some extra text", "error" # <--- specifiying an icon
23
+
24
+ # With a hash:
25
+ NotifySend.send({summary: "Hi", timeout: 2000})
26
+ NotifySend.send({summary: "Hi", body: "Hello, World!", icon: "info"})
27
+ ```
28
+
29
+ Icons
30
+ -------
31
+
32
+ The `:icon` parameter can be one of:
33
+ * 'error', 'info'
34
+ * Any of the files in `/usr/share/notify-osd/icons/gnome/scalable/status`, minus the file extension (if you're on Ubuntu)
35
+ * An absolute path to an image file, e.g. `{icon: "/home/user_name/Desktop/some_image.jpg", summary: ...}`
36
+
37
+ Notes and known issues
38
+ -------
39
+
40
+ * `:timeout` seems to be ignored on my desktop
41
+ * If `:summary` is an empty string, the notification will not be displayed
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
@@ -0,0 +1,45 @@
1
+ require 'dbus'
2
+
3
+ class NotifySend
4
+
5
+ @@interface = nil
6
+ DEFAULTS = {
7
+ app_name: __FILE__,
8
+ id: 0,
9
+ icon: 'info',
10
+ summary: '',
11
+ body: '',
12
+ actions: [],
13
+ hints: {},
14
+ timeout: 2000
15
+ }
16
+
17
+ def self.send(first, *others)
18
+ if first.is_a?(Hash) and others.length == 0
19
+ _send first
20
+ elsif first.respond_to?(:to_s) and others.length < 4
21
+ _send [:body, :icon, :timeout].zip(others).each_with_object({summary: first}) { |(k, v), obj| obj[k] = v unless v.nil? }
22
+ else
23
+ raise ArgumentError.new("Invalid arguments")
24
+ end
25
+ # _send DEFAULTS.merge(first.is_a?(Hash) ? first : {summary: first, body: others[0]})
26
+ end
27
+
28
+ private
29
+
30
+ def self.interface
31
+ @@interface ||= get_interface
32
+ end
33
+
34
+ def self.get_interface
35
+ bus = DBus::SessionBus.instance
36
+ obj = bus.service("org.freedesktop.Notifications").object "/org/freedesktop/Notifications"
37
+ obj.introspect
38
+ obj["org.freedesktop.Notifications"]
39
+ end
40
+
41
+ def self._send(params)
42
+ interface.Notify *DEFAULTS.merge(params).values
43
+ end
44
+
45
+ end
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "ruby-notify-send"
3
+ s.version = "0.0.1"
4
+ s.date = "2016-05-19"
5
+ s.summary = "Send notify-send notifications from your Ruby application"
6
+ s.description = "This replicates the functionality of notify-send, by talking directy to dbus"
7
+ s.authors = "cyclotron3k"
8
+ s.files = ["lib/notify-send.rb", "test/test_notify_send.rb", "Rakefile", "ruby-notify-send.gemspec", "README.md"]
9
+ s.test_files = ["test/test_notify_send.rb"]
10
+ s.homepage = "https://github.com/cyclotron3k/ruby-notify-send"
11
+ s.license = "MIT"
12
+ s.add_runtime_dependency "ruby-dbus"
13
+ s.required_ruby_version = ">= 1.9.0" # we rely on guaranteed hash key ordering
14
+ end
@@ -0,0 +1,13 @@
1
+ require 'minitest/autorun'
2
+ require 'notify-send'
3
+
4
+ class HolaTest < Minitest::Test
5
+ def test_argument
6
+ assert_raises ArgumentError do
7
+ NotifySend.send "test", "test", "test", "test", "test"
8
+ end
9
+ assert_raises ArgumentError do
10
+ NotifySend.send
11
+ end
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-notify-send
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - cyclotron3k
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-dbus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: This replicates the functionality of notify-send, by talking directy
28
+ to dbus
29
+ email:
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/notify-send.rb
35
+ - test/test_notify_send.rb
36
+ - Rakefile
37
+ - ruby-notify-send.gemspec
38
+ - README.md
39
+ homepage: https://github.com/cyclotron3k/ruby-notify-send
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - '>='
50
+ - !ruby/object:Gem::Version
51
+ version: 1.9.0
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.0.3
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Send notify-send notifications from your Ruby application
63
+ test_files:
64
+ - test/test_notify_send.rb