friend API development

This commit is contained in:
Brian Smith 2012-10-13 22:22:13 -04:00
parent 5d930f96b8
commit 8da4d1a42d
5 changed files with 78 additions and 1 deletions

View File

@ -0,0 +1,48 @@
class ApiUsersController < ApplicationController
before_filter :signed_in_user, only: [:index, :edit, :update, :destroy]
respond_to :json
def index
@users = User.paginate(page: params[:page])
end
def create
@user = User.new()
@user.creator = current_user
@user.description = params[:description]
@user.save
respond_with @user, responder: ApiResponder, :location => api_user_detail_url(@user)
end
def show
@user = User.find(params[:id])
end
def delete
@user = User.find(params[:id])
@user.delete
respond_with @user, responder: ApiResponder
end
def friend_request_index
end
def friend_request_create
end
def friend_index
end
def friend_create
end
def friend_show
end
def friend_destroy
end
end

View File

@ -0,0 +1,3 @@
collection @users
extends "api_users/show"

View File

@ -0,0 +1,7 @@
object @user
attributes :id, :name, :email, :admin
child :friends => :friends do
attributes :id, :name, :online
end

View File

@ -13,7 +13,7 @@ Rabl.configure do |config|
# config.include_bson_root = true
# config.include_plist_root = true
# config.include_xml_root = false
# config.include_child_root = true
config.include_child_root = false
# config.enable_json_callbacks = false
# config.xml_options = { :dasherize => true, :skip_types => false }
# config.view_paths = []

View File

@ -23,6 +23,7 @@ SampleApp::Application.routes.draw do
match '/client', to: 'clients#index'
scope '/api' do
# music sessions
match '/sessions/:id/participants' => 'api_music_sessions#participant_create', :via => :post
match '/participants/:id' => 'api_music_sessions#participant_show', :via => :get, :as => 'api_session_participant_detail'
match '/participants/:id' => 'api_music_sessions#participant_delete', :via => :delete
@ -31,5 +32,23 @@ SampleApp::Application.routes.draw do
match '/sessions' => 'api_music_sessions#index', :via => :get
match '/sessions' => 'api_music_sessions#create', :via => :post
# users
match '/users' => 'api_users#index', :via => :get
match '/users' => 'api_users#create', :via => :post
match '/users/:id' => 'api_users#show', :via => :get, :as => 'api_user_detail'
match '/users/:id' => 'api_users#edit', :via => :put
match '/users/:id' => 'api_users#destroy', :via => :delete
# friend requests
match '/users/:id/friend_requests' => 'api_users#friend_request_index', :via => :get
match '/users/:id/friend_requests' => 'api_users#friend_request_create', :via => :post
match '/users/:id/friends/:friend_request_id' => 'api_users#friend_request_show', :via => :get, :as => 'api_user_friend_request_detail'
match '/users/:id/friends/:friend_request_id' => 'api_users#friend_request_edit', :via => :put
# friends
match '/users/:id/friends' => 'api_users#friend_index', :via => :get
match '/users/:id/friends' => 'api_users#friend_create', :via => :post
match '/users/:id/friends/:friend_id' => 'api_users#friend_show', :via => :get, :as => 'api_user_friend_detail'
match '/users/:id/friends/:friend_id' => 'api_users#friend_destroy', :via => :delete
end
end