Permalink
Browse files

Add complete users API

  • Loading branch information...
1 parent 45516da commit 557253bf18d58c564170219b857b872441f95279 Rich Daley committed Jul 28, 2012
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
+// Place all the styles related to the Api::Choices controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,3 @@
+// Place all the styles related to the Api::Users controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,2 @@
+class Api::ChoicesController < ApplicationController
+end
@@ -0,0 +1,19 @@
+class Api::UsersController < ApplicationController
+
+ def index
+ render :json => User.all.collect {|u| u.for_api}
+ end
+
+ def show
+ render :json => User.find(params[:id]).for_api
+ end
+
+ def me
+ if current_user
+ render :json => current_user.for_api
+ else
+ render :json => {:error => 'please log in'}, :status => :unauthorized
+ end
+ end
+
+end
@@ -11,6 +11,7 @@ def create
:uid => auth['uid']).first || User.create_with_omniauth(auth)
# Update avatar
user.avatar_url = auth['info']['image']
+ user.position = 0
user.save!
session[:user_id] = user.id
if user.email.blank?
@@ -0,0 +1,2 @@
+module Api::ChoicesHelper
+end
@@ -0,0 +1,2 @@
+module Api::UsersHelper
+end
View
@@ -12,4 +12,12 @@ def self.create_with_omniauth(auth)
end
end
+ def for_api
+ {
+ :id => self.id,
+ :avatar_url => self.avatar_url,
+ :position => self.position
+ }
+ end
+
end
View
@@ -5,4 +5,12 @@
match '/signin' => 'sessions#new', :as => :signin
match '/signout' => 'sessions#destroy', :as => :signout
match '/auth/failure' => 'sessions#failure'
+
+ namespace :api do
+ resources :users, :only => [:index, :show, :update] do
+ get 'me', :on => :collection
+ end
+ resources :choices, :only => [:new, :update]
+ end
+
end
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class Api::ChoicesControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class Api::UsersControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class Api::ChoicesHelperTest < ActionView::TestCase
+end
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class Api::UsersHelperTest < ActionView::TestCase
+end

0 comments on commit 557253b

Please sign in to comment.