Skip to content
Extraits de code Groupes Projets
Valider 16bbce30 rédigé par maxwell's avatar maxwell
Parcourir les fichiers

DG MS ostatus post and author now exsist

parent c5bcab94
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
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
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
......
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
require File.dirname(__FILE__) + '/../spec_helper'
describe OstatusPost do
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