Bookmark now consumes cubbi.es JSON, cubbi.es things can be saved to Diaspora, but are not displayed.
This commit is contained in:
parent
be662a65c6
commit
9b941e6520
6 changed files with 143 additions and 1 deletions
55
app/controllers/bookmarks_controller.rb
Normal file
55
app/controllers/bookmarks_controller.rb
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
class BookmarksController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
skip_before_filter :verify_authenticity_token
|
||||
|
||||
respond_to :json
|
||||
|
||||
def create
|
||||
@bookmark = Bookmark.from_activity(params[:activity])
|
||||
@bookmark.author = current_user.person
|
||||
|
||||
if @bookmark.save
|
||||
Rails.logger.info("event=create type=bookmark")
|
||||
|
||||
current_user.add_to_streams(@bookmark, current_user.aspects)
|
||||
current_user.dispatch_post(@bookmark, :url => post_url(@bookmark))
|
||||
|
||||
render :nothing => true, :status => 201
|
||||
end
|
||||
end
|
||||
|
||||
=begin
|
||||
def destroy
|
||||
if @bookmark = current_user.posts.where(:id => params[:id]).first
|
||||
current_user.retract(@bookmark)
|
||||
else
|
||||
Rails.logger.info "event=post_destroy status=failure user=#{current_user.diaspora_handle} reason='User does not own post'"
|
||||
render :nothing => true, :status => 404
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@status_message = current_user.find_visible_post_by_id params[:id]
|
||||
if @status_message
|
||||
@object_aspect_ids = @status_message.aspects.map{|a| a.id}
|
||||
|
||||
# mark corresponding notification as read
|
||||
if notification = Notification.where(:recipient_id => current_user.id, :target_id => @status_message.id).first
|
||||
notification.unread = false
|
||||
notification.save
|
||||
end
|
||||
|
||||
respond_with @status_message
|
||||
else
|
||||
Rails.logger.info(:event => :link_to_nonexistent_post, :ref => request.env['HTTP_REFERER'], :user_id => current_user.id, :post_id => params[:id])
|
||||
flash[:error] = I18n.t('status_messages.show.not_found')
|
||||
redirect_to :back
|
||||
end
|
||||
end
|
||||
=end
|
||||
|
||||
end
|
||||
31
app/models/bookmark.rb
Normal file
31
app/models/bookmark.rb
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
class Bookmark < Post
|
||||
include Diaspora::Socketable
|
||||
|
||||
validates_presence_of :target_url
|
||||
|
||||
|
||||
def socket_to_user(user_or_id, opts={}) #adds aspect_ids to opts if they are not there
|
||||
unless opts[:aspect_ids]
|
||||
user_id = user_or_id.instance_of?(Fixnum) ? user_or_id : user_or_id.id
|
||||
aspect_ids = AspectMembership.connection.execute(
|
||||
AspectMembership.joins(:contact).where(:contacts => {:user_id => user_id, :person_id => self.author_id}).select('aspect_memberships.aspect_id').to_sql
|
||||
).map{|r| r.first}
|
||||
opts.merge!(:aspect_ids => aspect_ids)
|
||||
end
|
||||
super(user_or_id, opts)
|
||||
end
|
||||
|
||||
def self.from_activity(json)
|
||||
self.new(
|
||||
:image_url => json["target"]["image"]["url"],
|
||||
:image_height => json["target"]["image"]["height"],
|
||||
:image_width => json["target"]["image"]["width"],
|
||||
:target_url => json["target"]["url"]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -63,6 +63,7 @@ Diaspora::Application.routes.draw do
|
|||
# generating a new user token (for devise)
|
||||
match 'users/generate_new_token' => 'users#generate_new_token'
|
||||
|
||||
resources :bookmarks, :only => :create
|
||||
|
||||
|
||||
get 'login' => redirect('/users/sign_in')
|
||||
|
|
|
|||
15
db/migrate/20110518222303_add_column_for_bookmark.rb
Normal file
15
db/migrate/20110518222303_add_column_for_bookmark.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
class AddColumnForBookmark < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column(:posts, :target_url, :string)
|
||||
add_column(:posts, :image_url, :string)
|
||||
add_column(:posts, :image_height, :integer)
|
||||
add_column(:posts, :image_width, :integer)
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column(:posts, :image_width)
|
||||
remove_column(:posts, :image_height)
|
||||
remove_column(:posts, :image_url)
|
||||
remove_column(:posts, :target_url)
|
||||
end
|
||||
end
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20110518184453) do
|
||||
ActiveRecord::Schema.define(:version => 20110518222303) do
|
||||
|
||||
create_table "aspect_memberships", :force => true do |t|
|
||||
t.integer "aspect_id", :null => false
|
||||
|
|
@ -242,6 +242,10 @@ ActiveRecord::Schema.define(:version => 20110518184453) do
|
|||
t.datetime "updated_at"
|
||||
t.string "mongo_id"
|
||||
t.string "unprocessed_image"
|
||||
t.string "target_url"
|
||||
t.string "image_url"
|
||||
t.integer "image_height"
|
||||
t.integer "image_width"
|
||||
end
|
||||
|
||||
add_index "posts", ["author_id"], :name => "index_posts_on_person_id"
|
||||
|
|
|
|||
36
spec/models/bookmark_spec.rb
Normal file
36
spec/models/bookmark_spec.rb
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Bookmark do
|
||||
describe '.from_activity' do
|
||||
before do
|
||||
@json = {
|
||||
"verb"=>"save",
|
||||
"target"=> {
|
||||
"url"=>"http://abcnews.go.com/US/wireStory?id=13630884",
|
||||
"objectType"=>"photo",
|
||||
"image"=> {
|
||||
"url"=> "http://a.abcnews.com/images/Entertainment/abc_ann_wtb_blake_leo_110518_wl.jpg",
|
||||
"height"=>"112",
|
||||
"width"=>"200"
|
||||
}
|
||||
},
|
||||
"object"=> {
|
||||
"url"=>"cubbi.es/daniel",
|
||||
"objectType"=>"bookmark"
|
||||
}
|
||||
}
|
||||
end
|
||||
it 'marshals into a bookmark' do
|
||||
bookmark = Bookmark.from_activity(@json)
|
||||
bookmark.image_url.should == @json["target"]["image"]["url"]
|
||||
bookmark.image_height.should == @json["target"]["image"]["height"].to_i
|
||||
bookmark.image_width.should == @json["target"]["image"]["width"].to_i
|
||||
bookmark.target_url.should == @json["target"]["url"]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue