blather 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ v0.5.3
2
+ Feature(benlangfeld): Add XMPP Ping (XEP-0199) support
3
+
1
4
  v0.5.2
2
5
  Bugfix(benlangfeld): Remove specs for the Nokogiri extensions which were moved out
3
6
 
data/lib/blather.rb CHANGED
@@ -28,10 +28,11 @@
28
28
 
29
29
  blather/stanza
30
30
  blather/stanza/iq
31
- blather/stanza/iq/query
32
31
  blather/stanza/iq/command
33
- blather/stanza/iq/roster
34
32
  blather/stanza/iq/ibb
33
+ blather/stanza/iq/ping
34
+ blather/stanza/iq/query
35
+ blather/stanza/iq/roster
35
36
  blather/stanza/iq/s5b
36
37
  blather/stanza/iq/si
37
38
  blather/stanza/iq/vcard
@@ -226,6 +226,10 @@ module Blather
226
226
  # write StanzaError.new(iq, 'service-unavailable', :cancel).to_node
227
227
  # end
228
228
 
229
+ register_handler :ping, :type => :get do |ping|
230
+ write ping.reply
231
+ end
232
+
229
233
  register_handler :status do |status|
230
234
  roster[status.from].status = status if roster[status.from]
231
235
  nil
@@ -0,0 +1,50 @@
1
+ module Blather
2
+ class Stanza
3
+ class Iq
4
+
5
+ # # Ping Stanza
6
+ #
7
+ # [XEP-0199: XMPP Ping](http://xmpp.org/extensions/xep-0199.html)
8
+ #
9
+ # This is a base class for any Ping based Iq stanzas.
10
+ #
11
+ # @handler :ping
12
+ class Ping < Iq
13
+ # @private
14
+ register :ping, :ping, 'urn:xmpp:ping'
15
+
16
+ # Overrides the parent method to ensure a ping node is created
17
+ #
18
+ # @see Blather::Stanza::Iq.new
19
+ def self.new(type = :get, to = nil, id = nil)
20
+ node = super
21
+ node.ping
22
+ node
23
+ end
24
+
25
+ # Overrides the parent method to ensure the current ping node is destroyed
26
+ #
27
+ # @see Blather::Stanza::Iq#inherit
28
+ def inherit(node)
29
+ ping.remove
30
+ super
31
+ end
32
+
33
+ # Ping node accessor
34
+ # If a ping node exists it will be returned.
35
+ # Otherwise a new node will be created and returned
36
+ #
37
+ # @return [Balather::XMPPNode]
38
+ def ping
39
+ p = find_first 'ns:ping', :ns => self.class.registered_ns
40
+
41
+ unless p
42
+ (self << (p = XMPPNode.new('ping', self.document)))
43
+ p.namespace = self.class.registered_ns
44
+ end
45
+ p
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,4 +1,4 @@
1
1
  module Blather
2
2
  # Blather version number
3
- VERSION = '0.5.2'
3
+ VERSION = '0.5.3'
4
4
  end
@@ -291,6 +291,13 @@ describe 'Blather::Client default handlers' do
291
291
  # @client.receive_data get
292
292
  # end
293
293
 
294
+ it 'responds to s2c pings with a pong' do
295
+ ping = Blather::Stanza::Iq::Ping.new :get
296
+ pong = ping.reply
297
+ @client.expects(:write).with { |n| n.to_s.must_equal pong.to_s }
298
+ @client.receive_data ping
299
+ end
300
+
294
301
  it 'handles status changes by updating the roster if the status is from a Blather::JID in the roster' do
295
302
  jid = 'friend@jabber.local'
296
303
  status = Blather::Stanza::Presence::Status.new :away
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ def ping_xml
4
+ <<-XML
5
+ <iq from='capulet.lit' to='juliet@capulet.lit/balcony' id='s2c1' type='get'>
6
+ <ping xmlns='urn:xmpp:ping'/>
7
+ </iq>
8
+ XML
9
+ end
10
+
11
+ describe Blather::Stanza::Iq::Ping do
12
+ it 'registers itself' do
13
+ Blather::XMPPNode.class_from_registration(:ping, 'urn:xmpp:ping').must_equal Blather::Stanza::Iq::Ping
14
+ end
15
+
16
+ it 'can be imported' do
17
+ doc = parse_stanza ping_xml
18
+ node = Blather::XMPPNode.import(doc.root)
19
+ node.must_be_instance_of Blather::Stanza::Iq::Ping
20
+ end
21
+
22
+ it 'ensures a ping node is present on create' do
23
+ iq = Blather::Stanza::Iq::Ping.new
24
+ iq.xpath('ns:ping', :ns => 'urn:xmpp:ping').wont_be_empty
25
+ end
26
+
27
+ it 'ensures a ping node exists when calling #ping' do
28
+ iq = Blather::Stanza::Iq::Ping.new
29
+ iq.ping.remove
30
+ iq.xpath('ns:ping', :ns => 'urn:xmpp:ping').must_be_empty
31
+
32
+ iq.ping.wont_be_nil
33
+ iq.xpath('ns:ping', :ns => 'urn:xmpp:ping').wont_be_empty
34
+ end
35
+
36
+ it 'responds with an empty IQ' do
37
+ ping = Blather::Stanza::Iq::Ping.new :get, 'one@example.com', 'abc123'
38
+ ping.from = 'two@example.com'
39
+ ping.reply.must_equal Blather::Stanza::Iq.new(:result, 'two@example.com', 'abc123')
40
+ end
41
+ end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blather
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 5
9
- - 2
10
- version: 0.5.2
8
+ - 3
9
+ version: 0.5.3
11
10
  platform: ruby
