blather 0.4.7 → 0.4.8
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/README.md +162 -0
- data/examples/{print_heirarchy.rb → print_hierarchy.rb} +5 -5
- data/examples/stream_only.rb +27 -0
- data/lib/blather.rb +4 -0
- data/lib/blather/client/client.rb +91 -73
- data/lib/blather/client/dsl.rb +156 -32
- data/lib/blather/client/dsl/pubsub.rb +86 -54
- data/lib/blather/core_ext/active_support.rb +9 -9
- data/lib/blather/core_ext/active_support/inheritable_attributes.rb +2 -2
- data/lib/blather/core_ext/nokogiri.rb +12 -7
- data/lib/blather/errors.rb +25 -14
- data/lib/blather/errors/sasl_error.rb +21 -3
- data/lib/blather/errors/stanza_error.rb +37 -21
- data/lib/blather/errors/stream_error.rb +27 -17
- data/lib/blather/jid.rb +79 -24
- data/lib/blather/roster.rb +39 -21
- data/lib/blather/roster_item.rb +43 -21
- data/lib/blather/stanza.rb +88 -40
- data/lib/blather/stanza/disco.rb +12 -2
- data/lib/blather/stanza/disco/disco_info.rb +112 -20
- data/lib/blather/stanza/disco/disco_items.rb +81 -12
- data/lib/blather/stanza/iq.rb +94 -38
- data/lib/blather/stanza/iq/query.rb +16 -22
- data/lib/blather/stanza/iq/roster.rb +98 -20
- data/lib/blather/stanza/message.rb +266 -111
- data/lib/blather/stanza/presence.rb +118 -42
- data/lib/blather/stanza/presence/status.rb +140 -60
- data/lib/blather/stanza/presence/subscription.rb +44 -10
- data/lib/blather/stanza/pubsub.rb +70 -15
- data/lib/blather/stanza/pubsub/affiliations.rb +36 -7
- data/lib/blather/stanza/pubsub/create.rb +26 -4
- data/lib/blather/stanza/pubsub/errors.rb +13 -4
- data/lib/blather/stanza/pubsub/event.rb +56 -10
- data/lib/blather/stanza/pubsub/items.rb +46 -6
- data/lib/blather/stanza/pubsub/publish.rb +52 -7
- data/lib/blather/stanza/pubsub/retract.rb +45 -6
- data/lib/blather/stanza/pubsub/subscribe.rb +30 -4
- data/lib/blather/stanza/pubsub/subscription.rb +74 -6
- data/lib/blather/stanza/pubsub/subscriptions.rb +35 -9
- data/lib/blather/stanza/pubsub/unsubscribe.rb +30 -4
- data/lib/blather/stanza/pubsub_owner.rb +17 -7
- data/lib/blather/stanza/pubsub_owner/delete.rb +23 -5
- data/lib/blather/stanza/pubsub_owner/purge.rb +23 -5
- data/lib/blather/stream.rb +96 -29
- data/lib/blather/stream/parser.rb +6 -9
- data/lib/blather/xmpp_node.rb +101 -153
- data/spec/blather/client/client_spec.rb +1 -1
- data/spec/blather/errors_spec.rb +5 -5
- data/spec/blather/stanza/message_spec.rb +56 -0
- data/spec/blather/stanza/presence/status_spec.rb +1 -1
- data/spec/blather/stanza_spec.rb +3 -3
- data/spec/blather/xmpp_node_spec.rb +19 -74
- metadata +6 -10
- data/README.rdoc +0 -185
- data/examples/drb_client.rb +0 -5
- data/examples/ping.rb +0 -11
- data/examples/pong.rb +0 -6
- data/examples/pubsub/cli.rb +0 -64
- data/examples/pubsub/ping_pong.rb +0 -18
@@ -116,7 +116,7 @@ describe Blather::Stanza::Presence::Status do
|
|
116
116
|
lambda { status1 <=> status2 }.must_raise(Blather::ArgumentError)
|
117
117
|
end
|
118
118
|
|
119
|
-
Blather::Stanza::Presence::Status::VALID_STATES.each do |valid_state|
|
119
|
+
([:available] + Blather::Stanza::Presence::Status::VALID_STATES).each do |valid_state|
|
120
120
|
it "provides a helper (#{valid_state}?) for state #{valid_state}" do
|
121
121
|
Blather::Stanza::Presence::Status.new.must_respond_to :"#{valid_state}?"
|
122
122
|
end
|
data/spec/blather/stanza_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe Blather::Stanza do
|
|
7
7
|
|
8
8
|
it 'provides a handler registration mechanism' do
|
9
9
|
class Registration < Blather::Stanza; register :handler_test, :handler, 'test:namespace'; end
|
10
|
-
Registration.
|
10
|
+
Registration.handler_hierarchy.must_include :handler_test
|
11
11
|
Blather::Stanza.handler_list.must_include :handler_test
|
12
12
|
end
|
13
13
|
|
@@ -24,8 +24,8 @@ describe Blather::Stanza do
|
|
24
24
|
it 'can register subclass handlers' do
|
25
25
|
class SuperClassRegister < Blather::Stanza; register :super_class; end
|
26
26
|
class SubClassRegister < SuperClassRegister; register :sub_class; end
|
27
|
-
SuperClassRegister.
|
28
|
-
SubClassRegister.
|
27
|
+
SuperClassRegister.handler_hierarchy.wont_include :sub_class
|
28
|
+
SubClassRegister.handler_hierarchy.must_include :super_class
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'can import a node' do
|
@@ -51,110 +51,55 @@ describe Blather::XMPPNode do
|
|
51
51
|
Blather::XMPPNode.import(n).must_be_kind_of ImportSubClass
|
52
52
|
end
|
53
53
|
|
54
|
-
it 'provides an
|
55
|
-
foo =
|
56
|
-
foo.
|
57
|
-
foo.bar.must_be_nil
|
54
|
+
it 'provides an attribute reader' do
|
55
|
+
foo = Blather::XMPPNode.new
|
56
|
+
foo.read_attr(:bar).must_be_nil
|
58
57
|
foo[:bar] = 'baz'
|
59
|
-
foo.bar.must_equal 'baz'
|
58
|
+
foo.read_attr(:bar).must_equal 'baz'
|
60
59
|
end
|
61
60
|
|
62
|
-
it 'provides an
|
63
|
-
foo =
|
64
|
-
foo.
|
65
|
-
foo.bar.must_be_nil
|
61
|
+
it 'provides an attribute reader with converstion' do
|
62
|
+
foo = Blather::XMPPNode.new
|
63
|
+
foo.read_attr(:bar, :to_sym).must_be_nil
|
66
64
|
foo[:bar] = 'baz'
|
67
|
-
foo.bar.must_equal :baz
|
65
|
+
foo.read_attr(:bar, :to_sym).must_equal :baz
|
68
66
|
end
|
69
67
|
|
70
|
-
it 'provides an
|
71
|
-
foo =
|
68
|
+
it 'provides an attribute writer' do
|
69
|
+
foo = Blather::XMPPNode.new
|
72
70
|
foo[:bar].must_be_nil
|
73
|
-
foo.bar
|
71
|
+
foo.write_attr(:bar, 'baz')
|
74
72
|
foo[:bar].must_equal 'baz'
|
75
73
|
end
|
76
74
|
|
77
|
-
it 'provides an attribute_accessor' do
|
78
|
-
foo = Class.new(Blather::XMPPNode) do
|
79
|
-
attribute_accessor :bar, :call => :to_sym
|
80
|
-
attribute_accessor :baz
|
81
|
-
end.new
|
82
|
-
foo.must_respond_to :bar
|
83
|
-
foo.bar.must_be_nil
|
84
|
-
foo.bar = 'fiz'
|
85
|
-
foo.bar.must_equal :fiz
|
86
|
-
|
87
|
-
foo.must_respond_to :baz
|
88
|
-
foo.baz.must_be_nil
|
89
|
-
foo.baz = 'buz'
|
90
|
-
foo.baz.must_equal 'buz'
|
91
|
-
end
|
92
|
-
|
93
75
|
it 'provides a content reader' do
|
94
|
-
foo =
|
76
|
+
foo = Blather::XMPPNode.new('foo')
|
95
77
|
foo << (bar = Blather::XMPPNode.new('bar', foo.document))
|
96
78
|
bar.content = 'baz'
|
97
|
-
foo.
|
98
|
-
foo.bar.must_equal 'baz'
|
79
|
+
foo.read_content(:bar).must_equal 'baz'
|
99
80
|
end
|
100
81
|
|
101
82
|
it 'provides a content reader that converts the value' do
|
102
|
-
foo =
|
83
|
+
foo = Blather::XMPPNode.new('foo')
|
103
84
|
foo << (bar = Blather::XMPPNode.new('bar', foo.document))
|
104
85
|
bar.content = 'baz'
|
105
|
-
foo.
|
106
|
-
foo.bar.must_equal :baz
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'provides a content reader with a different node' do
|
110
|
-
foo = Class.new(Blather::XMPPNode) { content_attr_reader :bar, nil, :fiz }.new('foo')
|
111
|
-
foo << (fiz = Blather::XMPPNode.new('fiz', foo.document))
|
112
|
-
fiz.content = 'baz'
|
113
|
-
foo.must_respond_to :bar
|
114
|
-
foo.bar.must_equal 'baz'
|
86
|
+
foo.read_content(:bar, :to_sym).must_equal :baz
|
115
87
|
end
|
116
88
|
|
117
89
|
it 'provides a content writer' do
|
118
|
-
foo =
|
119
|
-
foo.
|
120
|
-
foo.bar = 'baz'
|
90
|
+
foo = Blather::XMPPNode.new('foo')
|
91
|
+
foo.set_content_for :bar, 'baz'
|
121
92
|
foo.content_from(:bar).must_equal 'baz'
|
122
93
|
end
|
123
94
|
|
124
|
-
it 'provides a content writer with a different node' do
|
125
|
-
foo = Class.new(Blather::XMPPNode) { content_attr_writer :bar, :fiz }.new('foo')
|
126
|
-
foo.must_respond_to :bar=
|
127
|
-
foo.bar = 'baz'
|
128
|
-
foo.content_from(:fiz).must_equal 'baz'
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'provides a content accessor' do
|
132
|
-
foo = Class.new(Blather::XMPPNode) { content_attr_accessor :bar }.new('foo')
|
133
|
-
foo << (bar = Blather::XMPPNode.new('bar', foo.document))
|
134
|
-
foo.must_respond_to :bar=
|
135
|
-
foo.must_respond_to :bar
|
136
|
-
foo.bar = 'baz'
|
137
|
-
foo.bar.must_equal 'baz'
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'provides a content accessor with conversion' do
|
141
|
-
foo = Class.new(Blather::XMPPNode) { content_attr_accessor :bar, :to_sym }.new('foo')
|
142
|
-
foo << (bar = Blather::XMPPNode.new('bar', foo.document))
|
143
|
-
foo.must_respond_to :bar=
|
144
|
-
foo.must_respond_to :bar
|
145
|
-
foo.bar = 'baz'
|
146
|
-
foo.bar.must_equal :baz
|
147
|
-
end
|
148
|
-
|
149
95
|
it 'provides a content writer that removes a child when set to nil' do
|
150
|
-
foo =
|
96
|
+
foo = Blather::XMPPNode.new('foo')
|
151
97
|
foo << (bar = Blather::XMPPNode.new('bar', foo.document))
|
152
98
|
bar.content = 'baz'
|
153
99
|
foo.content_from(:bar).must_equal 'baz'
|
154
100
|
foo.xpath('bar').wont_be_empty
|
155
101
|
|
156
|
-
foo.
|
157
|
-
foo.bar = nil
|
102
|
+
foo.set_content_for :bar, nil
|
158
103
|
foo.content_from(:bar).must_be_nil
|
159
104
|
foo.xpath('bar').must_be_empty
|
160
105
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blather
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Smick
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-17 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -40,18 +40,14 @@ extensions: []
|
|
40
40
|
|
41
41
|
extra_rdoc_files:
|
42
42
|
- LICENSE
|
43
|
-
- README.
|
43
|
+
- README.md
|
44
44
|
files:
|
45
|
-
- examples/drb_client.rb
|
46
45
|
- examples/echo.rb
|
47
46
|
- examples/execute.rb
|
48
|
-
- examples/ping.rb
|
49
47
|
- examples/ping_pong.rb
|
50
|
-
- examples/
|
51
|
-
- examples/print_heirarchy.rb
|
52
|
-
- examples/pubsub/cli.rb
|
53
|
-
- examples/pubsub/ping_pong.rb
|
48
|
+
- examples/print_hierarchy.rb
|
54
49
|
- examples/rosterprint.rb
|
50
|
+
- examples/stream_only.rb
|
55
51
|
- examples/xmpp4r/echo.rb
|
56
52
|
- lib/blather.rb
|
57
53
|
- lib/blather/client.rb
|
@@ -105,7 +101,7 @@ files:
|
|
105
101
|
- lib/blather/stream/parser.rb
|
106
102
|
- lib/blather/xmpp_node.rb
|
107
103
|
- LICENSE
|
108
|
-
- README.
|
104
|
+
- README.md
|
109
105
|
has_rdoc: true
|
110
106
|
homepage: http://github.com/sprsquish/blather
|
111
107
|
licenses: []
|
data/README.rdoc
DELETED
@@ -1,185 +0,0 @@
|
|
1
|
-
= Blather
|
2
|
-
|
3
|
-
XMPP DSL (and more) for Ruby written on EventMachine and Nokogiri.
|
4
|
-
|
5
|
-
== Features
|
6
|
-
|
7
|
-
* evented architecture
|
8
|
-
* uses Nokogiri
|
9
|
-
* simplified starting point
|
10
|
-
|
11
|
-
== Project Pages
|
12
|
-
|
13
|
-
Blather:: https://sprsquish.github.com/blather
|
14
|
-
|
15
|
-
GitHub:: https://github.com/sprsquish/blather
|
16
|
-
|
17
|
-
GitHub Docs:: http://docs.github.com/sprsquish/blather
|
18
|
-
|
19
|
-
RubyForge:: http://rubyforge.org/projects/squishtech
|
20
|
-
|
21
|
-
RDocs:: http://squishtech.rubyforge.org/blather
|
22
|
-
|
23
|
-
Google Group:: http://groups.google.com/group/xmpp-blather
|
24
|
-
|
25
|
-
= Usage
|
26
|
-
|
27
|
-
== Installation
|
28
|
-
|
29
|
-
sudo gem install blather
|
30
|
-
|
31
|
-
== Example
|
32
|
-
|
33
|
-
See the examples directory for more advanced examples.
|
34
|
-
|
35
|
-
This will auto-accept any subscription requests and echo back any chat messages.
|
36
|
-
|
37
|
-
require 'rubygems'
|
38
|
-
require 'blather/client'
|
39
|
-
|
40
|
-
setup 'echo@jabber.local', 'echo'
|
41
|
-
|
42
|
-
# Auto approve subscription requests
|
43
|
-
subscription :request? do |s|
|
44
|
-
write_to_stream s.approve!
|
45
|
-
end
|
46
|
-
|
47
|
-
# Echo back what was said
|
48
|
-
message :chat?, :body do |m|
|
49
|
-
write_to_stream m.reply
|
50
|
-
end
|
51
|
-
|
52
|
-
== Handlers
|
53
|
-
|
54
|
-
Setup handlers by calling their names as methods.
|
55
|
-
|
56
|
-
# Will only be called for messages where #chat? responds positively
|
57
|
-
# and #body == 'exit'
|
58
|
-
message :chat?, :body => 'exit'
|
59
|
-
|
60
|
-
=== Non-Stanza Handlers
|
61
|
-
|
62
|
-
So far there are two non-stanza related handlers.
|
63
|
-
|
64
|
-
when_ready (or handle(:ready) {})
|
65
|
-
Called after the connection has been connected. It's good for initializing your system.
|
66
|
-
|
67
|
-
disconnected (or handle(:disconnected) {})
|
68
|
-
Called after the connection has been terminated. Good for teardown or automatic reconnection.
|
69
|
-
The following will reconnect every time the connection is lost:
|
70
|
-
disconnected { client.connect }
|
71
|
-
|
72
|
-
=== Handler Guards
|
73
|
-
|
74
|
-
Guards act like AND statements. Each condition must be met if the handler is to be used.
|
75
|
-
|
76
|
-
# Equivalent to saying (stanza.chat? && stanza.body)
|
77
|
-
message :chat?, :body
|
78
|
-
|
79
|
-
The different types of guards are:
|
80
|
-
|
81
|
-
# Symbol
|
82
|
-
# Checks for a non-false reply to calling the symbol on the stanza
|
83
|
-
# Equivalent to stanza.chat?
|
84
|
-
message :chat?
|
85
|
-
|
86
|
-
# Hash with any value (:body => 'exit')
|
87
|
-
# Calls the key on the stanza and checks for equality
|
88
|
-
# Equivalent to stanza.body == 'exit'
|
89
|
-
message :body => 'exit'
|
90
|
-
|
91
|
-
# Hash with regular expression (:body => /exit/)
|
92
|
-
# Calls the key on the stanza and checks for a match
|
93
|
-
# Equivalent to stanza.body.match /exit/
|
94
|
-
message :body => /exit/
|
95
|
-
|
96
|
-
# Hash with array (:name => [:gone, :forbidden])
|
97
|
-
# Calls the key on the stanza and check for inclusion in the array
|
98
|
-
# Equivalent to [:gone, :forbidden].include?(stanza.name)
|
99
|
-
stanza_error :name => [:gone, :fobidden]
|
100
|
-
|
101
|
-
# Proc
|
102
|
-
# Calls the proc passing in the stanza
|
103
|
-
# Checks that the ID is modulo 3
|
104
|
-
message proc { |m| m.id % 3 == 0 }
|
105
|
-
|
106
|
-
# Array
|
107
|
-
# Use arrays with the previous types effectively turns the guard into
|
108
|
-
# an OR statement.
|
109
|
-
# Equivalent to stanza.body == 'foo' || stanza.body == 'baz'
|
110
|
-
message [{:body => 'foo'}, {:body => 'baz'}]
|
111
|
-
|
112
|
-
# XPath
|
113
|
-
# Runs the xpath query on the stanza and checks for results
|
114
|
-
# This guard type cannot be combined with other guards
|
115
|
-
# Equivalent to !stanza.find('/iq/ns:pubsub', :ns => 'pubsub:namespace').empty?
|
116
|
-
iq '/iq/ns:pubsub', :ns => 'pubsub:namespace'
|
117
|
-
|
118
|
-
=== Filters
|
119
|
-
|
120
|
-
Blather provides before and after filters that work much the way regular handlers work. Filters come in a before and after
|
121
|
-
flavor. They're called in order of definition and can be guarded like handlers.
|
122
|
-
|
123
|
-
before { |s| "I'm run before any handler" }
|
124
|
-
before { |s| "I'm run next" }
|
125
|
-
|
126
|
-
before(:message) { |s| "I'm only run in front of message stanzas" }
|
127
|
-
before(nil, :id => 1) { |s| "I'll only be run when the stanza's ID == 1" }
|
128
|
-
|
129
|
-
# ... handlers
|
130
|
-
|
131
|
-
after { |s| "I'm run after everything" }
|
132
|
-
|
133
|
-
== On the Command Line:
|
134
|
-
|
135
|
-
Default usage is:
|
136
|
-
|
137
|
-
[blather_script] [options] node@domain.com/resource password [host] [port]
|
138
|
-
|
139
|
-
Command line options:
|
140
|
-
|
141
|
-
-D, --debug Run in debug mode (you will see all XMPP communication)
|
142
|
-
-d, --daemonize Daemonize the process
|
143
|
-
--pid=[PID] Write the PID to this file
|
144
|
-
--log=[LOG] Write to the [LOG] file instead of stdout/stderr
|
145
|
-
-h, --help Show this message
|
146
|
-
-v, --version Show version
|
147
|
-
|
148
|
-
|
149
|
-
= TODO
|
150
|
-
|
151
|
-
* Add Disco the the DSL
|
152
|
-
* More examples (Re-write XMPP4R examples into Blather)
|
153
|
-
|
154
|
-
= Author
|
155
|
-
|
156
|
-
Jeff Smick <sprsquish@gmail.com>
|
157
|
-
|
158
|
-
=== Contributors
|
159
|
-
|
160
|
-
Nolan Darilek <nolan@thewordnerd.info>
|
161
|
-
|
162
|
-
= License
|
163
|
-
|
164
|
-
Blather
|
165
|
-
|
166
|
-
Copyright (c) 2009 Jeff Smick
|
167
|
-
|
168
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
169
|
-
a copy of this software and associated documentation files (the
|
170
|
-
"Software"), to deal in the Software without restriction, including
|
171
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
172
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
173
|
-
permit persons to whom the Software is furnished to do so, subject to
|
174
|
-
the following conditions:
|
175
|
-
|
176
|
-
The above copyright notice and this permission notice shall be
|
177
|
-
included in all copies or substantial portions of the Software.
|
178
|
-
|
179
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
180
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
181
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
182
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
183
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
184
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
185
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/examples/drb_client.rb
DELETED
data/examples/ping.rb
DELETED
data/examples/pong.rb
DELETED
data/examples/pubsub/cli.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'blather/client'
|
4
|
-
|
5
|
-
#ls
|
6
|
-
#cd
|
7
|
-
#cat
|
8
|
-
#Blather::LOG.level = Logger::DEBUG
|
9
|
-
module CliHandler
|
10
|
-
include EM::Protocols::LineText2
|
11
|
-
|
12
|
-
def ls(node)
|
13
|
-
pubsub.node(parse_dir(node)) do |result|
|
14
|
-
cur = node.split('/')
|
15
|
-
puts
|
16
|
-
puts result.items.map { |i| (i.node.split('/') - cur).join('/') }.join("\n")
|
17
|
-
start_line
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def cd(node)
|
22
|
-
@node = parse_dir(node)
|
23
|
-
start_line
|
24
|
-
end
|
25
|
-
|
26
|
-
def cat(item)
|
27
|
-
end
|
28
|
-
|
29
|
-
def connect(who)
|
30
|
-
@who = who
|
31
|
-
puts "connected to '#{who}'"
|
32
|
-
end
|
33
|
-
|
34
|
-
def exit(_)
|
35
|
-
EM.stop
|
36
|
-
end
|
37
|
-
|
38
|
-
def initialize
|
39
|
-
$stdout.sync = true
|
40
|
-
@node = ''
|
41
|
-
@who = ''
|
42
|
-
start_line
|
43
|
-
end
|
44
|
-
|
45
|
-
def start_line
|
46
|
-
puts "\n/#{@node}> "
|
47
|
-
end
|
48
|
-
|
49
|
-
def receive_line(line)
|
50
|
-
return unless line =~ /(connect|exit|ls|cd|cat)\s?(.*)/i
|
51
|
-
__send__ $1, $2
|
52
|
-
end
|
53
|
-
|
54
|
-
def parse_dir(list)
|
55
|
-
return '' if list == '/'
|
56
|
-
cur = @node.split('/')
|
57
|
-
list.split('/').each { |dir| dir == '..' ? cur.pop : (cur << dir) }
|
58
|
-
cur * '/'
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
setup 'echo@jabber.local', 'echo'
|
63
|
-
pubsub_host 'pubsub.jabber.local'
|
64
|
-
when_ready { EM.open_keyboard CliHandler }
|