Permalink
Browse files

facebook api!

  • Loading branch information...
1 parent 3626a46 commit 8114475d3439c976026ef84ef30a32aae4d8243c @bavardage committed Aug 21, 2011
Showing with 31 additions and 1 deletion.
  1. +2 −0 Gemfile
  2. +14 −0 Gemfile.lock
  3. +1 −0 app/controllers/sessions_controller.rb
  4. +6 −0 app/controllers/users_controller.rb
  5. +5 −0 app/models/user.rb
  6. +3 −1 config/routes.rb
View
@@ -11,6 +11,8 @@ gem 'jquery-rails', '>= 1.0.12'
gem "nested_form"
+gem "fb_graph"
+
# Use unicorn as the web server
# gem 'unicorn'
View
@@ -30,17 +30,23 @@ GEM
activesupport (3.0.9)
addressable (2.2.4)
arel (2.0.10)
+ attr_required (0.0.3)
builder (2.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
faraday (0.6.1)
addressable (~> 2.2.4)
multipart-post (~> 1.1.0)
rack (< 2, >= 1.1.0)
+ fb_graph (1.9.5)
+ httpclient (>= 2.2.0.2)
+ rack-oauth2 (>= 0.8.0)
+ httpclient (2.2.1)
i18n (0.5.0)
jquery-rails (1.0.13)
railties (~> 3.0)
thor (~> 0.14)
+ json (1.5.3)
mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
@@ -95,6 +101,13 @@ GEM
rack (1.2.3)
rack-mount (0.6.14)
rack (>= 1.0.0)
+ rack-oauth2 (0.9.2)
+ activesupport (>= 2.3)
+ attr_required (>= 0.0.3)
+ httpclient (>= 2.2.0.2)
+ i18n
+ json (>= 1.4.3)
+ rack (>= 1.1)
rack-openid (1.3.1)
rack (>= 1.1.0)
ruby-openid (>= 2.1.8)
@@ -133,6 +146,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ fb_graph
jquery-rails (>= 1.0.12)
nested_form
omniauth
@@ -4,6 +4,7 @@ def create
auth = request.env["omniauth.auth"]
user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) || User.create_with_omniauth(auth)
session[:user_id] = user.id
+ session[:token] = auth["credentials"]["token"]
redirect_to user_path(user), :notice => "Signed in!"
end
@@ -11,4 +11,10 @@ def show
end
end
+ def facebook_friends
+ respond_to do |format|
+ format.json { render :json => current_user.facebook_user(session[:token]).friends }
+ end
+ end
+
end
View
@@ -37,4 +37,9 @@ def has_role(wall, role)
:wall_id => wall,
:user_id => self}})
end
+
+ def facebook_user(token)
+ FbGraph::User.me(token)
+ end
+
end
View
@@ -3,7 +3,9 @@
match "/signout" => "sessions#destroy", :as => :signout
- resources :users
+ resources :users do
+ member { get 'facebook_friends' }
+ end
resources :walls do
resources :quotes

0 comments on commit 8114475

Please sign in to comment.