DG MS profiles send? who knows...

This commit is contained in:
maxwell 2010-07-29 15:53:38 -07:00
parent a636d97837
commit 6aa1fa1826
5 changed files with 49 additions and 12 deletions

View file

@ -29,7 +29,7 @@ class Profile
end
def to_diaspora_xml
self.to_xml.to_s
"<post>"+ self.to_xml.to_s + "</post>"
end
end

View file

@ -3,13 +3,18 @@ module Diaspora
def parse_owner_from_xml(xml)
doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
email = doc.xpath("//person/email").text.to_s
Person.where(:email => email).first
Person.first(:email => email)
end
def parse_body_contents_from_xml(xml)
doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
doc.xpath("/XML/posts/post")
end
def parse_owner_id_from_xml(doc)
id = doc.xpath("//person_id").text.to_s
Person.first(:id => id)
end
def parse_objects_from_xml(xml)
objects = []
@ -17,8 +22,17 @@ module Diaspora
body.children.each do |post|
begin
object = post.name.camelize.constantize.from_xml post.to_s
object.person = parse_owner_from_xml post.to_s if object.respond_to? :person
objects << object
if object.respond_to? :person
object.person = parse_owner_from_xml post.to_s
end
objects << object
#elsif object.is_a? Profile
# person = parse_owner_id_from_xml post
# profile_hash = Hash.from_xml(post.to_s)
# person.profile.update_attributes!(profile_hash)
#else
# object << object
#end
rescue
Rails.logger.info "Not a real type: #{object.to_s}"
end
@ -31,6 +45,7 @@ module Diaspora
objects.each do |p|
Rails.logger.info("Receiving object:\n#{p.inspect}")
if p.is_a? Retraction
puts "i am here"
p.perform
elsif p.is_a? Request
User.owner.receive_friend_request(p)
@ -42,4 +57,4 @@ module Diaspora
end
end
end
end
end

View file

@ -1,4 +1,3 @@
module Diaspora
module Webhooks
def self.included(klass)
@ -31,7 +30,7 @@ module Diaspora
@@queue.add_hub_notification(APP_CONFIG[:pubsub_server], User.owner.url + self.class.to_s.pluralize.underscore + '.atom')
unless recipients.empty?
recipients.map!{|x| x = x.url + "receive/"}
xml = self.class.build_xml_for(self)
xml = Post.build_xml_for(self)
Rails.logger.info("Adding xml for #{self} to message queue to #{recipients}")
@@queue.add_post_request( recipients, xml )
end

View file

@ -151,8 +151,30 @@ describe Diaspora::DiasporaParser do
Person.count.should == 2
store_objects_from_xml( request )
Person.count.should == 1
end
it 'should marshal a profile for a person' do
person = Factory.create(:person)
person.profile = Profile.new(:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com")
old_profile = person.profile
puts person.profile.inspect
xml = Post.build_xml_for(person.profile)
person.profile = nil
person.save
puts person.profile.inspect
person.profile.should_be nil
store_objects_from_xml xml
person = Person.first(:id => person.id)
person.profile.should == old_profile
person.profile.should_not be nil
end
end
end

View file

@ -65,15 +65,16 @@ describe User do
@user = Factory.create(:user)
p = {:profile => {:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com"}}
n = Profile.send :class_variable_get, :@@queue
n.should_receive(:process)
@user.update_profile(p).should == true
@user.profile.image_url.should == "http://clown.com"
Profile.should_receive(:build_xml_for)
n = Profile.send :class_variable_get, :@@queue
n.should_receive(:process)
end