From 965be632fc5c6c09bb213cf0cdeeaacf37f62820 Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Thu, 6 Nov 2014 23:37:09 -0200 Subject: [PATCH] Drop and replace hpricot with nokogiri --- Gemfile | 1 - INSTALL.md | 3 +-- app/helpers/application_helper.rb | 6 +++--- app/models/article.rb | 11 +++++------ app/models/external_feed.rb | 14 +++++++------- app/models/forum.rb | 2 +- app/models/text_article.rb | 10 +++++----- debian/control | 1 - lib/noosfero/plugin/macro.rb | 2 +- plugins/comment_group/lib/ext/article.rb | 2 +- plugins/community_track/lib/community_track_plugin/track.rb | 2 +- script/install-dependencies/debian-squeeze.sh | 2 +- test/functional/cms_controller_test.rb | 4 ++-- test/functional/profile_editor_controller_test.rb | 2 +- test/test_helper.rb | 1 - test/unit/application_helper_test.rb | 18 +++++++++--------- test/unit/comment_helper_test.rb | 2 +- test/unit/external_feed_test.rb | 2 +- test/unit/macro_test.rb | 2 +- test/unit/text_article_test.rb | 23 +++++++++++------------ vendor/cardmagic-contacts-f66219e6589ccaf3ab9e3574fdd41225d0dd5073/lib/contacts/aol.rb | 39 +++++++++++++++++++-------------------- vendor/plugins/ruby_bosh/Rakefile | 2 +- vendor/plugins/ruby_bosh/lib/ruby_bosh.rb | 38 +++++++++++++++++++------------------- vendor/plugins/ruby_bosh/ruby_bosh.gemspec | 3 --- 24 files changed, 91 insertions(+), 101 deletions(-) diff --git a/Gemfile b/Gemfile index 9990816..05a218e 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,6 @@ gem 'will_paginate', '~> 3.0.3' gem 'ruby-feedparser', '~> 0.7' gem 'daemons', '~> 1.1.5' gem 'thin', '~> 1.3.1' -gem 'hpricot', '~> 0.8.6' gem 'nokogiri', '~> 1.5.5' gem 'rake', :require => false gem 'rest-client', '~> 1.6.7' diff --git a/INSTALL.md b/INSTALL.md index d5b04a2..64ef642 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -21,7 +21,7 @@ Noosfero is written in Ruby with the "[Rails framework](http://www.rubyonrails.o You need to install some packages Noosfero depends on. On Debian GNU/Linux or Debian-based systems, all of these packages are available through the Debian archive. You can install them with the following command: # apt-get install ruby rake po4a libgettext-ruby-util libgettext-ruby1.8 \ - libsqlite3-ruby rcov librmagick-ruby libredcloth-ruby libhpricot-ruby \ + libsqlite3-ruby rcov librmagick-ruby libredcloth-ruby \ libwill-paginate-ruby iso-codes libfeedparser-ruby libdaemons-ruby thin \ tango-icon-theme @@ -40,7 +40,6 @@ On other systems, they may or may not be available through your regular package * Daemons - http://daemons.rubyforge.org * Thin: http://code.macournoyer.com/thin * tango-icon-theme: http://tango.freedesktop.org/Tango_Icon_Library -* Hpricot: http://hpricot.com If you manage to install Noosfero successfully on other systems than Debian, please feel free to contact the Noosfero development mailing with the diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7eb9808..05bf735 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1394,16 +1394,16 @@ module ApplicationHelper end def convert_macro(html, source) - doc = Hpricot(html) + doc = Nokogiri::HTML.fragment html #TODO This way is more efficient but do not support macro inside of # macro. You must parse them from the inside-out in order to enable # that. - doc.search('.macro').each do |macro| + doc.css('.macro').each do |macro| macro_name = macro['data-macro'] result = @plugins.parse_macro(macro_name, macro, source) macro.inner_html = result.kind_of?(Proc) ? self.instance_exec(&result) : result end - doc.html + doc.to_html end def default_folder_for_image_upload(profile) diff --git a/app/models/article.rb b/app/models/article.rb index 7b13218..f7b5974 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -1,4 +1,3 @@ -require 'hpricot' class Article < ActiveRecord::Base @@ -707,7 +706,7 @@ class Article < ActiveRecord::Base end def first_paragraph - paragraphs = Hpricot(to_html).search('p') + paragraphs = Nokogiri::HTML.fragment(to_html).css('p') paragraphs.empty? ? '' : paragraphs.first.to_html end @@ -729,8 +728,8 @@ class Article < ActiveRecord::Base def body_images_paths require 'uri' - Hpricot(self.body.to_s).search('img[@src]').collect do |i| - (self.profile && self.profile.environment) ? URI.join(self.profile.environment.top_url, URI.escape(i.attributes['src'])).to_s : i.attributes['src'] + Nokogiri::HTML.fragment(self.body.to_s).css('img[src]').collect do |i| + (self.profile && self.profile.environment) ? URI.join(self.profile.environment.top_url, URI.escape(i['src'])).to_s : i['src'] end end @@ -767,8 +766,8 @@ class Article < ActiveRecord::Base end def first_image - img = Hpricot(self.lead.to_s).search('img[@src]').first || Hpricot(self.body.to_s).search('img').first - img.nil? ? '' : img.attributes['src'] + img = Nokogiri::HTML.fragment(self.lead.to_s).css('img[src]').first || Nokogiri::HTML.fragment(self.body.to_s).search('img').first + img.nil? ? '' : img['src'] end delegate :lat, :lng, :region, :region_id, :environment, :environment_id, :to => :profile, :allow_nil => true diff --git a/app/models/external_feed.rb b/app/models/external_feed.rb index 40f018a..2220262 100644 --- a/app/models/external_feed.rb +++ b/app/models/external_feed.rb @@ -14,9 +14,9 @@ class ExternalFeed < ActiveRecord::Base def add_item(title, link, date, content) return if content.blank? - doc = Hpricot(content) - doc.search('*').each do |p| - if p.instance_of? Hpricot::Elem + doc = Nokogiri::HTML.fragment content + doc.css('*').each do |p| + if p.instance_of? Nokogiri::XML::Element p.remove_attribute 'style' p.remove_attribute 'class' end @@ -26,10 +26,10 @@ class ExternalFeed < ActiveRecord::Base article = TinyMceArticle.new article.name = title article.profile = blog.profile - article.body = content - article.published_at = date - article.source = link - article.profile = blog.profile + article.body = content + article.published_at = date + article.source = link + article.profile = blog.profile article.parent = blog article.author_name = self.feed_title unless blog.children.exists?(:slug => article.slug) diff --git a/app/models/forum.rb b/app/models/forum.rb index f6a7eb1..a6c1e3a 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -54,7 +54,7 @@ class Forum < Folder def first_paragraph return '' if body.blank? - paragraphs = Hpricot(body).search('p') + paragraphs = Nokogiri::HTML.fragment(body).css('p') paragraphs.empty? ? '' : paragraphs.first.to_html end diff --git a/app/models/text_article.rb b/app/models/text_article.rb index 5e774dc..66dbe9f 100644 --- a/app/models/text_article.rb +++ b/app/models/text_article.rb @@ -1,6 +1,6 @@ require 'noosfero/translatable_content' -# a base class for all text article types. +# a base class for all text article types. class TextArticle < Article xss_terminate :only => [ :name ], :on => 'validation' @@ -26,10 +26,10 @@ class TextArticle < Article before_save :set_relative_path def set_relative_path - parsed = Hpricot(self.body.to_s) - parsed.search('img[@src]').map { |i| change_element_path(i, 'src') } - parsed.search('a[@href]').map { |i| change_element_path(i, 'href') } - self.body = parsed.to_s + parsed = Nokogiri::HTML.fragment(self.body.to_s) + parsed.css('img[src]').each { |i| change_element_path(i, 'src') } + parsed.css('a[href]').each { |i| change_element_path(i, 'href') } + self.body = parsed.to_html end def change_element_path(el, attribute) diff --git a/debian/control b/debian/control index a88b378..a586141 100644 --- a/debian/control +++ b/debian/control @@ -48,7 +48,6 @@ Depends: adduser, ruby-feedparser, ruby-feedparser (>= 0.7-3~), ruby-gettext, - ruby-hpricot, ruby-memcache-client, ruby-minitest, ruby-nokogiri, diff --git a/lib/noosfero/plugin/macro.rb b/lib/noosfero/plugin/macro.rb index 1fdeb09..b459a9d 100644 --- a/lib/noosfero/plugin/macro.rb +++ b/lib/noosfero/plugin/macro.rb @@ -35,7 +35,7 @@ class Noosfero::Plugin::Macro def attributes(macro) macro.attributes.to_hash. select {|key, value| key[0..10] == 'data-macro-'}. - inject({}){|result, a| result.merge({a[0][11..-1] => a[1]})}. + inject({}){|result, a| result.merge({a[0][11..-1] => a[1].to_s})}. with_indifferent_access end diff --git a/plugins/comment_group/lib/ext/article.rb b/plugins/comment_group/lib/ext/article.rb index 1cde990..c532621 100644 --- a/plugins/comment_group/lib/ext/article.rb +++ b/plugins/comment_group/lib/ext/article.rb @@ -9,7 +9,7 @@ class Article def not_empty_group_comments_removed if body && body_changed? groups_with_comments = Comment.find(:all, :select => 'distinct group_id', :conditions => {:source_id => self.id}).map(&:group_id).compact - groups = Hpricot(body.to_s).search('.macro').collect{|element| element['data-macro-group_id'].to_i} + groups = Nokogiri::HTML.fragment(body.to_s).css('.macro').collect{|element| element['data-macro-group_id'].to_i} errors[:base] << (N_('Not empty group comment cannot be removed')) unless (groups_with_comments-groups).empty? end end diff --git a/plugins/community_track/lib/community_track_plugin/track.rb b/plugins/community_track/lib/community_track_plugin/track.rb index 4aa1d7c..7f56570 100644 --- a/plugins/community_track/lib/community_track_plugin/track.rb +++ b/plugins/community_track/lib/community_track_plugin/track.rb @@ -59,7 +59,7 @@ class CommunityTrackPlugin::Track < Folder def first_paragraph return '' if body.blank? - paragraphs = Hpricot(body).search('p') + paragraphs = Nokogiri::HTML.fragment(body).css('p') paragraphs.empty? ? '' : paragraphs.first.to_html end diff --git a/script/install-dependencies/debian-squeeze.sh b/script/install-dependencies/debian-squeeze.sh index fd2b100..02b5470 100644 --- a/script/install-dependencies/debian-squeeze.sh +++ b/script/install-dependencies/debian-squeeze.sh @@ -5,7 +5,7 @@ run sudo apt-get -y install $runtime_dependencies sudo apt-get -y install iceweasel || sudo apt-get -y install firefox # needed for development -run sudo apt-get -y install libtidy-ruby libhpricot-ruby libmocha-ruby imagemagick po4a xvfb libxml2-dev libxslt-dev postgresql openjdk-6-jre +run sudo apt-get -y install libtidy-ruby libmocha-ruby imagemagick po4a xvfb libxml2-dev libxslt-dev postgresql openjdk-6-jre gem which bundler >/dev/null 2>&1 || gem_install bundler setup_rubygems_path run bundle install diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 92f1298..81b67c2 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -663,8 +663,8 @@ class CmsControllerTest < ActionController::TestCase should 'be able to add image with alignment' do post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'image-alignment', :body => "the text of the article with image right align..." } saved = TinyMceArticle.find_by_name('image-alignment') - assert_match //, saved.body - assert_match //, saved.body + assert_match //, saved.body + assert_match //, saved.body end should 'be able to add image with alignment when textile' do diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index 41ec6d0..69cc7f8 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -500,7 +500,7 @@ class ProfileEditorControllerTest < ActionController::TestCase xhr :get, :update_categories, :profile => profile.identifier, :category_id => top.id assert_template 'shared/update_categories' assert_equal top, assigns(:current_category) - assert_equal [c1, c2], assigns(:categories) + assert_equivalent [c1, c2], assigns(:categories) end should 'display manage my groups button for person' do diff --git a/test/test_helper.rb b/test/test_helper.rb index 533299b..132349e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -3,7 +3,6 @@ ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'rails/test_help' require 'mocha' -require 'hpricot' require 'noosfero/test' require 'authenticated_test_helper' diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index 9bc2f95..cb5e63b 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -261,7 +261,7 @@ class ApplicationHelperTest < ActionView::TestCase fast_create(Community, :is_template => true, :environment_id => environment.id) environment.community_default_template= community environment.save - + assert_tag_in_string template_options(:communities, 'community'), :tag => 'input', :attributes => { :name => "community[template_id]", :value => community.id, :checked => true } end @@ -273,7 +273,7 @@ class ApplicationHelperTest < ActionView::TestCase fast_create(Person, :is_template => true, :environment_id => environment.id) environment.person_default_template= person environment.save - + assert_tag_in_string template_options(:people, 'profile_data'), :tag => 'input', :attributes => { :name => "profile_data[template_id]", :value => person.id, :checked => true } end @@ -287,7 +287,7 @@ class ApplicationHelperTest < ActionView::TestCase environment.enterprise_default_template= enterprise environment.save environment.reload - + assert_tag_in_string template_options(:enterprises, 'create_enterprise'), :tag => 'input', :attributes => { :name => "create_enterprise[template_id]", :value => enterprise.id, :checked => true } end @@ -734,16 +734,16 @@ class ApplicationHelperTest < ActionView::TestCase
" parsed_html = convert_macro(html, mock()) - parsed_divs = Hpricot(parsed_html).search('div') - expected_divs = Hpricot(" -
Test1
-
Test2
+ parsed_divs = Nokogiri::HTML.fragment(parsed_html).css('div') + expected_divs = Nokogiri::HTML.fragment(" +
Test1
+
Test2
Unsupported macro unexistent!
- ").search('div') + ").css('div') # comparing div attributes between parsed and expected html parsed_divs.each_with_index do |div, i| - assert_equal expected_divs[i].attributes.to_hash, div.attributes.to_hash + assert_equal expected_divs[i].attributes.to_xml, div.attributes.to_xml assert_equal expected_divs[i].inner_text, div.inner_text end end diff --git a/test/unit/comment_helper_test.rb b/test/unit/comment_helper_test.rb index 91c3200..d24591c 100644 --- a/test/unit/comment_helper_test.rb +++ b/test/unit/comment_helper_test.rb @@ -137,7 +137,7 @@ class CommentHelperTest < ActiveSupport::TestCase plugin_action = {:link => 'plugin_action', :action_bar => true} @plugins.stubs(:dispatch).returns([plugin_action]) html = comment_actions(comment) - assert_match /plugin_action/, Hpricot(html).search('.comments-action-bar').html + assert_match /plugin_action/, Nokogiri::HTML.fragment(html).css('.comments-action-bar').to_html end def link_to_function(content, url, options = {}) diff --git a/test/unit/external_feed_test.rb b/test/unit/external_feed_test.rb index f6e299d..9375a06 100644 --- a/test/unit/external_feed_test.rb +++ b/test/unit/external_feed_test.rb @@ -166,7 +166,7 @@ class ExternalFeedTest < ActiveSupport::TestCase next if a.kind_of?(RssFeed) dd << a.body.to_s.strip.gsub(/\s+/, ' ') end - assert_equal '