12
11
  authors:
13
12
  - Jeff Smick
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-06-09 00:00:00 +01:00
17
+ date: 2011-06-26 00:00:00 +01:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ~>
28
27
  - !ruby/object:Gem::Version
29
- hash: 35
30
28
  segments:
31
29
  - 0
32
30
  - 12
@@ -42,7 +40,6 @@ dependencies:
42
40
  requirements:
43
41
  - - ">="
44
42
  - !ruby/object:Gem::Version
45
- hash: 7
46
43
  segments:
47
44
  - 1
48
45
  - 4
@@ -58,7 +55,6 @@ dependencies:
58
55
  requirements:
59
56
  - - ">="
60
57
  - !ruby/object:Gem::Version
61
- hash: 23
62
58
  segments:
63
59
  - 0
64
60
  - 0
@@ -74,7 +70,6 @@ dependencies:
74
70
  requirements:
75
71
  - - ">="
76
72
  - !ruby/object:Gem::Version
77
- hash: 9
78
73
  segments:
79
74
  - 1
80
75
  - 7
@@ -90,7 +85,6 @@ dependencies:
90
85
  requirements:
91
86
  - - ">="
92
87
  - !ruby/object:Gem::Version
93
- hash: 9
94
88
  segments:
95
89
  - 3
96
90
  - 0
@@ -106,7 +100,6 @@ dependencies:
106
100
  requirements:
107
101
  - - ~>
108
102
  - !ruby/object:Gem::Version
109
- hash: 9
110
103
  segments:
111
104
  - 1
112
105
  - 7
@@ -122,7 +115,6 @@ dependencies:
122
115
  requirements:
123
116
  - - ~>
124
117
  - !ruby/object:Gem::Version
125
- hash: 35
126
118
  segments:
127
119
  - 0
128
120
  - 9
@@ -138,7 +130,6 @@ dependencies:
138
130
  requirements:
139
131
  - - ~>
140
132
  - !ruby/object:Gem::Version
141
- hash: 23
142
133
  segments:
143
134
  - 1
144
135
  - 0
@@ -154,7 +145,6 @@ dependencies:
154
145
  requirements:
155
146
  - - ~>
156
147
  - !ruby/object:Gem::Version
157
- hash: 41
158
148
  segments:
159
149
  - 0
160
150
  - 9
@@ -170,7 +160,6 @@ dependencies:
170
160
  requirements:
171
161
  - - ~>
172
162
  - !ruby/object:Gem::Version
173
- hash: 5
174
163
  segments:
175
164
  - 0
176
165
  - 6
@@ -186,7 +175,6 @@ dependencies:
186
175
  requirements:
187
176
  - - ~>
188
177
  - !ruby/object:Gem::Version
189
- hash: 11
190
178
  segments:
191
179
  - 2
192
180
  - 1
@@ -202,7 +190,6 @@ dependencies:
202
190
  requirements:
203
191
  - - ">="
204
192
  - !ruby/object:Gem::Version
205
- hash: 3
206
193
  segments:
207
194
  - 0
208
195
  version: "0"
@@ -261,6 +248,7 @@ files:
261
248
  - lib/blather/stanza/iq.rb
262
249
  - lib/blather/stanza/iq/command.rb
263
250
  - lib/blather/stanza/iq/ibb.rb
251
+ - lib/blather/stanza/iq/ping.rb
264
252
  - lib/blather/stanza/iq/query.rb
265
253
  - lib/blather/stanza/iq/roster.rb
266
254
  - lib/blather/stanza/iq/s5b.rb
@@ -313,6 +301,7 @@ files:
313
301
  - spec/blather/stanza/discos/disco_items_spec.rb
314
302
  - spec/blather/stanza/iq/command_spec.rb
315
303
  - spec/blather/stanza/iq/ibb_spec.rb
304
+ - spec/blather/stanza/iq/ping_spec.rb
316
305
  - spec/blather/stanza/iq/query_spec.rb
317
306
  - spec/blather/stanza/iq/roster_spec.rb
318
307
  - spec/blather/stanza/iq/s5b_spec.rb
@@ -363,7 +352,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
363
352
  requirements:
364
353
  - - ">="
365
354
  - !ruby/object:Gem::Version
366
- hash: 3
367
355
  segments:
368
356
  - 0
369
357
  version: "0"
@@ -372,14 +360,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
372
360
  requirements:
373
361
  - - ">="
374
362
  - !ruby/object:Gem::Version
375
- hash: 3
376
363
  segments:
377
364
  - 0
378
365
  version: "0"
379
366
  requirements: []
380
367
 
381
368
  rubyforge_project:
382
- rubygems_version: 1.4.2
369
+ rubygems_version: 1.3.7
383
370
  signing_key:
384
371
  specification_version: 3
385
372
  summary: Simpler XMPP built for speed
@@ -399,6 +386,7 @@ test_files:
399
386
  - spec/blather/stanza/discos/disco_items_spec.rb
400
387
  - spec/blather/stanza/iq/command_spec.rb
401
388
  - spec/blather/stanza/iq/ibb_spec.rb
389
+ - spec/blather/stanza/iq/ping_spec.rb
402
390
  - spec/blather/stanza/iq/query_spec.rb
403
391
  - spec/blather/stanza/iq/roster_spec.rb
404
392
  - spec/blather/stanza/iq/s5b_spec.rb