skyfallsin-ruby_bosh 0.3.2 → 0.4.0

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/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 2
2
+ :patch: 0
3
3
  :major: 0
4
- :minor: 3
4
+ :minor: 4
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 Timeout < StandardError; end
17
- class AuthFailed < StandardError; end
18
- class ConnFailed < StandardError; end
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 => "jabber:client", :type => "set",
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 "Ruby-BOSH - SEND\n#{msg}"; msg
143
+ puts("Ruby-BOSH - SEND\n#{msg}") if @@logging; msg
137
144
  end
138
145
 
139
146
  def recv(msg)
140
- puts "Ruby-BOSH - RECV\n#{msg}"; msg
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
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require File.join(File.dirname(__FILE__), '..', "lib", "ruby_bosh")
3
+ require 'spec'
4
+
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.3.2
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-18 00:00:00 -08:00
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
- - test/ruby_bosh_test.rb
67
- - test/test_helper.rb
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:
@@ -1,7 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class RubyBoshTest < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end
data/test/test_helper.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
- require 'mocha'
5
-
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'ruby_bosh'
8
-
9
- class Test::Unit::TestCase
10
- end