Html content 1.

Html content 2.

', dd.sort.join + assert_equal '

Html content 1.

Html content 2.

', dd.sort.join end should 'use feed title as author name' do diff --git a/test/unit/macro_test.rb b/test/unit/macro_test.rb index 647f551..6d60534 100644 --- a/test/unit/macro_test.rb +++ b/test/unit/macro_test.rb @@ -15,7 +15,7 @@ class MacroTest < ActiveSupport::TestCase def setup @macro = Plugin1::Macro.new - @macro_element = Hpricot(MACRO).search('.macro').first + @macro_element = Nokogiri::HTML.fragment(MACRO).css('.macro').first end attr_reader :macro, :macro_element diff --git a/test/unit/text_article_test.rb b/test/unit/text_article_test.rb index a3f9149..500acb8 100644 --- a/test/unit/text_article_test.rb +++ b/test/unit/text_article_test.rb @@ -1,9 +1,9 @@ require_relative "../test_helper" class TextArticleTest < ActiveSupport::TestCase - + # mostly dummy test. Can be removed when (if) there are real tests for this - # this class. + # this class. should 'inherit from Article' do assert_kind_of Article, TextArticle.new end @@ -44,7 +44,7 @@ class TextArticleTest < ActiveSupport::TestCase env = Environment.default article.body = "" article.save! - assert_equal "", article.body + assert_equal "", article.body end should 'change link to relative path' do @@ -60,18 +60,18 @@ class TextArticleTest < ActiveSupport::TestCase person = create_user('testuser').person article = TextArticle.new(:profile => person, :name => 'test') env = Environment.default - article.body = "" + article.body = "" article.save! - assert_equal "", article.body + assert_equal "", article.body end should 'change image path to relative for domain with port' do person = create_user('testuser').person article = TextArticle.new(:profile => person, :name => 'test') env = Environment.default - article.body = "" + article.body = "" article.save! - assert_equal "", article.body + assert_equal "", article.body end should 'change image path to relative for domain with www' do @@ -80,16 +80,16 @@ class TextArticleTest < ActiveSupport::TestCase env = Environment.default env.force_www = true env.save! - article.body = "" + article.body = "" article.save! - assert_equal "", article.body + assert_equal "", article.body end should 'not be translatable if there is no language available on environment' do environment = fast_create(Environment) environment.languages = nil profile = fast_create(Person, :environment_id => environment.id) - + text = TextArticle.new(:profile => profile) assert !text.translatable? @@ -102,11 +102,10 @@ class TextArticleTest < ActiveSupport::TestCase text = fast_create(TextArticle, :profile_id => profile.id) assert !text.translatable? - environment.languages = ['en','pt','fr'] environment.save - text.reload + text.reload assert text.translatable? end diff --git a/vendor/cardmagic-contacts-f66219e6589ccaf3ab9e3574fdd41225d0dd5073/lib/contacts/aol.rb b/vendor/cardmagic-contacts-f66219e6589ccaf3ab9e3574fdd41225d0dd5073/lib/contacts/aol.rb index 27eddcb..fb0f91d 100644 --- a/vendor/cardmagic-contacts-f66219e6589ccaf3ab9e3574fdd41225d0dd5073/lib/contacts/aol.rb +++ b/vendor/cardmagic-contacts-f66219e6589ccaf3ab9e3574fdd41225d0dd5073/lib/contacts/aol.rb @@ -8,20 +8,19 @@ class Hash end class Contacts - require 'hpricot' class Aol < Base URL = "http://www.aol.com/" LOGIN_URL = "https://my.screenname.aol.com/_cqr/login/login.psp" LOGIN_REFERER_URL = "http://webmail.aol.com/" LOGIN_REFERER_PATH = "sitedomain=sns.webmail.aol.com&lang=en&locale=us&authLev=0&uitype=mini&loginId=&redirType=js&xchk=false" AOL_NUM = "29970-343" # this seems to change each time they change the protocol - + CONTACT_LIST_URL = "http://webmail.aol.com/#{AOL_NUM}/aim-2/en-us/Lite/ContactList.aspx?folder=Inbox&showUserFolders=False" CONTACT_LIST_CSV_URL = "http://webmail.aol.com/#{AOL_NUM}/aim-2/en-us/Lite/ABExport.aspx?command=all" PROTOCOL_ERROR = "AOL has changed its protocols, please upgrade this library first. If that does not work, dive into the code and submit a patch at http://github.com/cardmagic/contacts" - + def real_connect - + postdata = { "loginId" => login, "password" => password, @@ -62,15 +61,15 @@ class Contacts until forward.nil? data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward] end - + data, resp, cookies, forward, old_url = get("#{LOGIN_URL}?#{LOGIN_REFERER_PATH}", cookies) + [LOGIN_REFERER_URL] until forward.nil? data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward] end - doc = Hpricot(data) - (doc/:input).each do |input| - postdata["usrd"] = input.attributes["value"] if input.attributes["name"] == "usrd" + doc = Nokogiri::HTML.fragment data + doc.css('input').each do |input| + postdata["usrd"] = input["value"] if input["name"] == "usrd" end # parse data for and add it to the postdata @@ -78,13 +77,13 @@ class Contacts postdata["SNS_LDC"] = cookie_hash_from_string(cookies)["SNS_LDC"] postdata["LTState"] = cookie_hash_from_string(cookies)["LTState"] # raise data.inspect - + data, resp, cookies, forward, old_url = post(LOGIN_URL, postdata.to_query_string, cookies, LOGIN_REFERER_URL) + [LOGIN_REFERER_URL] - + until forward.nil? data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward] end - + if data.index("Invalid Screen Name or Password.") raise AuthenticationError, "Username and password do not match" elsif data.index("Required field must not be blank") @@ -113,19 +112,19 @@ class Contacts until forward.nil? data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward] end - + if resp.code_type != Net::HTTPOK raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR) end # parse data and grab - doc = Hpricot(data) - (doc/:input).each do |input| - postdata["user"] = input.attributes["value"] if input.attributes["name"] == "user" + doc = Nokogiri::HTML.fragment data + doc.css('input').each do |input| + postdata["user"] = input["value"] if input["name"] == "user" end - + data, resp, cookies, forward, old_url = get(CONTACT_LIST_CSV_URL, @cookies, CONTACT_LIST_URL) + [CONTACT_LIST_URL] - + if forward.nil? parse data else @@ -134,15 +133,15 @@ class Contacts end end private - + def parse(data, options={}) data = CSV.parse(data) col_names = data.shift @contacts = data.map do |person| ["#{person[0]} #{person[1]}", person[4]] unless person[4].empty? end.compact - end + end end TYPES[:aol] = Aol -end \ No newline at end of file +end diff --git a/vendor/plugins/ruby_bosh/Rakefile b/vendor/plugins/ruby_bosh/Rakefile index bfa451c..417877c 100644 --- a/vendor/plugins/ruby_bosh/Rakefile +++ b/vendor/plugins/ruby_bosh/Rakefile @@ -12,7 +12,7 @@ begin s.add_dependency("builder") s.add_dependency("rest-client") - s.add_dependency("hpricot") + s.add_dependency("nokogiri") s.add_dependency("SystemTimer") end rescue LoadError diff --git a/vendor/plugins/ruby_bosh/lib/ruby_bosh.rb b/vendor/plugins/ruby_bosh/lib/ruby_bosh.rb index 401f270..b5cfa23 100644 --- a/vendor/plugins/ruby_bosh/lib/ruby_bosh.rb +++ b/vendor/plugins/ruby_bosh/lib/ruby_bosh.rb @@ -2,10 +2,10 @@ require 'rest_client' require 'builder' require 'rexml/document' require 'base64' -require 'hpricot' +require 'nokogiri' require 'timeout' -class RubyBOSH +class RubyBOSH BOSH_XMLNS = 'http://jabber.org/protocol/httpbind' TLS_XMLNS = 'urn:ietf:params:xml:ns:xmpp-tls' SASL_XMLNS = 'urn:ietf:params:xml:ns:xmpp-sasl' @@ -24,12 +24,12 @@ class RubyBOSH end attr_accessor :jid, :rid, :sid, :success - def initialize(jid, pw, service_url, opts={}) + def initialize(jid, pw, service_url, opts={}) @service_url = service_url @jid, @pw = jid, pw @host = jid.split("@").last @success = false - @timeout = opts[:timeout] || 3 #seconds + @timeout = opts[:timeout] || 3 #seconds @headers = {"Content-Type" => "text/xml; charset=utf-8", "Accept" => "text/xml"} @wait = opts[:wait] || 5 @@ -47,7 +47,7 @@ class RubyBOSH def connect initialize_bosh_session - if send_auth_request + if send_auth_request send_restart_request request_resource_binding @success = send_session_request @@ -55,12 +55,12 @@ class RubyBOSH raise RubyBOSH::AuthFailed, "could not authenticate #{@jid}" unless success? @rid += 1 #updates the rid for the next call from the browser - + [@jid, @sid, @rid] end private - def initialize_bosh_session + def initialize_bosh_session response = deliver(construct_body(:wait => @wait, :to => @host, :hold => @hold, :window => @window, "xmpp:version" => '1.0')) @@ -72,7 +72,7 @@ class RubyBOSH builder = Builder::XmlMarkup.new parameters = {:rid => @rid, :xmlns => BOSH_XMLNS, - "xmpp:version" => "1.0", + "xmpp:version" => "1.0", "xmlns:xmpp" => "urn:xmpp:xbosh"}.merge(params) if block_given? @@ -82,10 +82,10 @@ class RubyBOSH end end - def send_auth_request + def send_auth_request request = construct_body(:sid => @sid) do |body| - auth_string = "#{@jid}\x00#{@jid.split("@").first.strip}\x00#{@pw}" - body.auth(Base64.encode64(auth_string).gsub(/\s/,''), + auth_string = "#{@jid}\x00#{@jid.split("@").first.strip}\x00#{@pw}" + body.auth(Base64.encode64(auth_string).gsub(/\s/,''), :xmlns => SASL_XMLNS, :mechanism => 'PLAIN') end @@ -100,16 +100,16 @@ class RubyBOSH def request_resource_binding request = construct_body(:sid => @sid) do |body| - body.iq(:id => "bind_#{rand(100000)}", :type => "set", + body.iq(:id => "bind_#{rand(100000)}", :type => "set", :xmlns => "jabber:client") do |iq| iq.bind(:xmlns => BIND_XMLNS) do |bind| bind.resource("bosh_#{rand(10000)}") end end end - + response = deliver(request) - response.include?("") + response.include?("") end def send_session_request @@ -117,16 +117,16 @@ class RubyBOSH body.iq(:xmlns => CLIENT_XMLNS, :type => "set", :id => "sess_#{rand(100000)}") do |iq| iq.session(:xmlns => SESSION_XMLNS) - end + end end response = deliver(request) - response.include?("body") + response.include?("body") end def parse(_response) - doc = Hpricot(_response.to_s) - doc.search("//body").each do |body| + doc = Nokogiri::HTML.fragment(_response.to_s) + doc.search("body").each do |body| @sid = body.attributes["sid"].to_s end _response @@ -156,6 +156,6 @@ end if __FILE__ == $0 - p RubyBOSH.initialize_session(ARGV[0], ARGV[1], + p RubyBOSH.initialize_session(ARGV[0], ARGV[1], "http://localhost:5280/http-bind") end diff --git a/vendor/plugins/ruby_bosh/ruby_bosh.gemspec b/vendor/plugins/ruby_bosh/ruby_bosh.gemspec index 012d6ec..8d7fb14 100644 --- a/vendor/plugins/ruby_bosh/ruby_bosh.gemspec +++ b/vendor/plugins/ruby_bosh/ruby_bosh.gemspec @@ -24,18 +24,15 @@ Gem::Specification.new do |s| if Gem::Version.new(Gem::RubyGemsVersion) >= 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"]) s.add_runtime_dependency(%q, [">= 0"]) else s.add_dependency(%q, [">= 0"]) 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"]) s.add_dependency(%q, [">= 0"]) end end -- libgit2 0.21.2