jubjub 0.0.2 → 0.0.3

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.mdown CHANGED
@@ -62,11 +62,16 @@ Examples
62
62
  room = u.mucs.create('customjub'){|c|
63
63
  c['muc#roomconfig_allowinvites'] = false
64
64
  }
65
-
65
+
66
66
  # Destroy a room
67
67
  room.destroy
68
68
  => true
69
69
 
70
+ # Create a persistent room and exit it
71
+ u.mucs.create('persistent'){|c|
72
+ c['muc#roomconfig_persistentroom'] = true
73
+ }.exit
74
+
70
75
  TODO
71
76
  ====
72
77
 
@@ -327,11 +327,23 @@ module Jubjub
327
327
  }
328
328
  end
329
329
 
330
+ # http://xmpp.org/extensions/xep-0045.html#exit
331
+ # <presence
332
+ # from='hag66@shakespeare.lit/pda'
333
+ # to='darkcave@chat.shakespeare.lit/thirdwitch'
334
+ # type='unavailable'/>
335
+ def exit(full_jid)
336
+ presence full_jid, :unavailable
337
+ end
338
+
330
339
  private
331
340
 
332
- def presence(full_jid)
341
+ def presence(full_jid, availability = :available)
342
+ options = { :to => full_jid }
343
+ options[:type] = availability unless availability == :available
344
+
333
345
  request = Nokogiri::XML::Builder.new do |xml|
