wcc-xmpp-notificator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ <% if data.diff.nil? %>
2
+ Checked <%= data.site.uri.to_s %> the first time so no diff was possible.
3
+ <% else %>
4
+ Change at <%= data.site.uri.to_s %> - diff follows:
5
+
6
+ <%= data.diff.to_s %>
7
+
8
+ nHunks: <%= data.diff.nhunks %>, nIns: <%= data.diff.ninsertions %>, nDel: <%= data.diff.ndeletions %>, nLinesC: <%= data.diff.nlinesc %>, nCharsC: <%= data.diff.ncharsc %>
9
+ <% end %>
@@ -0,0 +1 @@
1
+ BLAH [<%= data.tag %>] <%= data.site.uri.host %> changed
@@ -0,0 +1,101 @@
1
+
2
+ require 'xmpp4r/client'
3
+
4
+ class XMPPNotificator
5
+ @@client = nil
6
+ @@subject_tpl = nil
7
+ @@body_tpl = nil
8
+
9
+ def initialize(opts)
10
+ @jid = Jabber::JID.new(opts)
11
+ end
12
+
13
+ def notify!(data)
14
+ # prepare message
15
+ subject = self.class.get_subject_tpl.result(binding)
16
+ body = self.class.get_body_tpl.result(binding)
17
+ m = Jabber::Message.new(@jid, body)
18
+ m.type = :normal
19
+ m.subject = subject
20
+ # send it
21
+ c = self.class.get_client
22
+ c.send(m) unless c.nil?
23
+ end
24
+
25
+ def self.parse_conf(conf)
26
+ if conf.is_a?(Hash)
27
+ if conf['jid'].nil?
28
+ WCC.logger.fatal "Missing jabber ID!"
29
+ return {:xmpp_jid => nil}
30
+ elsif conf['password'].nil?
31
+ WCC.logger.fatal "Missing jabber password!"
32
+ else
33
+ return {
34
+ :xmpp_jid => Jabber::JID.new(conf['jid']),
35
+ :xmpp_password => conf['password']
36
+ }
37
+ end
38
+ end
39
+ # no defaults
40
+ {}
41
+ end
42
+
43
+ def self.shut_down
44
+ if not @@client.nil?
45
+ @@client.send(Jabber::Presence.new.set_type(:unavailable))
46
+ @@client.close
47
+ end
48
+ end
49
+
50
+ def self.get_client
51
+ if @@client.nil? and not WCC::Conf[:xmpp_jid].nil?
52
+ @@client = Jabber::Client.new(WCC::Conf[:xmpp_jid])
53
+ @@client.connect
54
+ begin
55
+ @@client.auth(WCC::Conf[:xmpp_password])
56
+ @@client.send(Jabber::Presence.new.set_status('At your service every night.'))
57
+ rescue Jabber::ClientAuthenticationFailure => ex
58
+ WCC.logger.fatal "Wrong jabber password for #{WCC::Conf[:xmpp_jid]}!"
59
+ @@client.close
60
+ @@client = nil
61
+ end
62
+ end
63
+ @@client
64
+ end
65
+
66
+ def self.get_subject_tpl
67
+ if @@subject_tpl.nil?
68
+ @@subject_tpl = WCC::Prog.load_template('xmpp-subject.plain.erb')
69
+ if @@subject_tpl.nil?
70
+ src_path = Pathname.new(__FILE__) + "../../assets/template.d/xmpp-subject.plain.erb"
71
+ t = File.open(src_path, 'r') { |f| f.read }
72
+ WCC::Prog.save_template('xmpp-subject.plain.erb', t)
73
+ # retry load
74
+ @@subject_tpl = WCC::Prog.load_template('xmpp-subject.plain.erb')
75
+ end
76
+ if @@subject_tpl.nil?
77
+ @@subject_tpl = ERB.new("ERROR LOADING TEMPLATE 'xmpp-subject.plain.erb'!", 0, "<>")
78
+ end
79
+ end
80
+ @@subject_tpl
81
+ end
82
+
83
+ def self.get_body_tpl
84
+ if @@body_tpl.nil?
85
+ @@body_tpl = WCC::Prog.load_template('xmpp-body.plain.erb')
86
+ if @@body_tpl.nil?
87
+ src_path = Pathname.new(__FILE__) + "../../assets/template.d/xmpp-body.plain.erb"
88
+ t = File.open(src_path, 'r') { |f| f.read }
89
+ WCC::Prog.save_template('xmpp-body.plain.erb', t)
90
+ # retry load
91
+ @@body_tpl = WCC::Prog.load_template('xmpp-body.plain.erb')
92
+ end
93
+ if @@body_tpl.nil?
94
+ @@body_tpl = ERB.new("ERROR LOADING TEMPLATE 'xmpp-body.plain.erb'!", 0, "<>")
95
+ end
96
+ end
97
+ @@body_tpl
98
+ end
99
+ end
100
+
101
+ WCC::Notificators.map "xmpp", XMPPNotificator
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wcc-xmpp-notificator
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Christian Nicolai
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-08 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: xmpp4r
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description:
35
+ email: chrnicolai@gmail.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ files:
43
+ - assets/template.d/xmpp-subject.plain.erb
44
+ - assets/template.d/xmpp-body.plain.erb
45
+ - lib/wcc-xmpp-notificator.rb
46
+ homepage: https://github.com/cmur2/wcc-xmpp-notificator
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ requirements: []
73
+
74
+ rubyforge_project: wcc-xmpp-notificator
75
+ rubygems_version: 1.8.6
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: XMPP/Jabber notificator plugin for wcc
79
+ test_files: []
80
+