DG MS; receive hook working.
This commit is contained in:
parent
ba6d136bc7
commit
02137b9fb9
8 changed files with 64 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,2 +1,7 @@
|
|||
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
|
||||
|
|
|
|||
21
spec/helpers/parser_spec.rb
Normal file
21
spec/helpers/parser_spec.rb
Normal file
|
|
@ -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
|
||||
Loading…
Reference in a new issue