em-xmpp 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/em-xmpp/entity.rb +46 -1
- data/lib/em-xmpp/helpers.rb +20 -0
- data/lib/em-xmpp/version.rb +1 -1
- data/samples/hello.rb +63 -0
- metadata +10 -8
data/lib/em-xmpp/entity.rb
CHANGED
@@ -29,7 +29,52 @@ module EM::Xmpp
|
|
29
29
|
jid.to_s
|
30
30
|
end
|
31
31
|
|
32
|
-
#TODO:
|
32
|
+
#TODO: say, pub, sub, etc.
|
33
|
+
|
34
|
+
def subscribe
|
35
|
+
pres = connection.presence_stanza('to'=>jid.bare, 'type' => 'subscribe')
|
36
|
+
connection.send_stanza pres
|
37
|
+
end
|
38
|
+
|
39
|
+
def unsubscribe
|
40
|
+
pres = connection.presence_stanza('to'=>jid.bare, 'type' => 'unsubscribe')
|
41
|
+
connection.send_stanza pres
|
42
|
+
end
|
43
|
+
|
44
|
+
def add_to_roster(display_name=nil,groups=[])
|
45
|
+
f = Fiber.current
|
46
|
+
item_fields = {:jid => jid.bare}
|
47
|
+
item_fields[:name] = display_name if display_name
|
48
|
+
|
49
|
+
query = connection.iq_stanza(:type => 'set') do |iq|
|
50
|
+
iq.query(:xmlns => Roster) do |q|
|
51
|
+
q.item item_fields
|
52
|
+
groups.each do |grp|
|
53
|
+
q.group grp
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
connection.send_stanza(query) do |ctx|
|
59
|
+
f.resume ctx
|
60
|
+
end
|
61
|
+
Fiber.yield
|
62
|
+
end
|
63
|
+
|
64
|
+
def remove_from_roster
|
65
|
+
f = Fiber.current
|
66
|
+
item_fields = {:jid => jid.bare, :subscription => 'remove'}
|
67
|
+
|
68
|
+
query = connection.iq_stanza(:type => 'set') do |iq|
|
69
|
+
iq.query(:xmlns => Roster) do |q|
|
70
|
+
q.item item_fields
|
71
|
+
end
|
72
|
+
end
|
73
|
+
connection.send_stanza(query) do |ctx|
|
74
|
+
f.resume ctx
|
75
|
+
end
|
76
|
+
Fiber.yield
|
77
|
+
end
|
33
78
|
|
34
79
|
def discover_infos(node=nil)
|
35
80
|
f = Fiber.current
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
require 'em-xmpp/nodes'
|
3
|
+
module EM::Xmpp
|
4
|
+
module Helpers
|
5
|
+
include EM::Xmpp::Namespaces
|
6
|
+
def get_roster
|
7
|
+
f = Fiber.current
|
8
|
+
|
9
|
+
roster = iq_stanza do |iq|
|
10
|
+
iq.query(:xmlns => Roster)
|
11
|
+
end
|
12
|
+
|
13
|
+
send_stanza roster do |rsp|
|
14
|
+
f.resume rsp.items
|
15
|
+
end
|
16
|
+
|
17
|
+
Fiber.yield
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/em-xmpp/version.rb
CHANGED
data/samples/hello.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
$LOAD_PATH.unshift './lib'
|
2
|
+
require 'em-xmpp'
|
3
|
+
require 'em-xmpp/helpers'
|
4
|
+
|
5
|
+
if ARGV.empty?
|
6
|
+
puts "usage: #{__FILE__} <jid> [<pass>] [certificates-dir]"
|
7
|
+
exit 0
|
8
|
+
end
|
9
|
+
|
10
|
+
jid = ARGV.first
|
11
|
+
pass = ARGV[1]
|
12
|
+
certdir = ARGV[2]
|
13
|
+
|
14
|
+
module RosterClient
|
15
|
+
attr_reader :roster
|
16
|
+
|
17
|
+
include EM::Xmpp::Helpers
|
18
|
+
def ready
|
19
|
+
puts "***** #{@jid} ready"
|
20
|
+
|
21
|
+
on_presence do |ctx|
|
22
|
+
if ctx.subscription_request?
|
23
|
+
puts "**** accepting subscription from #{ctx.from}"
|
24
|
+
send_stanza ctx.reply('type'=>'subscribed')
|
25
|
+
ctx.from.subscribe
|
26
|
+
ctx.from.add_to_roster
|
27
|
+
else
|
28
|
+
puts "**** #{ctx.from} is present"
|
29
|
+
end
|
30
|
+
|
31
|
+
ctx #returns a ctx for subsequent handlers if any
|
32
|
+
end
|
33
|
+
|
34
|
+
on_message do |ctx|
|
35
|
+
puts "**** message from #{ctx.from}"
|
36
|
+
puts ctx.body
|
37
|
+
hello = ctx.reply do |rep|
|
38
|
+
rep.body "hello world"
|
39
|
+
end
|
40
|
+
send_stanza hello
|
41
|
+
|
42
|
+
ctx #returns a ctx for subsequent handlers if any
|
43
|
+
end
|
44
|
+
|
45
|
+
on_exception(:anything) do |ctx|
|
46
|
+
p "rescued error"
|
47
|
+
raise ctx.env['error']
|
48
|
+
ctx
|
49
|
+
end
|
50
|
+
|
51
|
+
puts "***** friends list"
|
52
|
+
subscriptions = get_roster
|
53
|
+
subscriptions.each do |sub|
|
54
|
+
p sub.to_a
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
cfg = {:certificates => certdir}
|
60
|
+
|
61
|
+
EM.run do
|
62
|
+
conn = EM::Xmpp::Connection.start(jid, pass, RosterClient, cfg)
|
63
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-xmpp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-25 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
16
|
-
requirement: &
|
16
|
+
requirement: &2154466840 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2154466840
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: nokogiri
|
27
|
-
requirement: &
|
27
|
+
requirement: &2154466420 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2154466420
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: ruby-sasl
|
38
|
-
requirement: &
|
38
|
+
requirement: &2154466000 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2154466000
|
47
47
|
description: XMPP client for event machine
|
48
48
|
email:
|
49
49
|
- crapooze@gmail.com
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- lib/em-xmpp/context.rb
|
65
65
|
- lib/em-xmpp/entity.rb
|
66
66
|
- lib/em-xmpp/handler.rb
|
67
|
+
- lib/em-xmpp/helpers.rb
|
67
68
|
- lib/em-xmpp/jid.rb
|
68
69
|
- lib/em-xmpp/namespaces.rb
|
69
70
|
- lib/em-xmpp/nodes.rb
|
@@ -71,6 +72,7 @@ files:
|
|
71
72
|
- lib/em-xmpp/stanza_handler.rb
|
72
73
|
- lib/em-xmpp/stanza_matcher.rb
|
73
74
|
- lib/em-xmpp/version.rb
|
75
|
+
- samples/hello.rb
|
74
76
|
homepage: https://github.com/crapooze/em-xmpp
|
75
77
|
licenses: []
|
76
78
|
post_install_message:
|