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
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -2,10 +2,5 @@ class ApplicationController < ActionController::Base ...@@ -2,10 +2,5 @@ class ApplicationController < ActionController::Base
protect_from_forgery :except => :receive protect_from_forgery :except => :receive
layout 'application' layout 'application'
def receive
puts params.inspect
puts "holy boner batman"
render :nothing => true
end
end end
class DashboardController < ApplicationController class DashboardController < ApplicationController
before_filter :authenticate_user!
before_filter :authenticate_user!, :except => :receive
include ApplicationHelper
def index def index
@posts = Post.stream @posts = Post.stream
end end
def receive
store_posts_from_xml (params[:xml])
puts "holy boner batman"
render :nothing => true
end
end end
...@@ -6,4 +6,15 @@ module ApplicationHelper ...@@ -6,4 +6,15 @@ module ApplicationHelper
def object_fields(object) def object_fields(object)
object.attributes.keys object.attributes.keys
end 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 end
module DashboardHelper module DashboardHelper
end end
...@@ -2,6 +2,8 @@ class StatusMessage < Post ...@@ -2,6 +2,8 @@ class StatusMessage < Post
include StatusMessagesHelper include StatusMessagesHelper
require 'lib/net/curl' require 'lib/net/curl'
xml_name :status_message
xml_accessor :message xml_accessor :message
field :message field :message
......
...@@ -14,7 +14,7 @@ Diaspora::Application.routes.draw do |map| ...@@ -14,7 +14,7 @@ Diaspora::Application.routes.draw do |map|
match 'logout', :to => 'devise/sessions#destroy', :as => "destroy_user_session" match 'logout', :to => 'devise/sessions#destroy', :as => "destroy_user_session"
match 'signup', :to => 'devise/registrations#new', :as => "new_user_registration" match 'signup', :to => 'devise/registrations#new', :as => "new_user_registration"
match 'receive', :to => 'application#receive' match 'receive', :to => 'dashboard#receive'
resources :users resources :users
resources :status_messages resources :status_messages
......
...@@ -16,10 +16,20 @@ module Diaspora ...@@ -16,10 +16,20 @@ module Diaspora
def prep_webhook def prep_webhook
self.to_xml.to_s self.to_xml.to_s
end end
def prep_many
"<post>#{self.to_xml.to_s}</post>"
end
def friends_with_permissions def friends_with_permissions
Friend.only(:url).map{|x| x = x.url + "/receive/"} Friend.only(:url).map{|x| x = x.url + "/receive/"}
end end
def self.build_xml_for(posts)
xml = "<posts>"
posts.each {|x| xml << x.prep_many}
xml = xml + "</posts>"
end
end end
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.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter