sprsquish-blather 0.4.3 → 0.4.4
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.rdoc +12 -0
- data/lib/blather/client/client.rb +3 -2
- data/lib/blather/client/dsl.rb +7 -1
- data/lib/blather/client/dsl/pubsub.rb +3 -2
- data/spec/blather/client/client_spec.rb +26 -0
- data/spec/blather/client/dsl_spec.rb +5 -0
- metadata +4 -3
data/README.rdoc
CHANGED
@@ -57,6 +57,18 @@ Setup handlers by calling their names as methods.
|
|
57
57
|
# and #body == 'exit'
|
58
58
|
message :chat?, :body => 'exit'
|
59
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
|
+
|
60
72
|
=== Handler Guards
|
61
73
|
|
62
74
|
Guards act like AND statements. Each condition must be met if the handler is to be used.
|
@@ -80,6 +80,7 @@ module Blather #:nodoc:
|
|
80
80
|
klass = @setup[0].node ? Blather::Stream::Client : Blather::Stream::Component
|
81
81
|
klass.start self, *@setup
|
82
82
|
end
|
83
|
+
alias_method :connect, :run
|
83
84
|
|
84
85
|
##
|
85
86
|
# Register a filter to be run before or after the handler chain is run.
|
@@ -141,7 +142,7 @@ module Blather #:nodoc:
|
|
141
142
|
end
|
142
143
|
|
143
144
|
def unbind # :nodoc:
|
144
|
-
EM.
|
145
|
+
call_handler_for(:disconnected, nil) || (EM.reactor_running? && EM.stop)
|
145
146
|
end
|
146
147
|
|
147
148
|
def receive_data(stanza) # :nodoc:
|
@@ -176,7 +177,7 @@ module Blather #:nodoc:
|
|
176
177
|
end
|
177
178
|
|
178
179
|
def current_handlers
|
179
|
-
[:ready] + Stanza.handler_list + BlatherError.handler_list
|
180
|
+
[:ready, :disconnected] + Stanza.handler_list + BlatherError.handler_list
|
180
181
|
end
|
181
182
|
|
182
183
|
def setup_initial_handlers # :nodoc:
|
data/lib/blather/client/dsl.rb
CHANGED
@@ -11,7 +11,7 @@ module Blather
|
|
11
11
|
module_function :client
|
12
12
|
|
13
13
|
def pubsub
|
14
|
-
@pubsub ||= PubSub.new jid.domain
|
14
|
+
@pubsub ||= PubSub.new client, jid.domain
|
15
15
|
end
|
16
16
|
|
17
17
|
##
|
@@ -62,6 +62,12 @@ module Blather
|
|
62
62
|
handle :ready, &block
|
63
63
|
end
|
64
64
|
|
65
|
+
##
|
66
|
+
# Wrapper for "handle :disconnected"
|
67
|
+
def disconnected(&block)
|
68
|
+
handle :disconnected, &block
|
69
|
+
end
|
70
|
+
|
65
71
|
##
|
66
72
|
# Set current status
|
67
73
|
def set_status(state = nil, msg = nil)
|
@@ -4,7 +4,8 @@ module DSL
|
|
4
4
|
class PubSub
|
5
5
|
attr_accessor :host
|
6
6
|
|
7
|
-
def initialize(host)
|
7
|
+
def initialize(client, host)
|
8
|
+
@client = client
|
8
9
|
@host = host
|
9
10
|
end
|
10
11
|
|
@@ -120,7 +121,7 @@ module DSL
|
|
120
121
|
private
|
121
122
|
def request(node, method = nil, callback = nil, &block)
|
122
123
|
block = lambda { |node| callback.call(method ? node.__send__(method) : node) } unless block_given?
|
123
|
-
|
124
|
+
@client.write_with_handler(node, &block)
|
124
125
|
end
|
125
126
|
|
126
127
|
def send_to(host = nil)
|
@@ -76,6 +76,32 @@ describe Blather::Client do
|
|
76
76
|
@client.unbind
|
77
77
|
end
|
78
78
|
|
79
|
+
it 'calls the :disconnected handler with #unbind is called' do
|
80
|
+
EM.expects(:reactor_running?).returns false
|
81
|
+
disconnected = mock()
|
82
|
+
disconnected.expects(:call)
|
83
|
+
@client.register_handler(:disconnected) { disconnected.call }
|
84
|
+
@client.unbind
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'does not call EM.stop on #unbind if a handler returns positive' do
|
88
|
+
EM.expects(:reactor_running?).never
|
89
|
+
EM.expects(:stop).never
|
90
|
+
disconnected = mock()
|
91
|
+
disconnected.expects(:call).returns true
|
92
|
+
@client.register_handler(:disconnected) { disconnected.call }
|
93
|
+
@client.unbind
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'calls EM.stop on #unbind if a handler returns negative' do
|
97
|
+
EM.expects(:reactor_running?).returns true
|
98
|
+
EM.expects(:stop)
|
99
|
+
disconnected = mock()
|
100
|
+
disconnected.expects(:call).returns false
|
101
|
+
@client.register_handler(:disconnected) { disconnected.call }
|
102
|
+
@client.unbind
|
103
|
+
end
|
104
|
+
|
79
105
|
it 'can register a temporary handler based on stanza ID' do
|
80
106
|
stanza = Blather::Stanza::Iq.new
|
81
107
|
response = mock()
|
@@ -63,6 +63,11 @@ describe Blather::DSL do
|
|
63
63
|
@dsl.when_ready
|
64
64
|
end
|
65
65
|
|
66
|
+
it 'provides a helper for disconnected' do
|
67
|
+
@client.expects(:register_handler).with :disconnected
|
68
|
+
@dsl.disconnected
|
69
|
+
end
|
70
|
+
|
66
71
|
it 'sets the initial status' do
|
67
72
|
state = :away
|
68
73
|
msg = 'do not disturb'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprsquish-blather
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
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: 2009-
|
12
|
+
date: 2009-08-12 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- README.rdoc
|
109
109
|
has_rdoc: false
|
110
110
|
homepage: http://github.com/sprsquish/blather
|
111
|
+
licenses:
|
111
112
|
post_install_message:
|
112
113
|
rdoc_options:
|
113
114
|
- --charset=UTF-8
|
@@ -128,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
129
|
requirements: []
|
129
130
|
|
130
131
|
rubyforge_project: squishtech
|
131
|
-
rubygems_version: 1.
|
132
|
+
rubygems_version: 1.3.5
|
132
133
|
signing_key:
|
133
134
|
specification_version: 3
|
134
135
|
summary: Simpler XMPP built for speed
|