DG MS we now fully parse an ostatus response
This commit is contained in:
parent
82e61ff99d
commit
1118b56bb1
5 changed files with 149 additions and 5 deletions
|
|
@ -4,10 +4,90 @@ module Diaspora
|
||||||
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 self.parse_sender(xml)
|
def self.process(xml)
|
||||||
puts "you just won the game"
|
doc = Nokogiri::HTML(xml)
|
||||||
|
parse_author(doc)
|
||||||
|
puts ""
|
||||||
|
parse_entry(doc)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parse_author(doc)
|
||||||
|
doc = Nokogiri::HTML(doc) if doc.is_a? String
|
||||||
|
|
||||||
|
|
||||||
|
service = parse_service(doc)
|
||||||
|
feed_url = parse_feed_url(doc)
|
||||||
|
avatar_thumbnail = parse_avatar_thumbnail(doc)
|
||||||
|
username = parse_username(doc)
|
||||||
|
profile_url = parse_profile_url(doc)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
puts "the sender:"
|
||||||
|
puts service
|
||||||
|
puts feed_url
|
||||||
|
puts avatar_thumbnail
|
||||||
|
puts username
|
||||||
|
puts profile_url
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_entry(doc)
|
||||||
|
doc = Nokogiri::HTML(doc) if doc.is_a? String
|
||||||
|
|
||||||
|
message = parse_message(doc)
|
||||||
|
permalink = parse_permalink(doc)
|
||||||
|
published_at = parse_published_at(doc)
|
||||||
|
updated_at = parse_updated_at(doc)
|
||||||
|
|
||||||
|
|
||||||
|
puts "the message"
|
||||||
|
puts message
|
||||||
|
puts permalink
|
||||||
|
puts published_at
|
||||||
|
puts updated_at
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
##author###
|
||||||
|
def self.parse_service(doc)
|
||||||
|
doc.xpath('//generator').inner_html
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.parse_feed_url(doc)
|
||||||
|
doc.xpath('//id').first.inner_html
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.parse_avatar_thumbnail(doc)
|
||||||
|
doc.xpath('//logo').first.inner_html
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.parse_username(doc)
|
||||||
|
doc.xpath('//author/name').first.inner_html
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.parse_profile_url(doc)
|
||||||
|
doc.xpath('//author/uri').first.inner_html
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
#entry##
|
||||||
|
def self.parse_message(doc)
|
||||||
|
doc.xpath('//entry/title').first.inner_html
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.parse_permalink(doc)
|
||||||
|
doc.xpath('//entry/id').first.inner_html
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.parse_published_at(doc)
|
||||||
|
doc.xpath('//entry/published').first.inner_html
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.parse_updated_at(doc)
|
||||||
|
doc.xpath('//entry/updated').first.inner_html
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def self.parse_objects(xml)
|
def self.parse_objects(xml)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ class MessageHandler
|
||||||
def process_ostatus_subscription(query_object, http)
|
def process_ostatus_subscription(query_object, http)
|
||||||
hub = Diaspora::OStatusParser::find_hub(http.response)
|
hub = Diaspora::OStatusParser::find_hub(http.response)
|
||||||
add_hub_subscription_request(hub, query_object.destination)
|
add_hub_subscription_request(hub, query_object.destination)
|
||||||
Diaspora::OStatusParser::parse_sender(http.response)
|
Diaspora::OStatusParser::process(http.response)
|
||||||
end
|
end
|
||||||
|
|
||||||
def process
|
def process
|
||||||
|
|
|
||||||
2
spec/fixtures/ostatus_update.xml
vendored
Normal file
2
spec/fixtures/ostatus_update.xml
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<feed xml:lang=\"en-US\" xmlns=\"http://www.w3.org/2005/Atom\" xmlns:thr=\"http://purl.org/syndication/thread/1.0\" xmlns:georss=\"http://www.georss.org/georss\" xmlns:activity=\"http://activitystrea.ms/spec/1.0/\" xmlns:media=\"http://purl.org/syndication/atommedia\" xmlns:poco=\"http://portablecontacts.net/spec/1.0\" xmlns:ostatus=\"http://ostatus.org/schema/1.0\" xmlns:statusnet=\"http://status.net/schema/api/1/\">\n <generator uri=\"http://status.net\" version=\"0.9.3\">StatusNet</generator>\n <id>http://identi.ca/api/statuses/user_timeline/217769.atom</id>\n <title>danielgrippi timeline</title>\n <subtitle>Updates from danielgrippi on Identi.ca!</subtitle>\n <logo>http://theme.status.net/0.9.3/identica/default-avatar-profile.png</logo>\n <updated>2010-07-22T22:15:31+00:00</updated>\n<author>\n <name>danielgrippi</name>\n <uri>http://identi.ca/user/217769</uri>\n</author>\n <link href=\"http://identi.ca/danielgrippi\" rel=\"alternate\" type=\"text/html\"/>\n <link href=\"http://identi.ca/main/sup#217769\" rel=\"http://api.friendfeed.com/2008/03#sup\" type=\"application/json\"/>\n <link href=\"http://identi.ca/main/push/hub\" rel=\"hub\"/>\n <link href=\"http://identi.ca/main/salmon/user/217769\" rel=\"http://salmon-protocol.org/ns/salmon-replies\"/>\n <link href=\"http://identi.ca/main/salmon/user/217769\" rel=\"http://salmon-protocol.org/ns/salmon-mention\"/>\n <link href=\"http://identi.ca/api/statuses/user_timeline/217769.atom\" rel=\"self\" type=\"application/atom+xml\"/>\n<activity:subject>\n <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>\n <id>http://identi.ca/user/217769</id>\n <title>Daniel Grippi</title>\n <link rel=\"alternate\" type=\"text/html\" href=\"http://identi.ca/danielgrippi\"/>\n <link rel=\"avatar\" type=\"image/png\" media:width=\"96\" media:height=\"96\" href=\"http://theme.status.net/0.9.3/identica/default-avatar-profile.png\"/>\n <link rel=\"avatar\" type=\"image/png\" media:width=\"48\" media:height=\"48\" href=\"http://theme.status.net/0.9.3/identica/default-avatar-stream.png\"/>\n <link rel=\"avatar\" type=\"image/png\" media:width=\"24\" media:height=\"24\" href=\"http://theme.status.net/0.9.3/identica/default-avatar-mini.png\"/>\n <georss:point>0 0</georss:point>\n<poco:preferredUsername>danielgrippi</poco:preferredUsername>\n<poco:displayName>Daniel Grippi</poco:displayName>\n<poco:note>hey there kids!</poco:note>\n<poco:address>\n <poco:formatted>earth</poco:formatted>\n</poco:address>\n<poco:urls>\n <poco:type>homepage</poco:type>\n <poco:value>http://danielgrippi.com/</poco:value>\n <poco:primary>true</poco:primary>\n</poco:urls>\n</activity:subject>\n<entry>\n <title>SOAP!</title>\n <link rel=\"alternate\" type=\"text/html\" href=\"http://identi.ca/notice/43074747\"/>\n <id>http://identi.ca/notice/43074747</id>\n <published>2010-07-22T22:15:31+00:00</published>\n <updated>2010-07-22T22:15:31+00:00</updated>\n <statusnet:notice_info local_id=\"43074747\" source=\"web\"></statusnet:notice_info>\n <link rel=\"ostatus:conversation\" href=\"http://identi.ca/conversation/42780740\"/>\n <content type=\"html\">SOAP!</content>\n <georss:point>37.7912 -122.401</georss:point>\n</entry>\n</feed>\n"
|
||||||
|
|
||||||
|
|
@ -194,10 +194,10 @@ describe MessageHandler do
|
||||||
Diaspora::OStatusParser.stub!(:find_hub).and_return("http://hub.google.com")
|
Diaspora::OStatusParser.stub!(:find_hub).and_return("http://hub.google.com")
|
||||||
MessageHandler.stub!(:add_hub_subscription_request).and_return(true)
|
MessageHandler.stub!(:add_hub_subscription_request).and_return(true)
|
||||||
|
|
||||||
Diaspora::OStatusParser.stub!(:parse_sender)
|
Diaspora::OStatusParser.stub!(:process)
|
||||||
Diaspora::OStatusParser.should_receive(:find_hub)
|
Diaspora::OStatusParser.should_receive(:find_hub)
|
||||||
@handler.should_receive(:add_hub_subscription_request)
|
@handler.should_receive(:add_hub_subscription_request)
|
||||||
Diaspora::OStatusParser.should_receive(:parse_sender)
|
Diaspora::OStatusParser.should_receive(:process)
|
||||||
|
|
||||||
g = mock("Message")
|
g = mock("Message")
|
||||||
g.stub!(:destination).and_return("google")
|
g.stub!(:destination).and_return("google")
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,68 @@ describe "parser in application helper" do
|
||||||
Diaspora::OStatusParser::find_hub(xml).should == 'http://identi.ca/main/push/hub'
|
Diaspora::OStatusParser::find_hub(xml).should == 'http://identi.ca/main/push/hub'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
describe 'subscriber info' do
|
||||||
|
before do
|
||||||
|
#load file
|
||||||
|
xml_path = File.dirname(__FILE__) + '/../fixtures/ostatus_update.xml'
|
||||||
|
@xml = File.open(xml_path).read
|
||||||
|
@xml = Nokogiri::HTML(@xml)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
it 'should parse the users service' do
|
||||||
|
Diaspora::OStatusParser::parse_service(@xml).should == 'StatusNet'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should parse the feed_url' do
|
||||||
|
Diaspora::OStatusParser::parse_feed_url(@xml).should == 'http://identi.ca/api/statuses/user_timeline/217769.atom'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should parse the avatar thumbnail' do
|
||||||
|
Diaspora::OStatusParser::parse_avatar_thumbnail(@xml).should == 'http://theme.status.net/0.9.3/identica/default-avatar-profile.png'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should parse the username' do
|
||||||
|
Diaspora::OStatusParser::parse_username(@xml).should == 'danielgrippi'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should parse the profile_url' do
|
||||||
|
Diaspora::OStatusParser::parse_profile_url(@xml).should == 'http://identi.ca/user/217769'
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'entry' do
|
||||||
|
before do
|
||||||
|
#load file
|
||||||
|
xml_path = File.dirname(__FILE__) + '/../fixtures/ostatus_update.xml'
|
||||||
|
@xml = File.open(xml_path).read
|
||||||
|
@xml = Nokogiri::HTML(@xml)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should parse the message' do
|
||||||
|
Diaspora::OStatusParser::parse_message(@xml).should == 'SOAP!'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should parse the permalink' do
|
||||||
|
Diaspora::OStatusParser::parse_permalink(@xml).should == 'http://identi.ca/notice/43074747'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should parse published at date' do
|
||||||
|
Diaspora::OStatusParser::parse_published_at(@xml).should == '2010-07-22T22:15:31+00:00'
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should parse the updated at date' do
|
||||||
|
Diaspora::OStatusParser::parse_updated_at(@xml).should == '2010-07-22T22:15:31+00:00'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "parsing compliant XML object" do
|
describe "parsing compliant XML object" do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue