diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb
index d4061d124..1e68a74da 100644
--- a/app/controllers/status_messages_controller.rb
+++ b/app/controllers/status_messages_controller.rb
@@ -1,5 +1,5 @@
class StatusMessagesController < ApplicationController
- before_filter :authenticate_user!
+ #before_filter :authenticate_user!
def index
@status_messages = StatusMessage.paginate :page => params[:page], :order => 'created_at DESC'
@@ -7,8 +7,7 @@ class StatusMessagesController < ApplicationController
respond_to do |format|
format.html
- format.xml {render :xml => Post.build_xml_for(@status_messages)}
- format.json { render :json => @status_messages }
+ format.atom {render :xml => Diaspora::XML::generate(:current_url => request.url, :objects => @status_messages)}
end
end
diff --git a/app/models/bookmark.rb b/app/models/bookmark.rb
index 3df470a39..340643716 100644
--- a/app/models/bookmark.rb
+++ b/app/models/bookmark.rb
@@ -18,7 +18,7 @@ class Bookmark < Post
def clean_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] != '/'
end
end
diff --git a/app/models/person.rb b/app/models/person.rb
index 82e7e4f9b..d9774413f 100644
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -2,9 +2,9 @@ class Person
include MongoMapper::Document
include ROXML
+ xml_accessor :_id
xml_accessor :email
xml_accessor :url
- xml_accessor :_id
xml_accessor :key_fingerprint
xml_accessor :profile, :as => Profile
diff --git a/app/models/request.rb b/app/models/request.rb
index ef935ac03..c3962a0f5 100644
--- a/app/models/request.rb
+++ b/app/models/request.rb
@@ -19,6 +19,11 @@ class Request
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 :from_user, lambda{ |user| where(:destination_url.ne => user.url) }
@@ -32,5 +37,14 @@ class Request
p.active = true
p.save
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
diff --git a/app/models/retraction.rb b/app/models/retraction.rb
index 538f89513..2e9a29f77 100644
--- a/app/models/retraction.rb
+++ b/app/models/retraction.rb
@@ -19,7 +19,6 @@ class Retraction
attr_accessor :type
def perform
- puts self.inspect
self.type.constantize.destroy(self.post_id)
end
diff --git a/app/models/status_message.rb b/app/models/status_message.rb
index 96c9c689e..65e578dd6 100644
--- a/app/models/status_message.rb
+++ b/app/models/status_message.rb
@@ -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
diff --git a/lib/common.rb b/lib/common.rb
index fcd9cd82b..7e053a4fc 100644
--- a/lib/common.rb
+++ b/lib/common.rb
@@ -91,4 +91,89 @@ module Diaspora
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
+
+
+Diaspora
+#{current_url}
+Stream
+its a stream
+#{Time.now.xmlschema}
+ XML
+ end
+
+ def self.author
+ <<-XML
+
+#{OWNER.real_name}
+#{OWNER.url}
+
+ XML
+ end
+
+ def self.endpoints
+ #generate pubsub, poco, salmon endpoints
+ ""
+ end
+
+ def self.subject
+ <<-XML
+
+http://activitystrea.ms/schema/1.0/person
+#{OWNER.url}
+#{OWNER.real_name}
+
+
+ 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
+
+#{status_message.message}
+
+#{OWNER.url}status_messages/#{status_message.id}
+#{status_message.created_at.xmlschema}
+#{status_message.updated_at.xmlschema}
+
+ XML
+ end
+
+ def self.footer
+ <<-XML.strip
+
+ XML
+ end
+ end
+ end
end
diff --git a/spec/lib/common_spec.rb b/spec/lib/common_spec.rb
index 7e2073d4d..debd5031f 100644
--- a/spec/lib/common_spec.rb
+++ b/spec/lib/common_spec.rb
@@ -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 ""
end
end
-
end
end
diff --git a/spec/lib/parser_spec.rb b/spec/lib/parser_spec.rb
index 92673e06c..c6650fb75 100644
--- a/spec/lib/parser_spec.rb
+++ b/spec/lib/parser_spec.rb
@@ -144,12 +144,8 @@ describe "parser in application helper" do
it 'should marshal a retraction for a person' do
retraction = Retraction.for(@user)
-
request = Retraction.build_xml_for( [retraction] )
-
- puts request.inspect
-
Person.count.should == 2
store_objects_from_xml( request )
Person.count.should == 1
diff --git a/spec/lib/xml_spec.rb b/spec/lib/xml_spec.rb
new file mode 100644
index 000000000..5c1714d73
--- /dev/null
+++ b/spec/lib/xml_spec.rb
@@ -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