ruby_bosh 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION.yml +1 -1
  2. data/lib/ruby_bosh.rb +37 -15
  3. data/ruby_bosh.gemspec +2 -2
  4. metadata +4 -4
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :build:
4
- :minor: 6
4
+ :minor: 7
5
5
  :patch: 0
data/lib/ruby_bosh.rb CHANGED
@@ -3,8 +3,6 @@ require 'builder'
3
3
  require 'rexml/document'
4
4
  require 'base64'
5
5
  require 'hpricot'
6
- require 'timeout'
7
- require 'system_timer'
8
6
 
9
7
  class RubyBOSH
10
8
  BOSH_XMLNS = 'http://jabber.org/protocol/httpbind'
@@ -126,32 +124,56 @@ class RubyBOSH
126
124
  end
127
125
 
128
126
  def parse(_response)
129
- doc = Hpricot(_response)
127
+ doc = Hpricot(_response.to_s)
130
128
  doc.search("//body").each do |body|
131
129
  @sid = body.attributes["sid"].to_s
132
130
  end
133
131
  _response
134
132
  end
135
133
 
136
- def deliver(xml)
137
- SystemTimer.timeout(@timeout) do
138
- send(xml)
139
- recv(RestClient.post(@service_url, xml, @headers))
134
+ begin
135
+ require 'system_timer'
136
+ def deliver(xml)
137
+ SystemTimer.timeout(@timeout) do
138
+ send(xml)
139
+ recv(RestClient.post(@service_url, xml, @headers))
140
+ end
141
+ rescue ::Timeout::Error => e
142
+ raise RubyBOSH::Timeout, e.message
143
+ rescue Errno::ECONNREFUSED => e
144
+ raise RubyBOSH::ConnFailed, "could not connect to #{@host}\n#{e.message}"
145
+ rescue Exception => e
146
+ raise RubyBOSH::Error, e.message
147
+ end
148
+ rescue LoadError
149
+ warn "WARNING: using the built-in Timeout class which is known to have issues when used for opening connections. Install the SystemTimer gem if you want to make sure the Redis client will not hang." unless RUBY_VERSION >= "1.9" || RUBY_PLATFORM =~ /java/
150
+
151
+ require "timeout"
152
+ def deliver(xml)
153
+ Timeout.timeout(@timeout) do
154
+ send(xml)
155
+ recv(RestClient.post(@service_url, xml, @headers))
156
+ end
157
+ rescue ::Timeout::Error => e
158
+ raise RubyBOSH::Timeout, e.message
159
+ rescue Errno::ECONNREFUSED => e
160
+ raise RubyBOSH::ConnFailed, "could not connect to #{@host}\n#{e.message}"
161
+ rescue Exception => e
162
+ raise RubyBOSH::Error, e.message
140
163
  end
141
- rescue ::Timeout::Error => e
142
- raise RubyBOSH::Timeout, e.message
143
- rescue Errno::ECONNREFUSED => e
144
- raise RubyBOSH::ConnFailed, "could not connect to #{@host}\n#{e.message}"
145
- rescue Exception => e
146
- raise RubyBOSH::Error, e.message
147
164
  end
148
165
 
149
166
  def send(msg)
150
- puts("Ruby-BOSH - SEND\n#{msg}") if @@logging; msg
167
+ puts("Ruby-BOSH - SEND\n[#{now}]: #{msg}") if @@logging; msg
151
168
  end
152
169
 
153
170
  def recv(msg)
154
- puts("Ruby-BOSH - RECV\n#{msg}") if @logging; msg
171
+ puts("Ruby-BOSH - RECV\n[#{now}]: #{msg}") if @logging; msg
172
+ end
173
+
174
+ private
175
+ def now
176
+ Time.now.strftime("%a %b %d %H:%M:%S %Y")
155
177
  end
156
178
  end
157
179
 
data/ruby_bosh.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruby_bosh}
8
- s.version = "0.6.0"
8
+ s.version = "0.7.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Pradeep Elankumaran"]
12
- s.date = %q{2011-03-17}
12
+ s.date = %q{2011-05-03}
13
13
  s.description = %q{An XMPP BOSH session pre-initializer for Ruby web applications}
14
14
  s.email = %q{pradeep@intridea.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_bosh
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 6
8
+ - 7
9
9
  - 0
10
- version: 0.6.0
10
+ version: 0.7.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pradeep Elankumaran
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-17 00:00:00 -07:00
18
+ date: 2011-05-03 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency