ostatus builder
This commit is contained in:
parent
1a876355d5
commit
df800dc87e
3 changed files with 93 additions and 0 deletions
|
|
@ -49,6 +49,10 @@ class Person
|
||||||
"#{self.url}receive/users/#{self.id}/"
|
"#{self.url}receive/users/#{self.id}/"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def public_url
|
||||||
|
"#{self.url}users/#{self.id}/public"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def public_key_hash
|
def public_key_hash
|
||||||
Base64.encode64 OpenSSL::Digest::SHA256.new(self.exported_key).to_s
|
Base64.encode64 OpenSSL::Digest::SHA256.new(self.exported_key).to_s
|
||||||
|
|
|
||||||
71
lib/diaspora/ostatus_builder.rb
Normal file
71
lib/diaspora/ostatus_builder.rb
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||||
|
# licensed under the Affero General Public License version 3. See
|
||||||
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
module Diaspora
|
||||||
|
module OstatusBuilder
|
||||||
|
|
||||||
|
def build(user)
|
||||||
|
if @user = User.find_by_id(user.id)
|
||||||
|
xml = ""
|
||||||
|
xml << create_headers
|
||||||
|
xml << create_endpoints
|
||||||
|
xml << create_subject
|
||||||
|
xml << create_body
|
||||||
|
xml << create_footer
|
||||||
|
else raise "Invalid user sent to builder" end
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_headers
|
||||||
|
<<-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>
|
||||||
|
<id>#{@user.username}/public</id>
|
||||||
|
<title>Stream</title>
|
||||||
|
<subtitle>its a stream</subtitle>
|
||||||
|
<updated>#{Time.now.xmlschema}</updated>
|
||||||
|
<author>
|
||||||
|
<name>#{@user.real_name}</name>
|
||||||
|
<uri>#{@user.public_url}</uri>
|
||||||
|
</author>
|
||||||
|
XML
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_endpoints
|
||||||
|
<<-XML
|
||||||
|
<link href="#{APP_CONFIG[:pubsub_server]}" rel="hub"/>
|
||||||
|
XML
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_subject
|
||||||
|
<<-XML
|
||||||
|
<activity:subject>
|
||||||
|
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
|
||||||
|
<id>#{@user.public_url}</id>
|
||||||
|
<title>#{@user.real_name}</title>
|
||||||
|
<link rel="alternative" type="text/html" href="#{@user.public_url}"/>
|
||||||
|
</activity:subject>
|
||||||
|
XML
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_body
|
||||||
|
@user.raw_visible_posts.all.inject do |xml,curr|
|
||||||
|
if curr.respond_to?(:to_activity)
|
||||||
|
unless xml
|
||||||
|
xml = curr.to_activity
|
||||||
|
else
|
||||||
|
xml + curr.to_activity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_footer
|
||||||
|
<<-XML
|
||||||
|
</feed>
|
||||||
|
XML
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
18
spec/lib/diaspora_ostatus_builder_spec.rb
Normal file
18
spec/lib/diaspora_ostatus_builder_spec.rb
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||||
|
# licensed under the Affero General Public License version 3. See
|
||||||
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
require 'spec_helper'
|
||||||
|
require File.dirname(__FILE__) + '/../../lib/diaspora/ostatus_builder'
|
||||||
|
|
||||||
|
describe Diaspora::OstatusBuilder do
|
||||||
|
|
||||||
|
let(:user) { Factory(:user) }
|
||||||
|
let(:aspect) { user.aspect(:name => "Public People") }
|
||||||
|
let!(:status_message1) { user.post(:status_message, :message => "One", :to => aspect.id) }
|
||||||
|
let!(:status_message2) { user.post(:status_message, :message => "Two", :to => aspect.id) }
|
||||||
|
|
||||||
|
let!(:atom) { Diaspora::OstatusBuilder::build(user) }
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
Loading…
Reference in a new issue