diff --git a/lib/common.rb b/lib/common.rb index ed4c98104..a4bb19717 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -1,14 +1,14 @@ module Diaspora module OStatusParser - def find_hub(xml) + def self.find_hub(xml) Nokogiri::HTML(xml).xpath('//link[@rel="hub"]').first.attribute("href").value end - def parse_sender(xml) - puts xml + def self.parse_sender(xml) + puts "you just won the game" end - def parse_objects(xml) + def self.parse_objects(xml) end end diff --git a/lib/message_handler.rb b/lib/message_handler.rb index 8e6bff9a2..0bed47b4f 100644 --- a/lib/message_handler.rb +++ b/lib/message_handler.rb @@ -1,6 +1,6 @@ class MessageHandler + - include Diaspora::OStatusParser NUM_TRIES = 3 TIMEOUT = 5 #seconds @@ -19,15 +19,22 @@ class MessageHandler end def add_hub_notification(destination, feed_location) - @queue.push(Message.new(:pubhub, destination, :body => feed_location)) + @queue.push(Message.new(:hub_publish, destination, :body => feed_location)) end def add_hub_subscription_request(hub, body) - @queue.push(Message.new(:pubhubsub, hub, :body => body)) + @queue.push(Message.new(:hub_subscribe, hub, :body => body)) end def add_subscription_request(feed) - @queue.push(Message.new(:subscribe, feed)) + @queue.push(Message.new(:ostatus_subscribe, feed)) + end + + + def process_ostatus_subscription(query_object, http) + hub = Diaspora::OStatusParser::find_hub(http.response) + add_hub_subscription_request(hub, query_object.destination) + Diaspora::OStatusParser::parse_sender(http.response) end def process @@ -40,25 +47,16 @@ class MessageHandler http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT http.callback {send_to_seed(query, http.response); process} - when :subscribe + when :ostatus_subscribe puts query.destination http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT - http.callback { - require 'lib/common' - puts http.response - hub = Nokogiri::HTML(http.response).xpath('//link[@rel="hub"]').first.attribute("href").value - - add_hub_subscription_request(hub, query.destination) - #Diaspora::OStatus::parse_sender(http.response) - - process - } + http.callback { process_ostatus_subscription(query, http); process} - when :pubhub + when :hub_publish http = EventMachine::PubSubHubbub.new(query.destination).publish query.body, :timeout => TIMEOUT http.callback { process} - when :pubhubsub + when :hub_subscribe http = EventMachine::PubSubHubbub.new(query.destination).subscribe query.body, User.owner.url, :timeout => TIMEOUT http.callback { process} else @@ -84,7 +82,7 @@ class MessageHandler end class Message - attr_accessor :type, :destination, :body, :try_count + attr_accessor :type, :destination, :body, :callback, :try_count def initialize(type, dest, opts = {}) @type = type @destination = dest diff --git a/spec/lib/message_handler_spec.rb b/spec/lib/message_handler_spec.rb index 553135b96..3e887e1a2 100644 --- a/spec/lib/message_handler_spec.rb +++ b/spec/lib/message_handler_spec.rb @@ -131,6 +131,52 @@ describe MessageHandler do end end + + describe 'ostatus_subscribe' do + + end + + describe 'hub_publish' do + + + it 'should correctly queue up a pubsubhub publish request' do + destination = "http://identi.ca/hub/" + feed_location = "http://google.com/" + + EventMachine.run { + @handler.add_hub_notification(destination, feed_location) + q = @handler.instance_variable_get(:@queue) + + message = "" + q.pop{|m| message = m} + + message.destination.should == destination + message.body.should == feed_location + + EventMachine.stop + } + end + + it 'should notify the hub about new content' do + request = FakeHttpRequest.new(:success) + request.should_receive(:publish).exactly(1).times.and_return(request) + EventMachine::PubSubHubbub.stub!(:new).and_return(request) + + EventMachine.run { + @handler.add_hub_notification("http://identi.ca/hub", "http://google.com/feed") + @handler.size.should == 1 + @handler.process + @handler.size.should == 0 + EventMachine.stop + } + end + + end + + describe 'hub_subscribe' do + + end + end class FakeHttpRequest diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 10ed630b1..3ad53ceed 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -46,24 +46,4 @@ describe User do user.terse_url.should == 'example.com' end - - it 'should subscribe to a status.net user' do - @user = Factory.create(:user) - @user.request_connection - - - #@user.send_friend_request(url) - @user.send_subscription(url) - get stream <== schedule async get :inquire_subscription - { - parse out hub - subscribe to hub => s - parse_profile - parse_messages - - } - end - end -=end - end