Skip to content
Extraits de code Groupes Projets
Valider b7fb844f rédigé par danielvincent's avatar danielvincent
Parcourir les fichiers

more cleanup on Diaspora::OStatusParser

parent 2938341b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
module Diaspora
module OStatusParser
def self.find_hub(xml)
xml = Nokogiri::HTML(xml) if xml.is_a? String
xml.xpath('//link[@rel="hub"]').first.attribute("href").value
end
def self.process(xml)
doc = Nokogiri::HTML(xml)
author_hash = parse_author(doc)
author_hash[:hub] = find_hub(doc)
author_hash[:hub] = self.hub(doc)
entry_hash = parse_entry(doc)
author = Author.instantiate(author_hash)
......@@ -38,44 +34,53 @@ module Diaspora
end
##author###
def self.hub(xml)
xml = Nokogiri::HTML(xml) if xml.is_a? String
xml.xpath('//link[@rel="hub"]').first.attribute("href").value
end
# Author #########################
def self.service(doc)
doc.xpath('//generator').each{|x| return x.inner_html}
self.contents(doc.xpath('//generator'))
end
def self.feed_url(doc)
doc.xpath('//id').each{|x| return x.inner_html}
self.contents(doc.xpath('//id'))
end
def self.avatar_thumbnail(doc)
doc.xpath('//logo').each{|x| return x.inner_html}
self.contents(doc.xpath('//logo'))
end
def self.username(doc)
doc.xpath('//author/name').each{|x| return x.inner_html}
self.contents(doc.xpath('//author/name'))
end
def self.profile_url(doc)
doc.xpath('//author/uri').each{|x| return x.inner_html}
self.contents(doc.xpath('//author/uri'))
end
#entry##
# Entry ##########################
def self.message(doc)
doc.xpath('//entry/title').each{|x| return x.inner_html}
self.contents(doc.xpath('//entry/title'))
end
def self.permalink(doc)
doc.xpath('//entry/id').each{|x| return x.inner_html}
self.contents(doc.xpath('//entry/id'))
end
def self.published_at(doc)
doc.xpath('//entry/published').each{|x| return x.inner_html}
self.contents(doc.xpath('//entry/published'))
end
def self.updated_at(doc)
doc.xpath('//entry/updated').each{|x| return x.inner_html}
self.contents(doc.xpath('//entry/updated'))
end
def self.contents(xpath)
xpath.each{|x| return x.inner_html}
end
end
end
......@@ -5,7 +5,7 @@ describe Diaspora::OStatusParser do
xml_path = File.dirname(__FILE__) + '/../fixtures/identica_feed.atom'
xml = File.open(xml_path).read
Diaspora::OStatusParser::find_hub(xml).should == 'http://identi.ca/main/push/hub'
Diaspora::OStatusParser::hub(xml).should == 'http://identi.ca/main/push/hub'
end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter