Created
August 16, 2012 16:38
-
-
Save danielholmstrom/3371530 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
helpers do | |
def get_entry(id) | |
entry = Entry[id] | |
error 404 unless entry | |
# Facebook acl for this entry | |
if entry.fb_owner_id | |
error 401 unless @fb_user and entry.fb_owner_id == @fb_user['id'] | |
else | |
error 401 | |
end | |
return entry | |
end | |
end | |
get :index, :with => :id, :provides => :json, :priority => :low do | |
return get_entry(params[:id][1]).to_json | |
end | |
put :index, :with => :id, :priority => :low, :provides => :json do | |
e = get_entry(:id) | |
case content_type | |
when :json then | |
e.body = params[:body] | |
e.save | |
redirect url(:entries, :index, :id=>e.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, :index, :id=>e.id) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment