diff --git a/lib/diaspora/ostatus_parser.rb b/lib/diaspora/ostatus_parser.rb index 01bdfdc66..201e908d2 100644 --- a/lib/diaspora/ostatus_parser.rb +++ b/lib/diaspora/ostatus_parser.rb @@ -16,65 +16,66 @@ module Diaspora author.ostatus_posts.create(entry_hash) unless entry_hash[:message] == 0 end - def self.parse_author(doc) + def self.author(doc) doc = Nokogiri::HTML(doc) if doc.is_a? String author = {} - author[:service] = parse_service(doc) - author[:feed_url] = parse_feed_url(doc) - author[:avatar_thumbnail] = parse_avatar_thumbnail(doc) - author[:username] = parse_username(doc) - author[:profile_url] = parse_profile_url(doc) + author[:service] = self.service(doc) + author[:feed_url] = self.feed_url(doc) + author[:avatar_thumbnail] = self.avatar_thumbnail(doc) + author[:username] = self.username(doc) + author[:profile_url] = self.profile_url(doc) author end - def self.parse_entry(doc) + def self.entry(doc) doc = Nokogiri::HTML(doc) if doc.is_a? String entry = {} - entry[:message] = parse_message(doc) - entry[:permalink] = parse_permalink(doc) - entry[:published_at] = parse_published_at(doc) - entry[:updated_at] = parse_updated_at(doc) + entry[:message] = self.message(doc) + entry[:permalink] = self.permalink(doc) + entry[:published_at] = self.published_at(doc) + entry[:updated_at] = self.updated_at(doc) entry end ##author### - def self.parse_service(doc) + def self.service(doc) doc.xpath('//generator').each{|x| return x.inner_html} end - def self.parse_feed_url(doc) + def self.feed_url(doc) doc.xpath('//id').each{|x| return x.inner_html} end - def self.parse_avatar_thumbnail(doc) + def self.avatar_thumbnail(doc) doc.xpath('//logo').each{|x| return x.inner_html} end - def self.parse_username(doc) + def self.username(doc) doc.xpath('//author/name').each{|x| return x.inner_html} end - def self.parse_profile_url(doc) + def self.profile_url(doc) doc.xpath('//author/uri').each{|x| return x.inner_html} end #entry## - def self.parse_message(doc) + def self.message(doc) doc.xpath('//entry/title').each{|x| return x.inner_html} end - def self.parse_permalink(doc) + def self.permalink(doc) doc.xpath('//entry/id').each{|x| return x.inner_html} end - def self.parse_published_at(doc) + def self.published_at(doc) doc.xpath('//entry/published').each{|x| return x.inner_html} end - def self.parse_updated_at(doc) + def self.updated_at(doc) doc.xpath('//entry/updated').each{|x| return x.inner_html} end + end -end \ No newline at end of file +end diff --git a/spec/lib/ostatus_parser_spec.rb b/spec/lib/ostatus_parser_spec.rb index 4bde6b19e..3f8b3a3ab 100644 --- a/spec/lib/ostatus_parser_spec.rb +++ b/spec/lib/ostatus_parser_spec.rb @@ -19,23 +19,23 @@ describe Diaspora::OStatusParser do it 'should parse the users service' do - Diaspora::OStatusParser::parse_service(@xml).should == 'StatusNet' + Diaspora::OStatusParser::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' + Diaspora::OStatusParser::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' + Diaspora::OStatusParser::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' + Diaspora::OStatusParser::username(@xml).should == 'danielgrippi' end it 'should parse the profile_url' do - Diaspora::OStatusParser::parse_profile_url(@xml).should == 'http://identi.ca/user/217769' + Diaspora::OStatusParser::profile_url(@xml).should == 'http://identi.ca/user/217769' end end @@ -49,20 +49,20 @@ describe Diaspora::OStatusParser do end it 'should parse the message' do - Diaspora::OStatusParser::parse_message(@xml).should == 'SOAP!' + Diaspora::OStatusParser::message(@xml).should == 'SOAP!' end it 'should parse the permalink' do - Diaspora::OStatusParser::parse_permalink(@xml).should == 'http://identi.ca/notice/43074747' + Diaspora::OStatusParser::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' + Diaspora::OStatusParser::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' + Diaspora::OStatusParser::updated_at(@xml).should == '2010-07-22T22:15:31+00:00' end end -end \ No newline at end of file +end