skyfallsin-ruby_bosh 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +2 -2
- data/lib/ruby_bosh.rb +13 -6
- data/spec/ruby_bosh_spec.rb +57 -0
- data/spec/spec_helper.rb +4 -0
- metadata +4 -4
- data/test/ruby_bosh_test.rb +0 -7
- data/test/test_helper.rb +0 -10
data/VERSION.yml
CHANGED
data/lib/ruby_bosh.rb
CHANGED
@@ -12,10 +12,17 @@ class RubyBOSH
|
|
12
12
|
SASL_XMLNS = 'urn:ietf:params:xml:ns:xmpp-sasl'
|
13
13
|
BIND_XMLNS = 'urn:ietf:params:xml:ns:xmpp-bind'
|
14
14
|
SESSION_XMLNS = 'urn:ietf:params:xml:ns:xmpp-session'
|
15
|
+
CLIENT_XMLNS = 'jabber:client'
|
15
16
|
|
16
|
-
class
|
17
|
-
class
|
18
|
-
class
|
17
|
+
class Error < StandardError; end
|
18
|
+
class Timeout < RubyBOSH::Error; end
|
19
|
+
class AuthFailed < RubyBOSH::Error; end
|
20
|
+
class ConnFailed < RubyBOSH::Error; end
|
21
|
+
|
22
|
+
@@logging = true
|
23
|
+
def self.logging=(value)
|
24
|
+
@@logging = value
|
25
|
+
end
|
19
26
|
|
20
27
|
attr_accessor :jid, :rid, :sid, :success
|
21
28
|
def initialize(jid, pw, service_url, opts={})
|
@@ -103,7 +110,7 @@ class RubyBOSH
|
|
103
110
|
|
104
111
|
def send_session_request
|
105
112
|
request = construct_body(:sid => @sid) do |body|
|
106
|
-
body.iq(:xmlns =>
|
113
|
+
body.iq(:xmlns => CLIENT_XMLNS, :type => "set",
|
107
114
|
:id => "sess_#{rand(100000)}") do |iq|
|
108
115
|
iq.session(:xmlns => SESSION_XMLNS)
|
109
116
|
end
|
@@ -133,11 +140,11 @@ class RubyBOSH
|
|
133
140
|
end
|
134
141
|
|
135
142
|
def send(msg)
|
136
|
-
puts
|
143
|
+
puts("Ruby-BOSH - SEND\n#{msg}") if @@logging; msg
|
137
144
|
end
|
138
145
|
|
139
146
|
def recv(msg)
|
140
|
-
puts
|
147
|
+
puts("Ruby-BOSH - RECV\n#{msg}") if @logging; msg
|
141
148
|
end
|
142
149
|
end
|
143
150
|
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe RubyBOSH do
|
4
|
+
before(:each) do
|
5
|
+
RubyBOSH.logging = false
|
6
|
+
@rbosh = RubyBOSH.new("skyfallsin@localhost", "skyfallsin",
|
7
|
+
"http://localhost:5280/http-bind")
|
8
|
+
#@rbosh.stub!(:success?).and_return(true)
|
9
|
+
#@rbosh.stub!(:initialize_bosh_session).and_return(true)
|
10
|
+
@rbosh.stub!(:send_auth_request).and_return(true)
|
11
|
+
@rbosh.stub!(:send_restart_request).and_return(true)
|
12
|
+
@rbosh.stub!(:request_resource_binding).and_return(true)
|
13
|
+
@rbosh.stub!(:send_session_request).and_return(true)
|
14
|
+
RestClient.stub!(:post).and_return("<body sid='123456'></body>")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should set the sid attribute after the session creation request" do
|
18
|
+
@rbosh.connect
|
19
|
+
@rbosh.sid.should == '123456'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should update the rid on every call to the BOSH server" do
|
23
|
+
@rbosh.rid = 100
|
24
|
+
@rbosh.connect
|
25
|
+
@rbosh.rid.should > 100
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return an array with [jid, sid, rid] on success" do
|
29
|
+
s = @rbosh.connect
|
30
|
+
s.should be_kind_of(Array)
|
31
|
+
s.size.should == 3
|
32
|
+
s.first.should == 'skyfallsin@localhost'
|
33
|
+
s.last.should be_kind_of(Fixnum)
|
34
|
+
s[1].should == '123456'
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "Errors" do
|
38
|
+
it "should crash with AuthFailed when its not a success?" do
|
39
|
+
@rbosh.stub!(:send_session_request).and_return(false)
|
40
|
+
lambda { @rbosh.connect }.should raise_error(RubyBOSH::AuthFailed)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should raise a ConnFailed if a connection could not be made to the XMPP server" do
|
44
|
+
RestClient.stub!(:post).and_raise(Errno::ECONNREFUSED)
|
45
|
+
lambda { @rbosh.connect }.should raise_error(RubyBOSH::ConnFailed)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should raise a Timeout::Error if the BOSH call takes forever" do
|
49
|
+
SystemTimer.stub!(:timeout).and_raise(::Timeout::Error)
|
50
|
+
lambda { @rbosh.connect }.should raise_error(RubyBOSH::Timeout)
|
51
|
+
end
|
52
|
+
|
53
|
+
after(:each) do
|
54
|
+
lambda { @rbosh.connect }.should raise_error(RubyBOSH::Error)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: skyfallsin-ruby_bosh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pradeep Elankumaran
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-23 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -63,8 +63,8 @@ extra_rdoc_files: []
|
|
63
63
|
files:
|
64
64
|
- VERSION.yml
|
65
65
|
- lib/ruby_bosh.rb
|
66
|
-
-
|
67
|
-
-
|
66
|
+
- spec/ruby_bosh_spec.rb
|
67
|
+
- spec/spec_helper.rb
|
68
68
|
has_rdoc: true
|
69
69
|
homepage: http://github.com/skyfallsin/ruby_bosh
|
70
70
|
post_install_message:
|
data/test/ruby_bosh_test.rb
DELETED