more cleanup on Diaspora::OStatusParser
This commit is contained in:
parent
2938341b54
commit
b7fb844fdf
2 changed files with 23 additions and 18 deletions
|
|
@ -1,15 +1,11 @@
|
||||||
module Diaspora
|
module Diaspora
|
||||||
module OStatusParser
|
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)
|
def self.process(xml)
|
||||||
doc = Nokogiri::HTML(xml)
|
doc = Nokogiri::HTML(xml)
|
||||||
author_hash = parse_author(doc)
|
author_hash = parse_author(doc)
|
||||||
|
|
||||||
author_hash[:hub] = find_hub(doc)
|
author_hash[:hub] = self.hub(doc)
|
||||||
entry_hash = parse_entry(doc)
|
entry_hash = parse_entry(doc)
|
||||||
|
|
||||||
author = Author.instantiate(author_hash)
|
author = Author.instantiate(author_hash)
|
||||||
|
|
@ -38,43 +34,52 @@ module Diaspora
|
||||||
end
|
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)
|
def self.service(doc)
|
||||||
doc.xpath('//generator').each{|x| return x.inner_html}
|
self.contents(doc.xpath('//generator'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.feed_url(doc)
|
def self.feed_url(doc)
|
||||||
doc.xpath('//id').each{|x| return x.inner_html}
|
self.contents(doc.xpath('//id'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.avatar_thumbnail(doc)
|
def self.avatar_thumbnail(doc)
|
||||||
doc.xpath('//logo').each{|x| return x.inner_html}
|
self.contents(doc.xpath('//logo'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.username(doc)
|
def self.username(doc)
|
||||||
doc.xpath('//author/name').each{|x| return x.inner_html}
|
self.contents(doc.xpath('//author/name'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.profile_url(doc)
|
def self.profile_url(doc)
|
||||||
doc.xpath('//author/uri').each{|x| return x.inner_html}
|
self.contents(doc.xpath('//author/uri'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Entry ##########################
|
||||||
#entry##
|
|
||||||
def self.message(doc)
|
def self.message(doc)
|
||||||
doc.xpath('//entry/title').each{|x| return x.inner_html}
|
self.contents(doc.xpath('//entry/title'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.permalink(doc)
|
def self.permalink(doc)
|
||||||
doc.xpath('//entry/id').each{|x| return x.inner_html}
|
self.contents(doc.xpath('//entry/id'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.published_at(doc)
|
def self.published_at(doc)
|
||||||
doc.xpath('//entry/published').each{|x| return x.inner_html}
|
self.contents(doc.xpath('//entry/published'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.updated_at(doc)
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ describe Diaspora::OStatusParser do
|
||||||
xml_path = File.dirname(__FILE__) + '/../fixtures/identica_feed.atom'
|
xml_path = File.dirname(__FILE__) + '/../fixtures/identica_feed.atom'
|
||||||
xml = File.open(xml_path).read
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue