Facebook Application Development with Ruby on Rails

4 min read

Technologies needed for this article

RFacebook

RFacebook (http://rfacebook.rubyforge.org/index.html) is a Ruby interface to the Facebook APIs. There are two parts to RFacebook—the gem and the plug-in. The plug-in is a stub that calls RFacebook on the Rails library packaged in the gem. RFacebook on Rails library extends the default Rails controller, model, and view. RFacebook also provides a simple interface through an RFacebook session to call any Facebook API. RFacebook uses some meta-programming idioms in Ruby to call Facebook APIs.

Indeed

Indeed is a job search engine that allows users to search for jobs based on keywords and location. It includes job listings from major job boards and newspapers and even company career pages.

Acquiring candidates through Facebook

We will be creating a Facebook application and displaying it through Facebook. This application, when added into the list of a user’s applications, allows the user to search for jobs using information in his or her Facebook profile. Facebook applications, though displayed within the Facebook interface, are actually hosted and processed somewhere else. To display it within Facebook, you need to host the application in a publicly available website and then register the application. We will go through these steps in creating the Job Board Facebook application.

Creating a Rails application

Next, create a Facebook application. To do this, you will need to first add a special application in your Facebook account—the Developer application. Go to http://www.facebook.com/developers and you will be asked to allow Developer to be installed in your Facebook account.

Add the Developer application and agree to everything in the permissions list.

You will not have any applications yet, so click on the create one link to create a new application. Next you will be asked for the name of the application you want to create. Enter a suitable name; in our case, enter ‘Job Board’ and you will be redirected to the Developer application main page, where you are shown your newly created application with its API key and secret.

You will need the API key and secret in a while.

Installing and configuring RFacebook

RFacebook consists of two components—the gem and the plug-in. The gem contains the libraries needed to communicate with Facebook while the plug-in enables your Rails application to integrate with Facebook. As mentioned earlier, the plug-in is basically a stub to the gem. The gem is installed like any other gem in Ruby:

$gem install rfacebook

To install the plug-in go to your RAILS_ROOT folder and type in:

$./script/plugin install svn://rubyforge.org/var/svn/rfacebook/trunk/rfacebook/plugins/rfacebook

Next, after the gem and plug-in is installed, run a setup rake script to create the configuration file in the RAILS_ROOT folder:

$rake facebook:setup

This creates a facebook.yml configuration file in RAILS_ROOT/config folder. The facebook.yml file contains three environments that mirror the Rails startup environments. Open it up to configure the necessary environment with the API key and secret that you were given when you created the application in the section above.

development:
key: YOUR_API_KEY_HERE
secret: YOUR_API_SECRET_HERE
canvas_path: /yourAppName/
callback_path: /path/to/your/callback/
tunnel:
username: yourLoginName
host: www.yourexternaldomain.com
port: 1234
local_port: 5678

For now, just fill in the API key and secret. In a later section when we configure the rest of the Facebook application, we will need to revisit this configuration.

Extracting the Facebook user profile

Next we want to extract the user’s Facebook user profile and display it on the Facebook application. We do this to let the user confirm that this is the information he or she wants to send as search parameters.

To do this, create a controller named search_controller.rb in the RAILS_ROOT/app/controllers folder.

class SearchController < ApplicationController
before_filter :require_facebook_install
layout 'main'
def index
view
render :action => :view
end
def view
if fbsession.is_valid?
response = fbsession.users_getInfo(:uids =>
[fbsession.session_user_id], :fields =>
["current_location", "education_history",
"work_history"])
@work_history = response.work_history
@education_history = response.education_history
@current_location = response.current_location
end
end
Packt

Share
Published by
Packt

Recent Posts

Top life hacks for prepping for your IT certification exam

I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…

3 years ago

Learn Transformers for Natural Language Processing with Denis Rothman

Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…

3 years ago

Learning Essential Linux Commands for Navigating the Shell Effectively

Once we learn how to deploy an Ubuntu server, how to manage users, and how…

3 years ago

Clean Coding in Python with Mariano Anaya

Key-takeaways:   Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…

3 years ago

Exploring Forms in Angular – types, benefits and differences   

While developing a web application, or setting dynamic pages and meta tags we need to deal with…

3 years ago

Gain Practical Expertise with the Latest Edition of Software Architecture with C# 9 and .NET 5

Software architecture is one of the most discussed topics in the software industry today, and…

3 years ago