wcc-xmpp-notificator 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ wcc-xmpp-notificator
2
+ ====================
3
+
4
+ This adds XMPP/Jabber support to [wcc](https://github.com/cmur2/wcc) encapsuled
5
+ in a separate gem.
6
+
7
+ Note: This notificator does not need to have an (and even not supports establishing some)
8
+ authorization/subscription to talk to the recipients jabber accounts.
9
+
10
+ What you need to add to your conf.yml:
11
+
12
+ conf:
13
+ [...]
14
+ # jid is the address wcc will talk from
15
+ xmpp:
16
+ jid: wcc@example.com/wcc
17
+ password: s3cr3t
18
+
19
+ recipients:
20
+ [...]
21
+ - me:
22
+ [...]
23
+ # address to be notified via Jabber
24
+ - xmpp: me@mydomain.com
@@ -1,9 +1,6 @@
1
1
  <% if data.diff.nil? %>
2
2
  Checked <%= data.site.uri.to_s %> the first time so no diff was possible.
3
3
  <% else %>
4
- Change at <%= data.site.uri.to_s %> - diff follows:
5
-
4
+ <%= data.site.uri.to_s %> changed:
6
5
  <%= 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
6
  <% end %>
@@ -3,8 +3,7 @@ require 'xmpp4r/client'
3
3
 
4
4
  class XMPPNotificator
5
5
  @@client = nil
6
- @@subject_tpl = nil
7
- @@body_tpl = nil
6
+ @@tpl = {}
8
7
 
9
8
  def initialize(opts)
10
9
  @jid = Jabber::JID.new(opts)
@@ -12,11 +11,9 @@ class XMPPNotificator
12
11
 
13
12
  def notify!(data)
14
13
  # prepare message
15
- subject = self.class.get_subject_tpl.result(binding)
16
- body = self.class.get_body_tpl.result(binding)
14
+ body = self.class.get_tpl(:body, 'xmpp-body.plain.erb').result(binding)
17
15
  m = Jabber::Message.new(@jid, body)
18
16
  m.type = :normal
19
- m.subject = subject
20
17
  # send it
21
18
  c = self.class.get_client
22
19
  c.send(m) unless c.nil?
@@ -63,38 +60,21 @@ class XMPPNotificator
63
60
  @@client
64
61
  end
65
62
 
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"
63
+ def self.get_tpl(id, name)
64
+ if @@tpl[id].nil?
65
+ @@tpl[id] = WCC::Prog.load_template(name)
66
+ if @@tpl[id].nil?
67
+ src_path = Pathname.new(__FILE__) + "../../assets/template.d/#{name}"
71
68
  t = File.open(src_path, 'r') { |f| f.read }
72
- WCC::Prog.save_template('xmpp-subject.plain.erb', t)
69
+ WCC::Prog.save_template(name, t)
73
70
  # retry load
74
- @@subject_tpl = WCC::Prog.load_template('xmpp-subject.plain.erb')
71
+ @@tpl[id] = WCC::Prog.load_template(name)
75
72
  end
76
- if @@subject_tpl.nil?
77
- @@subject_tpl = ERB.new("ERROR LOADING TEMPLATE 'xmpp-subject.plain.erb'!", 0, "<>")
73
+ if @@tpl[id].nil?
74
+ @@tpl[id] = ERB.new("ERROR LOADING TEMPLATE '#{name}'!", 0, "<>")
78
75
  end
79
76
  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
77
+ @@tpl[id]
98
78
  end
99
79
  end
100
80
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wcc-xmpp-notificator
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christian Nicolai
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-08 00:00:00 Z
18
+ date: 2011-11-13 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: xmpp4r
@@ -23,12 +23,13 @@ dependencies:
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - ">="
26
+ - - ~>
27
27
  - !ruby/object:Gem::Version
28
- hash: 3
28
+ hash: 1
29
29
  segments:
30
30
  - 0
31
- version: "0"
31
+ - 5
32
+ version: "0.5"
32
33
  type: :runtime
33
34
  version_requirements: *id001
34
35
  description:
@@ -40,9 +41,9 @@ extensions: []
40
41
  extra_rdoc_files: []
41
42
 
42
43
  files:
43
- - assets/template.d/xmpp-subject.plain.erb
44
44
  - assets/template.d/xmpp-body.plain.erb
45
45
  - lib/wcc-xmpp-notificator.rb
46
+ - README.md
46
47
  homepage: https://github.com/cmur2/wcc-xmpp-notificator
47
48
  licenses: []
48
49
 
@@ -1 +0,0 @@
1
- BLAH [<%= data.tag %>] <%= data.site.uri.host %> changed