From 3910204b73c581725af4612a3410c7101b87c70c Mon Sep 17 00:00:00 2001 From: mike Date: Tue, 14 Jun 2016 15:53:38 -0700 Subject: [PATCH 1/9] updating the code for ruby 2 --- .gitignore | 3 ++- Rakefile | 59 +++++------------------------------------- lib/ruby_bosh.rb | 16 ------------ ruby_bosh.gemspec | 45 ++++++++++++-------------------- spec/ruby_bosh_spec.rb | 24 +++++++---------- spec/spec_helper.rb | 13 +++++++++- 6 files changed, 45 insertions(+), 115 deletions(-) diff --git a/.gitignore b/.gitignore index 0e33e78..2677903 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.sw? .DS_Store -coverage \ No newline at end of file +coverage +.idea \ No newline at end of file diff --git a/Rakefile b/Rakefile index 4209bec..a62de9f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,55 +1,8 @@ -require 'rake' +#!/usr/bin/env rake +require "bundler/gem_tasks" +require "rspec/core/rake_task" -begin - require 'jeweler' - Jeweler::Tasks.new do |s| - s.name = "ruby_bosh" - s.summary = %Q{A BOSH session pre-initializer for Ruby web applications} - s.email = "pradeepe@gmail.com" - s.homepage = "http://github.com/skyfallsin/ruby_bosh" - s.description = "An XMPP BOSH session pre-initializer for Ruby web applications" - s.authors = ["Pradeep Elankumaran"] - - s.add_dependency("builder") - s.add_dependency("rest-client") - s.add_dependency("hpricot") - end -rescue LoadError - puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com" -end +RSpec::Core::RakeTask.new -require 'rdoc/task' -Rake::RDocTask.new do |rdoc| - rdoc.rdoc_dir = 'rdoc' - rdoc.title = 'ruby_bosh' - rdoc.options << '--line-numbers' << '--inline-source' - rdoc.rdoc_files.include('README*') - rdoc.rdoc_files.include('lib/**/*.rb') -end - -require 'rake/testtask' -Rake::TestTask.new(:test) do |t| - t.libs << 'lib' << 'test' - t.pattern = 'test/**/*_test.rb' - t.verbose = false -end - -begin - require 'rcov/rcovtask' - Rcov::RcovTask.new do |t| - t.libs << 'test' - t.test_files = FileList['test/**/*_test.rb'] - t.verbose = true - end -rescue LoadError - puts "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov" -end - -begin - require 'cucumber/rake/task' - Cucumber::Rake::Task.new(:features) -rescue LoadError - puts "Cucumber is not available. In order to run features, you must: sudo gem install cucumber" -end - -task :default => :test +task :default => :spec +task :test => :spec \ No newline at end of file diff --git a/lib/ruby_bosh.rb b/lib/ruby_bosh.rb index 74be172..871679a 100644 --- a/lib/ruby_bosh.rb +++ b/lib/ruby_bosh.rb @@ -136,22 +136,6 @@ def parse(_response) end begin - require 'system_timer' - def deliver(xml) - SystemTimer.timeout(@timeout) do - send(xml) - recv(RestClient.post(@service_url, xml, @headers)) - end - rescue Timeout::Error => e - raise RubyBOSH::TimeoutError, e.message - rescue Errno::ECONNREFUSED => e - raise RubyBOSH::ConnFailed, "could not connect to #{@host}\n#{e.message}" - rescue Exception => e - raise RubyBOSH::Error, e.message - end - rescue LoadError - 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/ - require "timeout" def deliver(xml) ::Timeout.timeout(@timeout) do diff --git a/ruby_bosh.gemspec b/ruby_bosh.gemspec index 1ee3dee..f7ed7b0 100644 --- a/ruby_bosh.gemspec +++ b/ruby_bosh.gemspec @@ -1,17 +1,10 @@ -# Generated by jeweler -# DO NOT EDIT THIS FILE DIRECTLY -# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' -# -*- encoding: utf-8 -*- -# stub: ruby_bosh 0.11.0 ruby lib - Gem::Specification.new do |s| s.name = "ruby_bosh" - s.version = "0.11.0" + s.version = "0.12" - s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.require_paths = ["lib"] - s.authors = ["Pradeep Elankumaran"] - s.date = "2014-12-13" + s.authors = ["Original author: Pradeep Elankumaran. Update for ruby 2: Mike Polischuk"] + s.date = "2016-06-13" s.description = "An XMPP BOSH session pre-initializer for Ruby web applications" s.email = "pradeepe@gmail.com" s.extra_rdoc_files = [ @@ -19,6 +12,7 @@ Gem::Specification.new do |s| "README", "TODO" ] + s.licenses = ['MIT'] s.files = [ "LICENSE", "README", @@ -31,26 +25,19 @@ Gem::Specification.new do |s| "spec/ruby_bosh_spec.rb", "spec/spec_helper.rb" ] - s.homepage = "http://github.com/skyfallsin/ruby_bosh" - s.rubygems_version = "2.4.1" - s.summary = "A BOSH session pre-initializer for Ruby web applications" + s.test_files = s.files.grep(%r{^(test|spec|features)/}) + s.homepage = "http://github.com/mikemarsian/ruby_bosh" + s.summary = "A BOSH session pre-initializer for Ruby web applications (for Ruby 2)" + s.required_ruby_version = '>= 1.9.3' + + s.add_development_dependency "bundler", "~> 1.10" + s.add_development_dependency "rake", "~> 10.0" + s.add_development_dependency "rspec", '~> 3.0' + s.add_development_dependency "rspec_junit_formatter", '0.2.2' - if s.respond_to? :specification_version then - s.specification_version = 4 + s.add_dependency "builder", "~> 3.0" + s.add_dependency "rest-client" , "~> 1.8" + s.add_dependency "hpricot", "~> 0.8" - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then - s.add_runtime_dependency(%q, [">= 0"]) - s.add_runtime_dependency(%q, [">= 0"]) - s.add_runtime_dependency(%q, [">= 0"]) - else - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) - end - else - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) - end end diff --git a/spec/ruby_bosh_spec.rb b/spec/ruby_bosh_spec.rb index 1b7d70e..3a05f51 100644 --- a/spec/ruby_bosh_spec.rb +++ b/spec/ruby_bosh_spec.rb @@ -5,13 +5,12 @@ RubyBOSH.logging = false @rbosh = RubyBOSH.new("skyfallsin@localhost", "skyfallsin", "http://localhost:5280/http-bind") - #@rbosh.stub!(:success?).and_return(true) - #@rbosh.stub!(:initialize_bosh_session).and_return(true) - @rbosh.stub!(:send_auth_request).and_return(true) - @rbosh.stub!(:send_restart_request).and_return(true) - @rbosh.stub!(:request_resource_binding).and_return(true) - @rbosh.stub!(:send_session_request).and_return(true) - RestClient.stub!(:post).and_return("") + + @rbosh.stub(:send_auth_request).and_return(true) + @rbosh.stub(:send_restart_request).and_return(true) + @rbosh.stub(:request_resource_binding).and_return(true) + @rbosh.stub(:send_session_request).and_return(true) + RestClient.stub(:post).and_return("") end it "should set the sid attribute after the session creation request" do @@ -36,23 +35,18 @@ describe "Errors" do it "should crash with AuthFailed when its not a success?" do - @rbosh.stub!(:send_session_request).and_return(false) + @rbosh.stub(:send_session_request).and_return(false) lambda { @rbosh.connect }.should raise_error(RubyBOSH::AuthFailed) end it "should raise a ConnFailed if a connection could not be made to the XMPP server" do - RestClient.stub!(:post).and_raise(Errno::ECONNREFUSED) + RestClient.stub(:post).and_raise(Errno::ECONNREFUSED) lambda { @rbosh.connect }.should raise_error(RubyBOSH::ConnFailed) end - it "should raise a Timeout::Error if the BOSH call takes forever" do - SystemTimer.stub!(:timeout).and_raise(Timeout::Error) - lambda { @rbosh.connect }.should raise_error(RubyBOSH::TimeoutError) - end - it "should crash with a generic error on any other problem" do [RestClient::ServerBrokeConnection, RestClient::RequestTimeout].each{|err| - RestClient.stub!(:post).and_raise(err) + RestClient.stub(:post).and_raise(err) lambda { @rbosh.connect }.should raise_error(RubyBOSH::Error) } end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d55e5f0..8b4e348 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,15 @@ require 'rubygems' +require 'rspec' require File.join(File.dirname(__FILE__), '..', "lib", "ruby_bosh") -require 'spec' + +RSpec.configure do |config| + + config.expect_with :rspec do |c| + c.syntax = :should + end + config.mock_with :rspec do |c| + c.syntax = :should + end + +end From 6717356ecacd5a4320ec60fefc925c2be7572e3f Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 27 Jul 2016 15:25:43 -0700 Subject: [PATCH 2/9] renaming gem and bumping version --- ruby_bosh.gemspec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ruby_bosh.gemspec b/ruby_bosh.gemspec index f7ed7b0..9bf044a 100644 --- a/ruby_bosh.gemspec +++ b/ruby_bosh.gemspec @@ -1,12 +1,12 @@ Gem::Specification.new do |s| - s.name = "ruby_bosh" - s.version = "0.12" + s.name = "mikemarsian-ruby_bosh" + s.version = "0.13" s.require_paths = ["lib"] s.authors = ["Original author: Pradeep Elankumaran. Update for ruby 2: Mike Polischuk"] - s.date = "2016-06-13" + s.date = "2016-07-27" s.description = "An XMPP BOSH session pre-initializer for Ruby web applications" - s.email = "pradeepe@gmail.com" + s.email = "mike@polischuk.com" s.extra_rdoc_files = [ "LICENSE", "README", From 212e10cfb361d841778dfea0186a273403f72692 Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 27 Jul 2016 15:39:23 -0700 Subject: [PATCH 3/9] documentation updates --- .gitignore | 3 ++- LICENSE | 3 ++- README | 14 +++++++------- TODO | 2 -- VERSION.yml | 5 ----- ruby_bosh.gemspec | 9 +++------ 6 files changed, 14 insertions(+), 22 deletions(-) delete mode 100644 TODO delete mode 100644 VERSION.yml diff --git a/.gitignore b/.gitignore index 2677903..9c78f29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.sw? .DS_Store coverage -.idea \ No newline at end of file +.idea +pkg \ No newline at end of file diff --git a/LICENSE b/LICENSE index eeab8d6..8835b16 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,5 @@ -Copyright (c) 2008 Pradeep Elankumaran +Copyright (c) 2008 Pradeep Elankumaran. +Copyright (c) 2016 Mike Polischuk. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README b/README index f322cc5..65ed519 100644 --- a/README +++ b/README @@ -1,19 +1,18 @@ -ruby_bosh -========= +# RubyBosh The RubyBOSH library handles creating and pre-authenticating BOSH streams inside your Ruby application before passing them off to your template engine. This method allows you to hide authentication details for your users' XMPP accounts. -Tested on Rails 2.x with eJabberd 1.2+ +Tested on Rails 4.2, Ruby 2.1.2 with eJabberd 16.04 + +## References -References -========== BOSH: http://xmpp.org/extensions/xep-0124.html XMPP via BOSH: http://xmpp.org/extensions/xep-0206.html -Example -======= +## Example + In your Ruby app controller (or equivalent): @session_jid, @session_id, @session_random_id = @@ -41,3 +40,4 @@ Jack Moffit #=> http://metajack.im/2008/10/03/getting-attached-to-strophe/ Copyright (c) 2008 Pradeep Elankumaran. See LICENSE for details. +Copyright (c) 2016 Mike Polischuk. See LICENSE for details. diff --git a/TODO b/TODO deleted file mode 100644 index 7902d01..0000000 --- a/TODO +++ /dev/null @@ -1,2 +0,0 @@ -write basic tests - diff --git a/VERSION.yml b/VERSION.yml deleted file mode 100644 index c149eb9..0000000 --- a/VERSION.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -:major: 0 -:minor: 11 -:patch: 0 -:build: diff --git a/ruby_bosh.gemspec b/ruby_bosh.gemspec index 9bf044a..06639e9 100644 --- a/ruby_bosh.gemspec +++ b/ruby_bosh.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "mikemarsian-ruby_bosh" - s.version = "0.13" + s.version = "0.13.1" s.require_paths = ["lib"] s.authors = ["Original author: Pradeep Elankumaran. Update for ruby 2: Mike Polischuk"] @@ -9,16 +9,13 @@ Gem::Specification.new do |s| s.email = "mike@polischuk.com" s.extra_rdoc_files = [ "LICENSE", - "README", - "TODO" + "README" ] s.licenses = ['MIT'] s.files = [ "LICENSE", "README", "Rakefile", - "TODO", - "VERSION.yml", "autotest/discover.rb", "lib/ruby_bosh.rb", "ruby_bosh.gemspec", @@ -27,7 +24,7 @@ Gem::Specification.new do |s| ] s.test_files = s.files.grep(%r{^(test|spec|features)/}) s.homepage = "http://github.com/mikemarsian/ruby_bosh" - s.summary = "A BOSH session pre-initializer for Ruby web applications (for Ruby 2)" + s.summary = "A BOSH session pre-initializer for Ruby web applications (for Ruby 2+)" s.required_ruby_version = '>= 1.9.3' s.add_development_dependency "bundler", "~> 1.10" From 68d95ef3371b602763f57176f02aaf0fa36e873b Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 27 Jul 2016 15:42:29 -0700 Subject: [PATCH 4/9] readme file rename --- README => README.md | 0 ruby_bosh.gemspec | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) rename README => README.md (100%) diff --git a/README b/README.md similarity index 100% rename from README rename to README.md diff --git a/ruby_bosh.gemspec b/ruby_bosh.gemspec index 06639e9..fd0f8a8 100644 --- a/ruby_bosh.gemspec +++ b/ruby_bosh.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "mikemarsian-ruby_bosh" - s.version = "0.13.1" + s.version = "0.13.2" s.require_paths = ["lib"] s.authors = ["Original author: Pradeep Elankumaran. Update for ruby 2: Mike Polischuk"] @@ -9,12 +9,12 @@ Gem::Specification.new do |s| s.email = "mike@polischuk.com" s.extra_rdoc_files = [ "LICENSE", - "README" + "README.md" ] s.licenses = ['MIT'] s.files = [ "LICENSE", - "README", + "README.md", "Rakefile", "autotest/discover.rb", "lib/ruby_bosh.rb", From 3753e91a058ec9d6587f46273a81504caa929a3e Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 27 Jul 2016 15:48:30 -0700 Subject: [PATCH 5/9] updating Readme --- README.md | 19 +++++++++++++------ ruby_bosh.gemspec | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 65ed519..38dab6e 100644 --- a/README.md +++ b/README.md @@ -15,29 +15,36 @@ XMPP via BOSH: http://xmpp.org/extensions/xep-0206.html In your Ruby app controller (or equivalent): +```ruby @session_jid, @session_id, @session_random_id = RubyBOSH.initialize_session("me@jabber.org", "my_password", "http://localhost:5280/http-bind") +``` If you want to define your own resource name, include it within the jid. RubyBOSH will create a random one if none is supplied. To define a resource name of 'home', do the following: +```ruby @session_jid, @session_id, @session_random_id = RubyBOSH.initialize_session("me@jabber.org/home", "my_password", "http://localhost:5280/http-bind") +``` In your template, you would then pass these directly to your javascript BOSH connector: +``` erb var bosh_jid = '<%= @session_jid %>'; var bosh_sid = '<%= @session_id %>'; var bosh_rid = '<%= @session_random_id %>'; +``` +``` js // using Strophe: -connect.attach(bosh_jid, bosh_sid, bosh_rid, onConnectHandlerFunction); +connect.attach(bosh_jid, bosh_sid, bosh_rid, onConnectHandlerFunction); +``` -Acknowledgements -================ -Jack Moffit -- thanks for the nice Django example :) -#=> http://metajack.im/2008/10/03/getting-attached-to-strophe/ +## Acknowledgements + +Jack Moffit - thanks for the [nice Django example](http://metajack.im/2008/10/03/getting-attached-to-strophe/) Copyright (c) 2008 Pradeep Elankumaran. See LICENSE for details. + Copyright (c) 2016 Mike Polischuk. See LICENSE for details. diff --git a/ruby_bosh.gemspec b/ruby_bosh.gemspec index fd0f8a8..190836f 100644 --- a/ruby_bosh.gemspec +++ b/ruby_bosh.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "mikemarsian-ruby_bosh" - s.version = "0.13.2" + s.version = "0.13.3" s.require_paths = ["lib"] s.authors = ["Original author: Pradeep Elankumaran. Update for ruby 2: Mike Polischuk"] From 09f054e21df44f081d1d8dc3b18f9345c9d615a3 Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 27 Jul 2016 15:54:33 -0700 Subject: [PATCH 6/9] added ConverseJS example --- README.md | 7 +++++++ ruby_bosh.gemspec | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 38dab6e..2fa109b 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Tested on Rails 4.2, Ruby 2.1.2 with eJabberd 16.04 ## References BOSH: http://xmpp.org/extensions/xep-0124.html + XMPP via BOSH: http://xmpp.org/extensions/xep-0206.html ## Example @@ -39,6 +40,12 @@ var bosh_rid = '<%= @session_random_id %>'; ``` js // using Strophe: connect.attach(bosh_jid, bosh_sid, bosh_rid, onConnectHandlerFunction); + +// using ConverseJS: +converse.initialize({ + jid: bosh_jid, sid: bosh_sid, rid: bosh_rid + // ... the rest of the initialization data + }) ``` ## Acknowledgements diff --git a/ruby_bosh.gemspec b/ruby_bosh.gemspec index 190836f..265eb8b 100644 --- a/ruby_bosh.gemspec +++ b/ruby_bosh.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "mikemarsian-ruby_bosh" - s.version = "0.13.3" + s.version = "0.13.4" s.require_paths = ["lib"] s.authors = ["Original author: Pradeep Elankumaran. Update for ruby 2: Mike Polischuk"] From 39b219991a581832e530bfc18daf0c50a08a8577 Mon Sep 17 00:00:00 2001 From: Austin Matzko Date: Wed, 26 Apr 2017 16:50:55 -0400 Subject: [PATCH 7/9] Remove deprecated use of "Fixnum" --- spec/ruby_bosh_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/ruby_bosh_spec.rb b/spec/ruby_bosh_spec.rb index 3a05f51..f600800 100644 --- a/spec/ruby_bosh_spec.rb +++ b/spec/ruby_bosh_spec.rb @@ -29,7 +29,7 @@ s.should be_kind_of(Array) s.size.should == 3 s.first.should == 'skyfallsin@localhost' - s.last.should be_kind_of(Fixnum) + s.last.should be_kind_of(Integer) s[1].should == '123456' end From a0e2a4ade744defc8204c724269b4053a4e04457 Mon Sep 17 00:00:00 2001 From: Austin Matzko Date: Wed, 26 Apr 2017 16:53:22 -0400 Subject: [PATCH 8/9] Allow later versions of rest-client --- ruby_bosh.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby_bosh.gemspec b/ruby_bosh.gemspec index 265eb8b..8ba2ce7 100644 --- a/ruby_bosh.gemspec +++ b/ruby_bosh.gemspec @@ -33,7 +33,7 @@ Gem::Specification.new do |s| s.add_development_dependency "rspec_junit_formatter", '0.2.2' s.add_dependency "builder", "~> 3.0" - s.add_dependency "rest-client" , "~> 1.8" + s.add_dependency "rest-client" , ">= 1.8" s.add_dependency "hpricot", "~> 0.8" end From a9fed33ad33cc26a54f01aa8925359a14bd3fd2d Mon Sep 17 00:00:00 2001 From: Mike Date: Tue, 15 May 2018 14:28:39 -0300 Subject: [PATCH 9/9] bumping version after merging pull request --- LICENSE | 2 +- ruby_bosh.gemspec | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LICENSE b/LICENSE index 8835b16..62d5c6d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ Copyright (c) 2008 Pradeep Elankumaran. -Copyright (c) 2016 Mike Polischuk. +Copyright (c) 2018 Mike Polischuk. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/ruby_bosh.gemspec b/ruby_bosh.gemspec index 8ba2ce7..87bf119 100644 --- a/ruby_bosh.gemspec +++ b/ruby_bosh.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "mikemarsian-ruby_bosh" - s.version = "0.13.4" + s.version = "0.13.5" s.require_paths = ["lib"] s.authors = ["Original author: Pradeep Elankumaran. Update for ruby 2: Mike Polischuk"] @@ -23,7 +23,7 @@ Gem::Specification.new do |s| "spec/spec_helper.rb" ] s.test_files = s.files.grep(%r{^(test|spec|features)/}) - s.homepage = "http://github.com/mikemarsian/ruby_bosh" + s.homepage = "https://github.com/mikemarsian/ruby_bosh" s.summary = "A BOSH session pre-initializer for Ruby web applications (for Ruby 2+)" s.required_ruby_version = '>= 1.9.3'