Skip to content
Extraits de code Groupes Projets
Valider 02137b9f rédigé par danielvincent's avatar danielvincent
Parcourir les fichiers

DG MS; receive hook working.

parent ba6d136b
Branches
Étiquettes
Aucune requête de fusion associée trouvée
......@@ -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
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
......@@ -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
module DashboardHelper
end
......@@ -2,6 +2,8 @@ class StatusMessage < Post
include StatusMessagesHelper
require 'lib/net/curl'
xml_name :status_message
xml_accessor :message
field :message
......
......@@ -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
......
......@@ -16,10 +16,20 @@ module Diaspora
def prep_webhook
self.to_xml.to_s
end
def prep_many
"<post>#{self.to_xml.to_s}</post>"
end
def friends_with_permissions
Friend.only(:url).map{|x| x = x.url + "/receive/"}
end
def self.build_xml_for(posts)
xml = "<posts>"
posts.each {|x| xml << x.prep_many}
xml = xml + "</posts>"
end
end
end
end
......
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
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter