DG MS ostatus post and author now exsist
This commit is contained in:
parent
c5bcab94e1
commit
16bbce3054
5 changed files with 64 additions and 28 deletions
17
app/models/author.rb
Normal file
17
app/models/author.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
class Author
|
||||
include MongoMapper::Document
|
||||
|
||||
key :service, String
|
||||
key :feed_url, String
|
||||
key :avatar_thumbnail, String
|
||||
key :username, String
|
||||
key :profile_url, String
|
||||
|
||||
many :ostatus_posts, :class_name => 'OstatusPost', :foreign_key => :author_id
|
||||
|
||||
|
||||
def self.instantiate(opts)
|
||||
author = Author.first(:feed_url => opts[:feed_url])
|
||||
author ||= Author.create(opts)
|
||||
end
|
||||
end
|
||||
9
app/models/ostatus_post.rb
Normal file
9
app/models/ostatus_post.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
class OstatusPost
|
||||
include MongoMapper::Document
|
||||
|
||||
key :author_id, ObjectId
|
||||
|
||||
belongs_to :author, :class_name => 'Author'
|
||||
|
||||
end
|
||||
|
||||
|
|
@ -5,43 +5,32 @@ module Diaspora
|
|||
end
|
||||
|
||||
def self.process(xml)
|
||||
|
||||
doc = Nokogiri::HTML(xml)
|
||||
parse_author(doc)
|
||||
puts ""
|
||||
parse_entry(doc)
|
||||
author_hash = parse_author(doc)
|
||||
entry_hash = parse_entry(doc)
|
||||
|
||||
author = Author.instantiate(author_hash).ostatus_posts.create(entry_hash)
|
||||
end
|
||||
|
||||
def self.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
|
||||
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
|
||||
end
|
||||
|
||||
def self.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
|
||||
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
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
16
spec/models/author_spec.rb
Normal file
16
spec/models/author_spec.rb
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
|
||||
include Diaspora::OStatusParser
|
||||
|
||||
describe Author do
|
||||
|
||||
it 'should create from ostatus compliant xml from the parser' do
|
||||
xml_path = File.dirname(__FILE__) + '/../fixtures/ostatus_update.xml'
|
||||
xml = File.open(xml_path).read
|
||||
|
||||
Author.count.should == 0
|
||||
Diaspora::OStatusParser.process(xml)
|
||||
Author.count.should == 1
|
||||
end
|
||||
|
||||
end
|
||||
5
spec/models/ostatus_post_spec.rb
Normal file
5
spec/models/ostatus_post_spec.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
|
||||
describe OstatusPost do
|
||||
|
||||
end
|
||||
Loading…
Reference in a new issue