Skip to content

Commit

Permalink
updated doc
Browse files Browse the repository at this point in the history
  • Loading branch information
pomartel authored and mmangino committed Mar 11, 2011
1 parent 018745a commit 2325135
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 37 deletions.
32 changes: 15 additions & 17 deletions README.md
Expand Up @@ -8,38 +8,37 @@ Requires the mogli gem.


Example
=======
-------

0. Prerequisite: You need a facebook app. Have your API Key, Application
0- Prerequisite: You need a facebook app. Have your API Key, Application
Secret, and Application ID handy.

1. Install facebooker2 as a plugin in your rails app.
1- Install facebooker2 as a plugin in your rails app.

2. Create `config/facebooker.yml` with the appropriate environment.
2- Create `config/facebooker.yml` with the appropriate environment.

production:
app_id: <your application id>
secret: <your application secret>
api_key: <your application key>

3. Create `config/initializers/facebooker2.rb` and place the following line in it
3- Create `config/initializers/facebooker2.rb` and place the following line in it

Facebooker2.load_facebooker_yaml

4. Add the following line to your `app/controllers/application_controller.rb`
4- Add the following line to your `app/controllers/application_controller.rb`
(add it right after the line class `ApplicationController < ActionController::Base` so as to add the Facebooker2 instance methods to the Application controller)

include Facebooker2::Rails::Controller
include Facebooker2::Rails::Controller

5. Update your rails applications to use the rails helpers. This could be in a
5- Update your rails applications to use the rails helpers. This could be in a
shared login partial.

<%= fb_connect_async_js %>
<% if current_facebook_user %>
<%= "Welcome #{current_facebook_user.first_name} #{current_facebook_user.last_name}!" %>
or
<%= "Hello #{fb_name(current_facebook_user, :useyou => false)}!" # link to facebook profile
%>
<%= "Welcome #{current_facebook_user.first_name} #{current_facebook_user.last_name}!" %>
or
<%= "Hello #{fb_name(current_facebook_user, :useyou => false)}!" # link to facebook profile %>
<%= fb_logout_link("Logout of fb", request.url) %><br />
<% else
# you must explicitly request permissions for facebook user fields.
Expand All @@ -49,21 +48,20 @@ shared login partial.
<%= fb_login_and_redirect('<your URL here>', :perms => 'email,user_birthday') %>
<% end %>


Facebook canvas applications
============================
----------------------------

If you are building an application that runs inside a Facebook canvas, all the coming requests from Facebook to your iframe will
be [POST requests](http://developers.facebook.com/docs/canvas/post/).

You can use the PostCanvas rack middleware to turn the Facebook POST requests back to GET requests.
You can use the PostCanvas rack middleware to turn the Facebook POST requests back to GET requests and keep your app restful
as described in [this blog post](http://blog.coderubik.com/?p=178).
If you are using Rails 3, put this line of code inside your `config.ru` file :

use Rack::PostCanvas


Contributing
============
------------

Unit tests use rspec and require the following environment configuration to run:
rails 2.3.10
Expand Down
3 changes: 2 additions & 1 deletion lib/facebooker2.rb
Expand Up @@ -47,4 +47,5 @@ def self.cast_to_facebook_id(object)
require "facebooker2/rails/helpers/javascript"
require "facebooker2/rails/helpers/request_forms"
require "facebooker2/rails/helpers/user"
require "facebooker2/rails/helpers"
require "facebooker2/rails/helpers"
require "facebooker2/rack/post_canvas"
19 changes: 0 additions & 19 deletions lib/facebooker2/rack/PostCanvas.rb

This file was deleted.

23 changes: 23 additions & 0 deletions lib/facebooker2/rack/post_canvas.rb
@@ -0,0 +1,23 @@
# Rack middleware that converts POST requests from Facebook to GET request.
# When there is a signed_parameter in the request params, this is a request iniated by the top Facebook frame
# It will be sent as a POST request that we want to convert to a GET request to keep the app restful
# See for details : http://blog.coderubik.com/?p=178
module Rack
class PostCanvas

def initialize(app)
@app = app
end

def call(env)
request = Request.new(env)

if request.POST['signed_request']
env["REQUEST_METHOD"] = 'GET'
end

return @app.call(env)
end

end
end

0 comments on commit 2325135

Please sign in to comment.