diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index e65e00d7c..42dd80cd4 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -2,10 +2,5 @@ class ApplicationController < ActionController::Base
protect_from_forgery :except => :receive
layout 'application'
- def receive
- puts params.inspect
- puts "holy boner batman"
- render :nothing => true
- end
end
diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb
index 62911ac1c..91eff3cac 100644
--- a/app/controllers/dashboard_controller.rb
+++ b/app/controllers/dashboard_controller.rb
@@ -1,7 +1,19 @@
class DashboardController < ApplicationController
- before_filter :authenticate_user!
+
+ before_filter :authenticate_user!, :except => :receive
+ include ApplicationHelper
def index
@posts = Post.stream
end
+
+
+ def receive
+ store_posts_from_xml (params[:xml])
+
+
+
+ puts "holy boner batman"
+ render :nothing => true
+ end
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index f58313c9b..4580f9cd3 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -6,4 +6,15 @@ module ApplicationHelper
def object_fields(object)
object.attributes.keys
end
+
+ def store_posts_from_xml(xml)
+ doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
+ doc.xpath("//post").each do |post| #this is the post wrapper
+ post.children.each do|type| #now the text of post itself is the type
+ #type object to xml is the the thing we want to from_xml
+ object = type.name.camelize.constantize.from_xml type.to_s
+ object.save
+ end
+ end
+ end
end
diff --git a/app/helpers/dashboard_helper.rb b/app/helpers/dashboard_helper.rb
index a94ddfc2e..d06bca135 100644
--- a/app/helpers/dashboard_helper.rb
+++ b/app/helpers/dashboard_helper.rb
@@ -1,2 +1,7 @@
module DashboardHelper
+
+
+
+
+
end
diff --git a/app/models/status_message.rb b/app/models/status_message.rb
index b9eb2c4fc..0b58ee72b 100644
--- a/app/models/status_message.rb
+++ b/app/models/status_message.rb
@@ -2,6 +2,8 @@ class StatusMessage < Post
include StatusMessagesHelper
require 'lib/net/curl'
+ xml_name :status_message
+
xml_accessor :message
field :message
diff --git a/config/routes.rb b/config/routes.rb
index f1466709a..efdc9426f 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -14,7 +14,7 @@ Diaspora::Application.routes.draw do |map|
match 'logout', :to => 'devise/sessions#destroy', :as => "destroy_user_session"
match 'signup', :to => 'devise/registrations#new', :as => "new_user_registration"
- match 'receive', :to => 'application#receive'
+ match 'receive', :to => 'dashboard#receive'
resources :users
resources :status_messages
diff --git a/lib/common.rb b/lib/common.rb
index 218d34ca5..7b9538e88 100644
--- a/lib/common.rb
+++ b/lib/common.rb
@@ -16,10 +16,20 @@ module Diaspora
def prep_webhook
self.to_xml.to_s
end
-
+
+ def prep_many
+ "#{self.to_xml.to_s}"
+ end
+
def friends_with_permissions
Friend.only(:url).map{|x| x = x.url + "/receive/"}
end
+
+ def self.build_xml_for(posts)
+ xml = ""
+ posts.each {|x| xml << x.prep_many}
+ xml = xml + ""
+ end
end
end
end
diff --git a/spec/helpers/parser_spec.rb b/spec/helpers/parser_spec.rb
new file mode 100644
index 000000000..04c1846b4
--- /dev/null
+++ b/spec/helpers/parser_spec.rb
@@ -0,0 +1,21 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+include ApplicationHelper
+
+describe DashboardHelper do
+ before do
+ Factory.create(:user)
+ end
+
+ it "should store objects sent from xml" do
+ status_messages = []
+ 10.times { status_messages << Factory.build(:status_message)}
+
+ xml = Post.build_xml_for(status_messages)
+
+ store_posts_from_xml(xml)
+ StatusMessage.count.should == 10
+ end
+
+
+end