DG MS; added specs for publishing to a hub
This commit is contained in:
parent
6869384732
commit
69477b17f5
4 changed files with 66 additions and 42 deletions
|
|
@ -1,14 +1,14 @@
|
||||||
module Diaspora
|
module Diaspora
|
||||||
module OStatusParser
|
module OStatusParser
|
||||||
def find_hub(xml)
|
def self.find_hub(xml)
|
||||||
Nokogiri::HTML(xml).xpath('//link[@rel="hub"]').first.attribute("href").value
|
Nokogiri::HTML(xml).xpath('//link[@rel="hub"]').first.attribute("href").value
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_sender(xml)
|
def self.parse_sender(xml)
|
||||||
puts xml
|
puts "you just won the game"
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_objects(xml)
|
def self.parse_objects(xml)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
class MessageHandler
|
class MessageHandler
|
||||||
|
|
||||||
|
|
||||||
include Diaspora::OStatusParser
|
|
||||||
NUM_TRIES = 3
|
NUM_TRIES = 3
|
||||||
TIMEOUT = 5 #seconds
|
TIMEOUT = 5 #seconds
|
||||||
|
|
||||||
|
|
@ -19,15 +19,22 @@ class MessageHandler
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_hub_notification(destination, feed_location)
|
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
|
end
|
||||||
|
|
||||||
def add_hub_subscription_request(hub, body)
|
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
|
end
|
||||||
|
|
||||||
def add_subscription_request(feed)
|
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
|
end
|
||||||
|
|
||||||
def process
|
def process
|
||||||
|
|
@ -40,25 +47,16 @@ class MessageHandler
|
||||||
http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT
|
http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT
|
||||||
http.callback {send_to_seed(query, http.response); process}
|
http.callback {send_to_seed(query, http.response); process}
|
||||||
|
|
||||||
when :subscribe
|
when :ostatus_subscribe
|
||||||
puts query.destination
|
puts query.destination
|
||||||
http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT
|
http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT
|
||||||
http.callback {
|
http.callback { process_ostatus_subscription(query, http); process}
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
when :pubhub
|
when :hub_publish
|
||||||
http = EventMachine::PubSubHubbub.new(query.destination).publish query.body, :timeout => TIMEOUT
|
http = EventMachine::PubSubHubbub.new(query.destination).publish query.body, :timeout => TIMEOUT
|
||||||
http.callback { process}
|
http.callback { process}
|
||||||
|
|
||||||
when :pubhubsub
|
when :hub_subscribe
|
||||||
http = EventMachine::PubSubHubbub.new(query.destination).subscribe query.body, User.owner.url, :timeout => TIMEOUT
|
http = EventMachine::PubSubHubbub.new(query.destination).subscribe query.body, User.owner.url, :timeout => TIMEOUT
|
||||||
http.callback { process}
|
http.callback { process}
|
||||||
else
|
else
|
||||||
|
|
@ -84,7 +82,7 @@ class MessageHandler
|
||||||
end
|
end
|
||||||
|
|
||||||
class Message
|
class Message
|
||||||
attr_accessor :type, :destination, :body, :try_count
|
attr_accessor :type, :destination, :body, :callback, :try_count
|
||||||
def initialize(type, dest, opts = {})
|
def initialize(type, dest, opts = {})
|
||||||
@type = type
|
@type = type
|
||||||
@destination = dest
|
@destination = dest
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,52 @@ describe MessageHandler do
|
||||||
|
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
class FakeHttpRequest
|
class FakeHttpRequest
|
||||||
|
|
|
||||||
|
|
@ -46,24 +46,4 @@ describe User do
|
||||||
user.terse_url.should == 'example.com'
|
user.terse_url.should == 'example.com'
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue