DG MS; started Diaspora::XML for ostatus compliance
This commit is contained in:
parent
f9f7f0fcc7
commit
ed8ed9be9e
4 changed files with 121 additions and 4 deletions
|
|
@ -9,8 +9,7 @@ class StatusMessage < Post
|
|||
|
||||
validates_presence_of :message
|
||||
|
||||
|
||||
def ==(other)
|
||||
def ==(other)
|
||||
(self.message == other.message) && (self.person.email == other.person.email)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -91,4 +91,94 @@ module Diaspora
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
module XML
|
||||
|
||||
|
||||
def self.generate(opts= {})
|
||||
@owner = User.owner
|
||||
@root_url = @owner.url
|
||||
|
||||
xml = self.generate_headers(opts[:current_url])
|
||||
xml << self.generate_author
|
||||
xml << self.generate_endpoints
|
||||
xml << self.generate_subject
|
||||
xml << self.build_entries(opts[:objects])
|
||||
xml << self.generate_footer
|
||||
end
|
||||
|
||||
def self.generate_headers(current_url)
|
||||
<<-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="#{@owner.url}">Diaspora</generator>
|
||||
<id>#{current_url}</id>
|
||||
<title>Stream</title>
|
||||
<subtitle>its a stream </subtitle>
|
||||
<logo></logo>
|
||||
<updated>#{Time.now}</updated>
|
||||
XML
|
||||
end
|
||||
|
||||
def self.generate_author
|
||||
<<-XML
|
||||
<author>
|
||||
<name>#{@owner.real_name}</name>
|
||||
<uri>#{@root_url}</uri>
|
||||
</author>
|
||||
XML
|
||||
end
|
||||
|
||||
def self.generate_endpoints
|
||||
#generate pubsub, poco, salmon endpoints
|
||||
""
|
||||
end
|
||||
|
||||
def self.build_entries(objects)
|
||||
xml = ""
|
||||
if objects.respond_to? :each
|
||||
objects.each {|x| xml << self.build_entry(x)}
|
||||
else
|
||||
xml << self.build_entry(objects)
|
||||
end
|
||||
xml
|
||||
end
|
||||
|
||||
def self.generate_subject
|
||||
<<-XML
|
||||
<activity:subject>
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
|
||||
<id>#{@root_url}</id>
|
||||
<title>#{@owner.real_name}</title>
|
||||
<link rel="alternative" type="text/html" href="#{@root_url}"/>
|
||||
</activity:subject>
|
||||
XML
|
||||
end
|
||||
|
||||
def self.build_entry(object)
|
||||
eval "#{object.class}_build_entry(object)"
|
||||
end
|
||||
|
||||
def self.StatusMessage_build_entry(status_message)
|
||||
<<-XML
|
||||
<entry>
|
||||
<title>#{status_message.message}</title>
|
||||
<link rel="alternative" type="text/html" href="#{@root_url}/status_messages/#{status_message.id}"/>
|
||||
<id>#{status_message.id}</id>
|
||||
<published>#{status_message.created_at}</published>
|
||||
<updated>#{status_message.updated_at}</updated>
|
||||
</entry>
|
||||
XML
|
||||
end
|
||||
|
||||
|
||||
def self.generate_footer
|
||||
<<-XML
|
||||
</feed>
|
||||
XML
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
|
||||
|
||||
include Diaspora
|
||||
|
||||
describe Diaspora do
|
||||
|
|
@ -63,7 +62,6 @@ describe Diaspora do
|
|||
xml.should include "<bookmark>"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
30
spec/lib/xml_spec.rb
Normal file
30
spec/lib/xml_spec.rb
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
|
||||
describe "XML generation" do
|
||||
|
||||
describe "header" do
|
||||
it 'should generate an OStatus compliant header' do
|
||||
user = Factory.create(:user)
|
||||
Diaspora::XML::generate_headers.should include user.url
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "status message entry" do
|
||||
before do
|
||||
@status_message = Factory.build(:status_message)
|
||||
end
|
||||
|
||||
it "should encode to activity stream xml" do
|
||||
Factory.create(:user)
|
||||
sm_entry = Diaspora::XML::generate(:objects => @status_message)
|
||||
sm_entry.should include(@status_message.message)
|
||||
sm_entry.should include('title')
|
||||
|
||||
puts sm_entry
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
Loading…
Reference in a new issue