mlangenberg-merb_xmpp 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -0
- data/README.textile +37 -0
- data/lib/merb_xmpp.rb +1 -0
- data/lib/merb_xmpp/xmpp.rb +53 -0
- metadata +73 -0
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2008 Matthijs Langenberg
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
h1. Merb_XMPP
|
2
|
+
|
3
|
+
A plugin for the Merb framework that allows you to send XMPP/Jabber notifications from Merb applications.
|
4
|
+
If you quickly want to notify a user (if his cheeseburger is ready), this is the plugin you need!
|
5
|
+
It doesn't seperate composition and sending into micro MVC yet (like merb-mailer does), but that's on my TODO list (just like merging with merb-mailer).
|
6
|
+
|
7
|
+
h2. Installation
|
8
|
+
|
9
|
+
(sudo) gem install mlangenberg-merb_xmpp
|
10
|
+
|
11
|
+
h2. Configuration
|
12
|
+
|
13
|
+
Add a 'merb_xmpp' dependency in init.rb and add set the configuration like so.
|
14
|
+
<pre><code class="ruby">
|
15
|
+
Merb::Xmpp.config = {
|
16
|
+
:user => 'user@jabber.org',
|
17
|
+
:password => 'some-secrect-password',
|
18
|
+
:persistent => true, #this is optional if you don't want the jabber client to disconnect after delivery
|
19
|
+
:test_send => true #also optional, will add messages to Merb::Xmpp.deliveries array instead of sending.
|
20
|
+
}
|
21
|
+
</code></pre>
|
22
|
+
|
23
|
+
h2. Usage
|
24
|
+
|
25
|
+
Sending a jabber message to a user is really easy:
|
26
|
+
|
27
|
+
<pre><code class="ruby">
|
28
|
+
message = Merb::Xmpp.new(:to => 'another_user@jabber.org', :body => 'cheezburger ready!')
|
29
|
+
message.deliver
|
30
|
+
</code></pre>
|
31
|
+
|
32
|
+
You can also specify multiple receipients.
|
33
|
+
|
34
|
+
<pre><code class="ruby">
|
35
|
+
message = Merb::Xmpp.new(:to => ['user_one@jabber.org', 'user_two@jabber.org'], :body => 'cheezburger ready!')
|
36
|
+
message.deliver
|
37
|
+
</code></pre>
|
data/lib/merb_xmpp.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'merb_xmpp/xmpp'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
begin
|
2
|
+
require 'xmpp4r-simple'
|
3
|
+
rescue LoadError # TODO isn't this the job of the gem dependencies?
|
4
|
+
Merb.logger.warn "You need to install the xmpp4r-simple gem to use Merb::Xmpp"
|
5
|
+
end
|
6
|
+
|
7
|
+
module Merb
|
8
|
+
class Xmpp
|
9
|
+
class_inheritable_accessor :config, :deliveries
|
10
|
+
self.deliveries = []
|
11
|
+
|
12
|
+
# ==== Parameters
|
13
|
+
# message<Hash>:: Outgoing message
|
14
|
+
def initialize(message={})
|
15
|
+
@message = message
|
16
|
+
end
|
17
|
+
|
18
|
+
def deliver
|
19
|
+
config[:test_send] ? test_send : real_send
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_send
|
23
|
+
self.deliveries << @message
|
24
|
+
end
|
25
|
+
|
26
|
+
def real_send
|
27
|
+
@message[:to] = @message[:to].is_a?(Array) ? @message[:to] : [@message[:to]]
|
28
|
+
connection do |im|
|
29
|
+
@message[:to].each do |jid|
|
30
|
+
im.deliver(jid, @message[:body])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def connection
|
38
|
+
im = if config[:persistent]
|
39
|
+
@@jabber ||= connect
|
40
|
+
else
|
41
|
+
connect
|
42
|
+
end
|
43
|
+
yield im
|
44
|
+
im.disconnect unless config[:persistent]
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def connect
|
49
|
+
Jabber::Simple.new(config[:user], config[:password])
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mlangenberg-merb_xmpp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthijs Langengerg
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-13 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: merb-core
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.9.3
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: xmpp4r-simple
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 0.8.7
|
32
|
+
version:
|
33
|
+
description: A plugin for the Merb framework that allows you to send XMPP/Jabber notifications from Merb applications.
|
34
|
+
email: mlangenberg@gmail.com
|
35
|
+
executables: []
|
36
|
+
|
37
|
+
extensions: []
|
38
|
+
|
39
|
+
extra_rdoc_files: []
|
40
|
+
|
41
|
+
files:
|
42
|
+
- LICENSE
|
43
|
+
- README.textile
|
44
|
+
- lib/merb_xmpp.rb
|
45
|
+
- lib/merb_xmpp/xmpp.rb
|
46
|
+
has_rdoc: false
|
47
|
+
homepage:
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.2.0
|
69
|
+
signing_key:
|
70
|
+
specification_version: 2
|
71
|
+
summary: XMPP/Jabber notification plugin for Merb.
|
72
|
+
test_files: []
|
73
|
+
|