Created
August 16, 2012 14:37
-
-
Save danielholmstrom/3370583 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'entry' | |
Safeshare.controllers :entries do | |
get :show, :map => '/entries/:id', :provides => :json, :priority => :low do | |
@entry = Entry[params[:id][1]] | |
error 404 unless @entry | |
# Facebook acl for this post | |
@entry_owner = false | |
if @entry.fb_owner_id | |
error 401 unless @fb_user and @entry.fb_owner_id == @fb_user['id'] | |
@entry_owner = true | |
else | |
error 401 | |
end | |
return @entry.to_json() | |
end | |
put :update, :map => '/entries/:id', :priority => :low, :provides => :json do | |
@entry = Entry[params[:id][1]] | |
error 404 unless @entry | |
# Facebook acl for this post | |
@entry_owner = false | |
if @entry.fb_owner_id | |
error 401 unless @fb_user and @entry.fb_owner_id == @fb_user['id'] | |
@entry_owner = true | |
else | |
error 401 | |
end | |
case content_type | |
when :json then | |
@entry.body = params[:body] | |
@entry.save | |
redirect url(:entries, :show, :id=>@entry.id) | |
end | |
end | |
post :index, :provides => :json do | |
Entry.new do |e| | |
e.type = 'text' | |
e.body = params[:body] | |
e.fb_owner_id = @fb_user['id'] if @fb_user | |
e.save | |
redirect url(:entries, :show, :id=>e.id) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment