notifiers 1.0

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.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/.infinity_test ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ infinity_test do
3
+ use :rubies => %w(1.9.2 ree 1.8.7 jruby), :test_framework => :rspec
4
+ end
data/README.markdown ADDED
@@ -0,0 +1,26 @@
1
+ # Notifier
2
+
3
+ Use notifications in a simple and elegant way. :)
4
+
5
+ ## Install
6
+
7
+ gem install notifiers
8
+
9
+ # Usage
10
+
11
+ require 'notifiers'
12
+ include Notifiers
13
+
14
+ ## Growl
15
+
16
+ growl.message('Hi Growl!').image('my_image.png').priority(2).name('my_app').notify!
17
+
18
+ ## Lib_Notify
19
+
20
+ notify_send.image('my_image.png').message('Hi Growl').notify!
21
+
22
+ # Why I created this gem?
23
+
24
+ ## Only one explanation:
25
+
26
+ ### <b>Because is fun! =)</b>
data/Tasks ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ class Tasks < Morpheus::Base
3
+ rspec
4
+ end
@@ -0,0 +1,54 @@
1
+ class Growl
2
+ COMMAND = "growlnotify"
3
+
4
+ def image(icon)
5
+ @image = icon
6
+ self
7
+ end
8
+
9
+ def title(text)
10
+ @title = text
11
+ self
12
+ end
13
+
14
+ def message(text)
15
+ @message = text
16
+ self
17
+ end
18
+
19
+ def priority(number)
20
+ @priority = number
21
+ self
22
+ end
23
+
24
+ def host(hostname)
25
+ @host = hostname
26
+ self
27
+ end
28
+
29
+ def password(secret)
30
+ @password = secret
31
+ self
32
+ end
33
+
34
+ def auth(authentication)
35
+ @auth = authentication
36
+ self
37
+ end
38
+
39
+ def to_s
40
+ command = COMMAND.clone
41
+ command << " --title '#{@title}'" if @title
42
+ command << " --message '#{@message}'"
43
+ [:image, :priority, :host, :password, :auth].each do |option|
44
+ variable = instance_variable_get("@#{option}")
45
+ command << " --#{option} #{variable}" if variable
46
+ end
47
+ command
48
+ end
49
+
50
+ def notify!
51
+ system(to_s)
52
+ end
53
+
54
+ end
@@ -0,0 +1,7 @@
1
+ class Knotify
2
+
3
+ def new
4
+ raise 'Dont support Knotify (YET)'
5
+ end
6
+
7
+ end
@@ -0,0 +1,53 @@
1
+ class NotifySend
2
+ COMMAND = 'notify-send'
3
+
4
+ def message(text)
5
+ @message = text
6
+ self
7
+ end
8
+
9
+ def title(text)
10
+ @title = text
11
+ self
12
+ end
13
+
14
+ def image(icon)
15
+ @icon = icon
16
+ self
17
+ end
18
+
19
+ def urgency(level)
20
+ @urgency = level.to_s
21
+ self
22
+ end
23
+
24
+ def expire_time(time)
25
+ @expire_time = time
26
+ self
27
+ end
28
+
29
+ def hint(values)
30
+ @hint = values.collect.each { |element| element.to_s}.join(':')
31
+ self
32
+ end
33
+
34
+ def to_s
35
+ command = COMMAND.clone
36
+ [:hint, :priority, :icon, :urgency].each do |option|
37
+ variable = instance_variable_get("@#{option}")
38
+ command << " --#{option}=#{variable}" if variable
39
+ end
40
+ command << " --expire-time=#{@expire_time}" if @expire_time
41
+ [:title, :message].each do |option|
42
+ variable = instance_variable_get("@#{option}")
43
+ command << " '#{variable}'" if variable
44
+ end
45
+ command
46
+ end
47
+
48
+ # Extract this to a module or something
49
+ def notify!
50
+ system(to_s)
51
+ end
52
+
53
+ end
data/lib/notifiers.rb ADDED
@@ -0,0 +1,19 @@
1
+ [ :growl, :knotify, :notify_send].each do |notifier|
2
+ require "notifiers/#{notifier}"
3
+ end
4
+
5
+ module Notifiers
6
+
7
+ def growl
8
+ Growl.new
9
+ end
10
+
11
+ def knotify
12
+ Knotify.new
13
+ end
14
+
15
+ def notify_send
16
+ NotifySend.new
17
+ end
18
+
19
+ end
data/notifiers.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "notifiers"
5
+ s.version = '1.0'
6
+ s.platform = Gem::Platform::RUBY
7
+ s.authors = ["Tomás D'Stefano"]
8
+ s.email = ["tomasdestefi@gmail.com"]
9
+ s.homepage = "http://rubygems.org/gems/notifiers"
10
+ s.summary = "Use notifications in a simple and elegant way."
11
+ s.description = "Use Growl and Lib-Notify in a simple and clean way."
12
+
13
+ s.required_rubygems_version = ">= 1.3.6"
14
+ s.rubyforge_project = "notifiers"
15
+
16
+ s.add_development_dependency('rspec', ">= 2.0.1")
17
+ s.add_development_dependency('bundler', ">= 1.0.0")
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
21
+ s.require_path = 'lib'
22
+ end
@@ -0,0 +1,113 @@
1
+ require 'spec_helper'
2
+
3
+ describe Growl do
4
+
5
+ before do
6
+ @growl = growl
7
+ end
8
+
9
+ describe '#image' do
10
+
11
+ it "should keep the image" do
12
+ @growl.image('my_image.png')
13
+ @growl.instance_variable_get(:@image).should eql 'my_image.png'
14
+ end
15
+
16
+ it "should set the image" do
17
+ @growl.image('wario.png')
18
+ @growl.instance_variable_get(:@image).should eql 'wario.png'
19
+ end
20
+
21
+ end
22
+
23
+ describe '#message' do
24
+
25
+ it "should set the message option" do
26
+ @growl.message('Hello World!')
27
+ @growl.instance_variable_get(:@message).should eql 'Hello World!'
28
+ end
29
+
30
+ it "should set the message" do
31
+ @growl.message('May the Force be with you')
32
+ @growl.instance_variable_get(:@message).should eql 'May the Force be with you'
33
+ end
34
+ end
35
+
36
+ describe '#title' do
37
+ it "should set the title" do
38
+ @growl.title('Nirvana')
39
+ @growl.instance_variable_get(:@title).should eql 'Nirvana'
40
+ end
41
+
42
+ it "should set the title option" do
43
+ @growl.title('Pearl Jam')
44
+ @growl.instance_variable_get(:@title).should eql 'Pearl Jam'
45
+ end
46
+ end
47
+
48
+ describe '#priority' do
49
+
50
+ it "should set the priority" do
51
+ @growl.priority(0)
52
+ @growl.instance_variable_get(:@priority).should be 0
53
+ end
54
+
55
+ it "should set the priority number" do
56
+ @growl.priority(1)
57
+ @growl.instance_variable_get(:@priority).should be 1
58
+ end
59
+ end
60
+
61
+ describe '#host' do
62
+
63
+ it "should set the hostname" do
64
+ @growl.host('localhost')
65
+ @growl.instance_variable_get(:@host).should eql 'localhost'
66
+ end
67
+
68
+ it "should set the host" do
69
+ @growl.host('beer_duff.com')
70
+ @growl.instance_variable_get(:@host).should eql 'beer_duff.com'
71
+ end
72
+ end
73
+
74
+ describe '#password' do
75
+
76
+ it "should set the password" do
77
+ @growl.password('top_secret')
78
+ @growl.instance_variable_get(:@password).should eql 'top_secret'
79
+ end
80
+
81
+ it "should set the secret password" do
82
+ @growl.password('paradise_city')
83
+ @growl.instance_variable_get(:@password).should eql 'paradise_city'
84
+ end
85
+ end
86
+
87
+ describe '#auth' do
88
+ it "should set the auth option" do
89
+ @growl.auth('SHA256')
90
+ @growl.instance_variable_get(:@auth).should eql 'SHA256'
91
+ end
92
+ end
93
+
94
+ describe '#to_s' do
95
+
96
+ it "should construct the command" do
97
+ command = @growl.message('Hello World!').priority(1).image('mario.png').to_s # What Mario?
98
+ command.should eql "growlnotify --message 'Hello World!' --image mario.png --priority 1"
99
+ end
100
+
101
+ it "should construct the command with host password and auth" do
102
+ command = @growl.message('Donuts').host('duff_bear').auth('SHA256').password('welcome_to_the_jungle').to_s
103
+ command.should eql "growlnotify --message 'Donuts' --host duff_bear --password welcome_to_the_jungle --auth SHA256"
104
+ end
105
+
106
+ it "should construct the command with title and message" do
107
+ command = @growl.message('Last Kiss').title('Pearl Jam').to_s
108
+ command.should eql "growlnotify --title 'Pearl Jam' --message 'Last Kiss'"
109
+ end
110
+
111
+ end
112
+
113
+ end
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+
3
+ describe NotifySend do
4
+
5
+ before do
6
+ @notify_send = notify_send
7
+ end
8
+
9
+ describe '#image' do
10
+
11
+ it "should set the image" do
12
+ @notify_send.image('my_image.png')
13
+ @notify_send.instance_variable_get(:@icon).should eql 'my_image.png'
14
+ end
15
+
16
+ it "should set the icon option" do
17
+ @notify_send.image('homer_simpson.png')
18
+ @notify_send.instance_variable_get(:@icon).should eql 'homer_simpson.png'
19
+ end
20
+
21
+ end
22
+
23
+ describe '#message' do
24
+
25
+ it "should set the message" do
26
+ @notify_send.message('Oh Donuts!')
27
+ @notify_send.instance_variable_get(:@message).should eql 'Oh Donuts!'
28
+ end
29
+
30
+ it "should set the message option" do
31
+ @notify_send.message('Duff Beer')
32
+ @notify_send.instance_variable_get(:@message).should eql 'Duff Beer'
33
+ end
34
+
35
+ end
36
+
37
+ describe '#title' do
38
+
39
+ it "should set the title" do
40
+ @notify_send.title('W00T!!')
41
+ @notify_send.instance_variable_get(:@title).should == 'W00T!!'
42
+ end
43
+
44
+ it "should set a title as intance variable" do
45
+ @notify_send.title('Joker Owned Batman!')
46
+ @notify_send.instance_variable_get(:@title).should == 'Joker Owned Batman!'
47
+ end
48
+
49
+ end
50
+
51
+ describe '#urgency' do
52
+
53
+ it "should set the urgency instance variable to low" do
54
+ @notify_send.urgency(:low)
55
+ @notify_send.instance_variable_get(:@urgency).should == 'low'
56
+ end
57
+
58
+ it "should set he urgency instance variable to normal" do
59
+ @notify_send.urgency(:normal)
60
+ @notify_send.instance_variable_get(:@urgency).should == 'normal'
61
+ end
62
+
63
+ it "should set the urgency to critical" do
64
+ @notify_send.urgency(:critical)
65
+ @notify_send.instance_variable_get(:@urgency).should == 'critical'
66
+ end
67
+
68
+ end
69
+
70
+ describe '#expire_time' do
71
+
72
+ it "should set the expire time" do
73
+ @notify_send.expire_time(1000)
74
+ @notify_send.instance_variable_get(:@expire_time).should == 1000
75
+ end
76
+
77
+ it "should set the expire time in miliseconds" do
78
+ @notify_send.expire_time(2000)
79
+ @notify_send.instance_variable_get(:@expire_time).should == 2000
80
+ end
81
+
82
+ end
83
+
84
+ describe '#hint' do
85
+
86
+ it "should set the hint" do
87
+ @notify_send.hint([:string, :me, :yeah])
88
+ @notify_send.instance_variable_get(:@hint).should == 'string:me:yeah'
89
+ end
90
+
91
+ it "should set the hint in int" do
92
+ @notify_send.hint([:int, :me, 1])
93
+ @notify_send.instance_variable_get(:@hint).should == 'int:me:1'
94
+ end
95
+
96
+ end
97
+
98
+ describe '#to_s' do
99
+
100
+ it "should transform in a command" do
101
+ command = @notify_send.title('Inception').message('3 levels').image('my_image.png').to_s
102
+ command.should == "notify-send --icon=my_image.png 'Inception' '3 levels'"
103
+ end
104
+
105
+ it "should transform in a command to execute" do
106
+ command = @notify_send.title('Joker').message('Haha ha!').expire_time(1000).hint([:string, :me, :woot]).to_s
107
+ command.should == "notify-send --hint=string:me:woot --expire-time=1000 'Joker' 'Haha ha!'"
108
+ end
109
+
110
+ it "should transform in a command to execute" do
111
+ command = @notify_send.title('Batman').urgency(:critical).to_s
112
+ command.should == "notify-send --urgency=critical 'Batman'"
113
+ end
114
+
115
+ end
116
+
117
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'notifiers' do
4
+
5
+ it { growl.should be_instance_of(Growl) }
6
+
7
+ it { knotify.should be_instance_of(Knotify) }
8
+
9
+ it { notify_send.should be_instance_of(NotifySend)}
10
+
11
+ end
@@ -0,0 +1,6 @@
1
+
2
+ require 'notifiers'
3
+
4
+ RSpec.configure do |config|
5
+ config.include Notifiers
6
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: notifiers
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ version: "1.0"
9
+ platform: ruby
10
+ authors:
11
+ - "Tom\xC3\xA1s D'Stefano"
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2010-10-28 00:00:00 -02:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: rspec
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 0
30
+ - 1
31
+ version: 2.0.1
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: bundler
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 1
44
+ - 0
45
+ - 0
46
+ version: 1.0.0
47
+ type: :development
48
+ version_requirements: *id002
49
+ description: Use Growl and Lib-Notify in a simple and clean way.
50
+ email:
51
+ - tomasdestefi@gmail.com
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files: []
57
+
58
+ files:
59
+ - .gitignore
60
+ - .infinity_test
61
+ - README.markdown
62
+ - Tasks
63
+ - lib/notifiers.rb
64
+ - lib/notifiers/growl.rb
65
+ - lib/notifiers/knotify.rb
66
+ - lib/notifiers/notify_send.rb
67
+ - notifiers.gemspec
68
+ - spec/notifiers/growl_spec.rb
69
+ - spec/notifiers/notify_send_spec.rb
70
+ - spec/notifiers_spec.rb
71
+ - spec/spec_helper.rb
72
+ has_rdoc: true
73
+ homepage: http://rubygems.org/gems/notifiers
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options: []
78
+
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ segments:
95
+ - 1
96
+ - 3
97
+ - 6
98
+ version: 1.3.6
99
+ requirements: []
100
+
101
+ rubyforge_project: notifiers
102
+ rubygems_version: 1.3.7
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Use notifications in a simple and elegant way.
106
+ test_files: []
107
+