Newer
Older
def parse_owner_from_xml(xml)
doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
danielvincent
a validé
Person.where(:email => email).first
def parse_body_contents_from_xml(xml)
doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
doc.xpath("/XML/posts/post")
end
def parse_objects_from_xml(xml)
objects = []
body = parse_body_contents_from_xml(xml)
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
Rails.logger.info "Not a real type: #{object.to_s}"
end
end
objects
end
def store_objects_from_xml(xml)
objects = parse_objects_from_xml(xml)
objects.each do |p|
Rails.logger.info("Receiving object:\n#{p.inspect}")
User.owner.receive_friend_request(p)
#This line checks if the sender was in the database, among other things?
danielvincent
a validé
elsif p.respond_to?(:person) && !(p.person.nil?) && !(p.person.is_a? User) #WTF
#p.save if p.respond_to?(:person) && !(p.person == nil) #WTF
end
end
end
def self.included(klass)
klass.class_eval do
maxwell
a validé
include ROXML
require 'message_handler'
danielvincent
a validé
def notify_people
if self.person_id == User.owner.id
danielvincent
a validé
push_to(people_with_permissions)
@@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])
Rails.logger.info("Adding xml for #{self} to message queue to #{recipients}")
@@queue.add_post_request( recipients, xml )
end
maxwell
a validé
def push_to_url(url)
hook_url = url + "receive/"
Rails.logger.info("Adding xml for #{self} to message queue to #{url}")
@@queue.add_post_request( [hook_url], xml )
@@queue.process
def prep_webhook
"<post>#{self.to_xml.to_s}</post>"
danielvincent
a validé
def people_with_permissions
xml = "<XML>"
posts.each {|x| xml << x.prep_webhook}
xml += "</posts>"
xml += "</XML>"
end
end
module XML
def self.generate(opts= {})
maxwell
a validé
xml = Generate::headers(opts[:current_url])
xml << Generate::author
xml << Generate::endpoints
xml << Generate::subject
xml << Generate::entries(opts[:objects])
xml << Generate::footer
maxwell
a validé
module Generate
def self.headers(current_url)
maxwell
a validé
#this is retarded
@@user = User.owner
maxwell
a validé
<<-XML
<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:georss="http://www.georss.org/georss" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:media="http://purl.org/syndication/atommedia" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0" xmlns:statusnet="http://status.net/schema/api/1/">
<generator uri="http://joindiaspora.com/">Diaspora</generator>
maxwell
a validé
<id>#{current_url}</id>
<title>Stream</title>
<subtitle>its a stream </subtitle>
<updated>#{Time.now.xmlschema}</updated>
XML
end
maxwell
a validé
def self.author
<<-XML
<author>
maxwell
a validé
<name>#{@@user.real_name}</name>
<uri>#{@@user.url}</uri>
maxwell
a validé
</author>
XML
end
maxwell
a validé
def self.endpoints
<link href="#{APP_CONFIG[:pubsub_server]}" rel="hub"/>
maxwell
a validé
end
def self.subject
<<-XML
<activity:subject>
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
maxwell
a validé
<id>#{@@user.url}</id>
<title>#{@@user.real_name}</title>
<link rel="alternative" type="text/html" href="#{@@user.url}"/>
maxwell
a validé
</activity:subject>
XML
maxwell
a validé
def self.entries(objects)
xml = ""
if objects.respond_to? :each
objects.each {|x| xml << self.entry(x)}
else
xml << self.entry(objects)
end
xml
end
maxwell
a validé
def self.entry(object)
eval "#{object.class}_build_entry(object)"
end
maxwell
a validé
def self.StatusMessage_build_entry(status_message)
<<-XML
<entry>
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
maxwell
a validé
<title>#{status_message.message}</title>
maxwell
a validé
<link rel="alternate" type="text/html" href="#{@@user.url}status_messages/#{status_message.id}"/>
<id>#{@@user.url}status_messages/#{status_message.id}</id>
maxwell
a validé
<published>#{status_message.created_at.xmlschema}</published>
<updated>#{status_message.updated_at.xmlschema}</updated>
</entry>
XML
end
def self.Bookmark_build_entry(bookmark)
<<-XML
<entry>
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
<title>#{bookmark.title}</title>
maxwell
a validé
<link rel="alternate" type="text/html" href="#{@@user.url}bookmarks/#{bookmark.id}"/>
<link rel="related" type="text/html" href="#{bookmark.link}"/>
maxwell
a validé
<id>#{@@user.url}bookmarks/#{bookmark.id}</id>
<published>#{bookmark.created_at.xmlschema}</published>
<updated>#{bookmark.updated_at.xmlschema}</updated>
</entry>
XML
end
def self.Blog_build_entry(blog)
<<-XML
<entry>
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
<title>#{blog.title}</title>
<content>#{blog.body}</content>
maxwell
a validé
<link rel="alternate" type="text/html" href="#{@@user.url}blogs/#{blog.id}"/>
<id>#{@@user.url}blogs/#{blog.id}</id>
<published>#{blog.created_at.xmlschema}</published>
<updated>#{blog.updated_at.xmlschema}</updated>
</entry>
XML
end
maxwell
a validé
def self.footer
<<-XML.strip
</feed>
XML
end