334
- xml.presence_(:to => full_jid) {
346
+ xml.presence_(options) {
335
347
  xml.x_('xmlns' => 'http://jabber.org/protocol/muc')
336
348
  }
337
349
  end
data/lib/jubjub/muc.rb CHANGED
@@ -9,6 +9,13 @@ module Jubjub
9
9
  @connection = connection
10
10
  end
11
11
 
12
+ def exit(nick = nil)
13
+ full_jid = Jubjub::Jid.new @jid.node, @jid.domain, nick || @connection.jid.node
14
+
15
+ @connection.muc.exit(full_jid)
16
+ self
17
+ end
18
+
12
19
  def destroy
13
20
  @connection.muc.destroy(@jid)
14
21
  end
@@ -115,6 +115,28 @@ describe Jubjub::Connection::XmppGateway do
115
115
 
116
116
  end
117
117
 
118
+ describe "exit" do
119
+ use_vcr_cassette 'muc exit', :record => :new_episodes
120
+
121
+ before do
122
+ @full_jid = Jubjub::Jid.new 'extra@conference.theo-template.local/nick'
123
+ @jid = Jubjub::Jid.new 'extra@conference.theo-template.local'
124
+ @connection.muc.create(@full_jid)
125
+ end
126
+
127
+ it "should send correct stanza" do
128
+ # will attempt to create new vcr cassette if the stanza is wrong
129
+ # relies on cassette being manually checked
130
+ @connection.muc.exit(@full_jid)
131
+ end
132
+
133
+ after do
134
+ # Just incase the room is persistent
135
+ @connection.muc.destroy(@jid)
136
+ end
137
+
138
+ end
139
+
118
140
  describe "destroy" do
119
141
 
120
142
  use_vcr_cassette 'muc destroy', :record => :new_episodes
@@ -0,0 +1,91 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :post
5
+ uri: http://theozaurus%40theo-template.local:secret@127.0.0.1:8000/
6
+ body: stanza=%3c%3fxml%20version%3d%221.0%22%3f%3e%0a%3cpresence%20to%3d%22extra%40conference.theo-template.local%2fnick%22%3e%0a%20%20%3cx%20xmlns%3d%22http%3a%2f%2fjabber.org%2fprotocol%2fmuc%22%2f%3e%0a%3c%2fpresence%3e%0a
7
+ headers:
8
+ content-type:
9
+ - application/x-www-form-urlencoded
10
+ response: !ruby/struct:VCR::Response
11
+ status: !ruby/struct:VCR::ResponseStatus
12
+ code: 200
13
+ message: ...
14
+ headers:
15
+ content-type:
16
+ - application/xml
17
+ content-length:
18
+ - "40"
19
+ body: |
20
+ #<EventMachine::Timer:0x00000100b29d90>
21
+
22
+ http_version: "1.1"
23
+ - !ruby/struct:VCR::HTTPInteraction
24
+ request: !ruby/struct:VCR::Request
25
+ method: :post
26
+ uri: http://theozaurus%40theo-template.local:secret@127.0.0.1:8000/
27
+ body: stanza=%3c%3fxml%20version%3d%221.0%22%3f%3e%0a%3ciq%20type%3d%22set%22%20to%3d%22extra%40conference.theo-template.local%22%3e%0a%20%20%3cquery%20xmlns%3d%22http%3a%2f%2fjabber.org%2fprotocol%2fmuc%23owner%22%3e%0a%20%20%20%20%3cx%20xmlns%3d%22jabber%3ax%3adata%22%20type%3d%22submit%22%2f%3e%0a%20%20%3c%2fquery%3e%0a%3c%2fiq%3e%0a
28
+ headers:
29
+ content-type:
30
+ - application/x-www-form-urlencoded
31
+ response: !ruby/struct:VCR::Response
32
+ status: !ruby/struct:VCR::ResponseStatus
33
+ code: 200
34
+ message: ...
35
+ headers:
36
+ content-type:
37
+ - application/xml
38
+ content-length:
39
+ - "204"
40
+ body: |
41
+ <iq type="result" id="blather0175" from="extra@conference.theo-template.local" to="theozaurus@theo-template.local/7633460851296657831415060">
42
+ <query xmlns="http://jabber.org/protocol/muc#owner"/>
43
+ </iq>
44
+
45
+ http_version: "1.1"
46
+ - !ruby/struct:VCR::HTTPInteraction
47
+ request: !ruby/struct:VCR::Request
48
+ method: :post
49
+ uri: http://theozaurus%40theo-template.local:secret@127.0.0.1:8000/
50
+ body: stanza=%3c%3fxml%20version%3d%221.0%22%3f%3e%0a%3cpresence%20type%3d%22unavailable%22%20to%3d%22extra%40conference.theo-template.local%2fnick%22%3e%0a%20%20%3cx%20xmlns%3d%22http%3a%2f%2fjabber.org%2fprotocol%2fmuc%22%2f%3e%0a%3c%2fpresence%3e%0a
51
+ headers:
52
+ content-type:
53
+ - application/x-www-form-urlencoded
54
+ response: !ruby/struct:VCR::Response
55
+ status: !ruby/struct:VCR::ResponseStatus
56
+ code: 200
57
+ message: ...
58
+ headers:
59
+ content-type:
60
+ - application/xml
61
+ content-length:
62
+ - "40"
63
+ body: |
64
+ #<EventMachine::Timer:0x00000100ade610>
65
+
66
+ http_version: "1.1"
67
+ - !ruby/struct:VCR::HTTPInteraction
68
+ request: !ruby/struct:VCR::Request
69
+ method: :post
70
+ uri: http://theozaurus%40theo-template.local:secret@127.0.0.1:8000/
71
+ body: stanza=%3c%3fxml%20version%3d%221.0%22%3f%3e%0a%3ciq%20type%3d%22set%22%20to%3d%22extra%40conference.theo-template.local%22%3e%0a%20%20%3cquery%20xmlns%3d%22http%3a%2f%2fjabber.org%2fprotocol%2fmuc%23owner%22%3e%0a%20%20%20%20%3cdestroy%2f%3e%0a%20%20%3c%2fquery%3e%0a%3c%2fiq%3e%0a
72
+ headers:
73
+ content-type:
74
+ - application/x-www-form-urlencoded
75
+ response: !ruby/struct:VCR::Response
76
+ status: !ruby/struct:VCR::ResponseStatus
77
+ code: 200
78
+ message: ...
79
+ headers:
80
+ content-type:
81
+ - application/xml
82
+ content-length:
83
+ - "426"
84
+ body: |
85
+ <iq type="error" id="blather0177" from="extra@conference.theo-template.local" to="theozaurus@theo-template.local/7633460851296657831415060" lang="en">
86
+ <query xmlns="http://jabber.org/protocol/muc#owner">
87
+ <destroy/>
88
+ </query>
89
+ <error code="404" type="cancel"><item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Conference room does not exist</text></error></iq>
90
+
91
+ http_version: "1.1"
@@ -39,6 +39,34 @@ describe Jubjub::Muc do
39
39
  end
40
40
  end
41
41
 
42
+ describe "exit" do
43
+ before do
44
+ muc_mock = mock
45
+ muc_mock.stub(:exit) # exit doesn't work in a stub chain, manually build it
46
+
47
+ @mock_connection = mock
48
+ @mock_connection.stub(:jid).and_return( Jubjub::Jid.new 'nick@foo.com' )
49
+ @mock_connection.stub(:muc).and_return( muc_mock )
50
+ end
51
+
52
+ it "should call muc.exit on connection" do
53
+ @mock_connection.muc.should_receive(:exit).with( Jubjub::Jid.new 'room@conference.foo.com/nick' )
54
+
55
+ Jubjub::Muc.new("room@conference.foo.com",nil,@mock_connection).exit
56
+ end
57
+
58
+ it "should support custom nick name" do
59
+ @mock_connection.muc.should_receive(:exit).with( Jubjub::Jid.new 'room@conference.foo.com/custom_nick' )
60
+
61
+ Jubjub::Muc.new("room@conference.foo.com",nil,@mock_connection).exit('custom_nick')
62
+ end
63
+
64
+ it "should be chainable" do
65
+ room = Jubjub::Muc.new("room@conference.foo.com",nil,@mock_connection)
66
+ room.exit.should eql room
67
+ end
68
+ end
69
+
42
70
  describe "destroy" do
43
71
 
44
72
  it "should call muc.destroy on connection" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jubjub
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Theo Cushion
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-01 00:00:00 +00:00
18
+ date: 2011-02-02 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -114,6 +114,7 @@ files:
114
114
  - spec/fixtures/vcr_cassettes/muc_create.yml
115
115
  - spec/fixtures/vcr_cassettes/muc_create_with_configuration.yml
116
116
  - spec/fixtures/vcr_cassettes/muc_destroy.yml
117
+ - spec/fixtures/vcr_cassettes/muc_exit.yml
117
118
  - spec/fixtures/vcr_cassettes/muc_list.yml
118
119
  - spec/mixins/user_spec.rb
119
120
  - spec/models/jid_spec.rb
@@ -165,6 +166,7 @@ test_files:
165
166
  - spec/fixtures/vcr_cassettes/muc_create.yml
166
167
  - spec/fixtures/vcr_cassettes/muc_create_with_configuration.yml
167
168
  - spec/fixtures/vcr_cassettes/muc_destroy.yml
169
+ - spec/fixtures/vcr_cassettes/muc_exit.yml
168
170
  - spec/fixtures/vcr_cassettes/muc_list.yml
169
171
  - spec/mixins/user_spec.rb
170
172
  - spec/models/jid_spec.rb