merging in master
This commit is contained in:
commit
83ea15c97a
10 changed files with 135 additions and 14 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
class StatusMessagesController < ApplicationController
|
class StatusMessagesController < ApplicationController
|
||||||
before_filter :authenticate_user!
|
#before_filter :authenticate_user!
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@status_messages = StatusMessage.paginate :page => params[:page], :order => 'created_at DESC'
|
@status_messages = StatusMessage.paginate :page => params[:page], :order => 'created_at DESC'
|
||||||
|
|
@ -7,8 +7,7 @@ class StatusMessagesController < ApplicationController
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
format.xml {render :xml => Post.build_xml_for(@status_messages)}
|
format.atom {render :xml => Diaspora::XML::generate(:current_url => request.url, :objects => @status_messages)}
|
||||||
format.json { render :json => @status_messages }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class Bookmark < Post
|
||||||
|
|
||||||
def clean_link
|
def clean_link
|
||||||
if self.link
|
if self.link
|
||||||
self.link = 'http://' + self.link unless self.link.match('http://' || 'https://')
|
self.link = 'http://' + self.link unless self.link.match('https?://')
|
||||||
self.link = self.link + '/' if self.link[-1,1] != '/'
|
self.link = self.link + '/' if self.link[-1,1] != '/'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@ class Person
|
||||||
include MongoMapper::Document
|
include MongoMapper::Document
|
||||||
include ROXML
|
include ROXML
|
||||||
|
|
||||||
|
xml_accessor :_id
|
||||||
xml_accessor :email
|
xml_accessor :email
|
||||||
xml_accessor :url
|
xml_accessor :url
|
||||||
xml_accessor :_id
|
|
||||||
xml_accessor :key_fingerprint
|
xml_accessor :key_fingerprint
|
||||||
xml_accessor :profile, :as => Profile
|
xml_accessor :profile, :as => Profile
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,11 @@ class Request
|
||||||
|
|
||||||
validates_presence_of :destination_url, :callback_url
|
validates_presence_of :destination_url, :callback_url
|
||||||
|
|
||||||
|
#validates_format_of :destination_url, :with =>
|
||||||
|
#/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix
|
||||||
|
|
||||||
|
before_validation :clean_link
|
||||||
|
|
||||||
scope :for_user, lambda{ |user| where(:destination_url => user.url) }
|
scope :for_user, lambda{ |user| where(:destination_url => user.url) }
|
||||||
scope :from_user, lambda{ |user| where(:destination_url.ne => user.url) }
|
scope :from_user, lambda{ |user| where(:destination_url.ne => user.url) }
|
||||||
|
|
||||||
|
|
@ -32,5 +37,14 @@ class Request
|
||||||
p.active = true
|
p.active = true
|
||||||
p.save
|
p.save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def clean_link
|
||||||
|
if self.destination_url
|
||||||
|
self.destination_url = 'http://' + self.destination_url unless self.destination_url.match('https?://')
|
||||||
|
self.destination_url = self.destination_url + '/' if self.destination_url[-1,1] != '/'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ class Retraction
|
||||||
attr_accessor :type
|
attr_accessor :type
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
puts self.inspect
|
|
||||||
self.type.constantize.destroy(self.post_id)
|
self.type.constantize.destroy(self.post_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,7 @@ class StatusMessage < Post
|
||||||
|
|
||||||
validates_presence_of :message
|
validates_presence_of :message
|
||||||
|
|
||||||
|
def ==(other)
|
||||||
def ==(other)
|
|
||||||
(self.message == other.message) && (self.person.email == other.person.email)
|
(self.message == other.message) && (self.person.email == other.person.email)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,4 +91,89 @@ module Diaspora
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module XML
|
||||||
|
|
||||||
|
OWNER = User.owner
|
||||||
|
|
||||||
|
def self.generate(opts= {})
|
||||||
|
xml = Generate::headers(opts[:current_url])
|
||||||
|
xml << Generate::author
|
||||||
|
xml << Generate::endpoints
|
||||||
|
xml << Generate::subject
|
||||||
|
xml << Generate::entries(opts[:objects])
|
||||||
|
xml << Generate::footer
|
||||||
|
end
|
||||||
|
|
||||||
|
module Generate
|
||||||
|
def self.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>
|
||||||
|
<updated>#{Time.now.xmlschema}</updated>
|
||||||
|
XML
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.author
|
||||||
|
<<-XML
|
||||||
|
<author>
|
||||||
|
<name>#{OWNER.real_name}</name>
|
||||||
|
<uri>#{OWNER.url}</uri>
|
||||||
|
</author>
|
||||||
|
XML
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.endpoints
|
||||||
|
#generate pubsub, poco, salmon endpoints
|
||||||
|
""
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.subject
|
||||||
|
<<-XML
|
||||||
|
<activity:subject>
|
||||||
|
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
|
||||||
|
<id>#{OWNER.url}</id>
|
||||||
|
<title>#{OWNER.real_name}</title>
|
||||||
|
<link rel="alternative" type="text/html" href="#{OWNER.url}"/>
|
||||||
|
</activity:subject>
|
||||||
|
XML
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
def self.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="alternate" type="text/html" href="#{OWNER.url}status_messages/#{status_message.id}"/>
|
||||||
|
<id>#{OWNER.url}status_messages/#{status_message.id}</id>
|
||||||
|
<published>#{status_message.created_at.xmlschema}</published>
|
||||||
|
<updated>#{status_message.updated_at.xmlschema}</updated>
|
||||||
|
</entry>
|
||||||
|
XML
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.footer
|
||||||
|
<<-XML.strip
|
||||||
|
</feed>
|
||||||
|
XML
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
require File.dirname(__FILE__) + '/../spec_helper'
|
require File.dirname(__FILE__) + '/../spec_helper'
|
||||||
|
|
||||||
|
|
||||||
include Diaspora
|
include Diaspora
|
||||||
|
|
||||||
describe Diaspora do
|
describe Diaspora do
|
||||||
|
|
@ -63,7 +62,6 @@ describe Diaspora do
|
||||||
xml.should include "<bookmark>"
|
xml.should include "<bookmark>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -144,12 +144,8 @@ describe "parser in application helper" do
|
||||||
|
|
||||||
it 'should marshal a retraction for a person' do
|
it 'should marshal a retraction for a person' do
|
||||||
retraction = Retraction.for(@user)
|
retraction = Retraction.for(@user)
|
||||||
|
|
||||||
request = Retraction.build_xml_for( [retraction] )
|
request = Retraction.build_xml_for( [retraction] )
|
||||||
|
|
||||||
|
|
||||||
puts request.inspect
|
|
||||||
|
|
||||||
Person.count.should == 2
|
Person.count.should == 2
|
||||||
store_objects_from_xml( request )
|
store_objects_from_xml( request )
|
||||||
Person.count.should == 1
|
Person.count.should == 1
|
||||||
|
|
|
||||||
31
spec/lib/xml_spec.rb
Normal file
31
spec/lib/xml_spec.rb
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
require File.dirname(__FILE__) + '/../spec_helper'
|
||||||
|
|
||||||
|
describe Diaspora::XML do
|
||||||
|
before do
|
||||||
|
@user = Factory.create(:user, :profile => { :first_name => "robert", :last_name => "grimm" } )
|
||||||
|
Diaspora::XML::OWNER = @user
|
||||||
|
end
|
||||||
|
|
||||||
|
describe Diaspora::XML::Generate do
|
||||||
|
|
||||||
|
describe "header" do
|
||||||
|
it 'should generate an OStatus compliant header' do
|
||||||
|
Diaspora::XML::Generate::headers(:current_url => @user.url).should include @user.url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "status message entry" do
|
||||||
|
before do
|
||||||
|
@status_message = Factory.create(:status_message, :message => "feed me")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should encode to activity stream xml" do
|
||||||
|
sm_entry = Diaspora::XML::generate(:objects => @status_message, :current_url => "http://diaspora.com/")
|
||||||
|
sm_entry.should include(@status_message.message)
|
||||||
|
sm_entry.should include('title')
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue