Wednesday, 28 August 2013

github_api gem with Rails 4: How to import github user information to your Rails Application

This time i am back with one more API feature to the list , that we can incorporate with the existing Rails 4 Application. github api gem is the Ruby wrapper for the GitHub REST API v3.It supports almost all the API methods provided by Github.



Add gem 'github-api' & gem 'rest-client' to your Gemfile. 'rest-client' gem is a simple HTTP and REST client for Ruby. It will help you to get the response data from github after attaching the access token.

Github Controller

As you all know the basic API authentication and after that returning the user back to the callback method, here also there no much changes in the basic functions .First it will authenticate the user to the github app , after that it will redirect the user back to the callback method that we have specified in the redirect url with an authorization code as params , by using the authorization code returned from the github , we will be able to generate a github client object and we can call the get_token method by passing the authorization code as an argument . It will return the Access token to you . by using the access token you can easily call the Git API link by attaching the access token. It will give you the whole user Repository list as JSON. 

Route File

View file

Linkedin Gem with Rails 4 : How to Import Linkedin user information to your Rails Application

All your Linkedin Information's are now just a mouse click away. by using linkedin gem with Rails we can easily import all your linkedin information's  like your skills , contact details , experience details, education details , project details , connection details etc. Now almost all popular websites mainly working in the Professional Networking platform are providing this feature ,  is my favorite among them , which does the job very brilliant. 



  gem 'linkedin', '0.4.2', :git => "git://"

Linkedin Controller

As you all know the basic authentication and the Callback methods , here also first it will  authenticate the user with the linkedin app . You can specify the user access information here in the Linkedin Configuration .What all user fields that your application want to get access. After Authenticating the user it will redirect the user back to the callback method with oauth_verifier as parmas. you will be able to create Access token and access token secret by using the linkedin client object that we have created using the response parameter.

Once the linkedin Client object creation is done , you will be able to access all the user information's like contact details , skills , education details , experience details etc , All the profile field information's are available at

LinkedIn is very particular about access to profile fields and you cannot combine multiple fields which requires 2 different type of access. so when you try to get just position details by c.profile(:fields => %w(positions)) it assumes the access of type 'r_basicprofile' whereas educations field require access of type 'r_fullprofile'.so try 2 seperate API calls to retrieve both fields.

"first_name","last_name","headline","positions" available for 'r_basicprofile' member permission,so they can be combined together. but "educations", "three_current_positions", "three_past_positions" , "certifications" etc are available in 'r_fullprofile' . So you have to separate the API calls with respect to the requirements.

Route File

View File 

Friday, 19 July 2013

Integrate Dropbox with your Rails App by using Dropbox API gem with Paperclip

We are going to steal all the Dropbox documents by using Dropbox API with the help of Paperclip. Hey got scared !! .. Oh pls ..  just kidding. But seriously ,We can do that with the help of dropbox-api gem & paperclip .

Step 1

Create an App in Dropbox  Developer  to get the key-Secret pair. You have to set the permission type to "Full Dropbox" mode to get the full Read/Write Access to any file inside the user's Dropbox.

Step 2

Setup your Rails App , include these 2 gems in your Gemfile.

gem 'dropbox-api'
gem "paperclip"

Step 3

Create a file in your config/initializers directory and name it dropbox.rb and put the following line of code inside.

Dropbox::API::Config.app_key    = 'APP KEY'
Dropbox::API::Config.app_secret = 'SECRET KEY'
Dropbox::API::Config.mode       = "dropbox"

Wednesday, 8 May 2013

Linkedin Gem for Rails : How to share dynamic contents to Linkedin from your Rails Application

After Facebook & Twitter share ,its time for Linkedin. I would suggest you to refer my 2 prev posts before going through this article.

Include "linkedin" gem in your Gemfile and bundle .

gem 'linkedin'

Route file:

 match '/linkedin_share/auth'   => 'linkedin_share#auth' , :method => :get , :as => :linkedin_auth

 match '/linkedin_share/callback' => 'linkedin_share#callback' , :method => :get , :as =>  :linkedin_callback

Twitter gem for Rails : How to share dynamic contents to Twitter from your Rails Application

Before going through this post . I would suggest you to go through my previous FB share  post. You will get to know the basic functionality & working from the prev post .After that please go through Twitter gem description.

I hope you have gone through the prev post and you have got some idea about it.

Now we will start with Twitter share implementation.You have to include  "twitter" & "oauth" gems into your Gemfile.

gem 'twitter'

gem 'oauth'

Compared to FB share , here we need to include "Oauth" gem for authenticating the user to twitter and redirect the user back to your applications Callback action.After getting the Oauth Secret Key i.e returning from Twitter you can configure the Twitter gem settings and you can post to twitter from your Rails app.

Tuesday, 7 May 2013

Fb Graph Gem for Rails : How to Post dynamic contents to Facebook Wall from your Rails Application

This post will introduce the usage of fb_graph Gem with your existing Rails Application.fb_graph has already done a lot for you guys to exploit the FB API features with your Rails Application , you can have an eye on this fb_graph Gem before going through this post.

Suppose you have a blogger kind of application, and when you compose a new post , you would like to share the same in your Facebook wall, and also would like to give the same option for all the users ,those who liked your post and would like to share the same in their Facebook Wall.

I think now almost all the websites are using this feature to increase their user traffic , to popularize their sites,  Since Facebook turned out to be a great option for advertising and marketing your site content.

One day i also felt the same and after one complete days of effort ..... i was successful.            I thought i should share the same for you guys to reduce your one days effort ( or may be less ) for implementing this FB share option.

I hope i am not boring you , anyway stop to all kind of rubbish introduction and lets start coding ..

Thursday, 17 January 2013

Ruby On Rails: Omniauth Devise Authentication using Facebook , Google & Twitter.

This post is just a simple straightforward description of Omniauth:Overview , intended for the beginners , those who wants to try the OmniAuth for the first time with Facebook , Google & Twitter. This post will cover all the basic information i.e From creating the app in Facebook, Google & Twitter for getting the secret key To connect these Apps to your Rails Application.

Things in common :

add Devise & omniauth gem to your Gemfile.

gem 'omniauth' 
gem 'devise' 

First of all install Devise into your application.
rails generate devise:install  
You have to create user model using devise ,
rails g devise user  
and after that we need to add 2 more columns i.e "uid" and 'provider' to our user model.

rails g migration AddColumnsToUsers provider:string uid:string
rake db:migrate
 also dont forget to add ":provider" and ":uid" to your attr_accessible also.

 We have done with the things that is common in authentication using facebook,Google, Twitter.

 We will start with Facebook Authentication first 

 Facebook Authentication :

 add gem 'omniauth-facebook' to your gem file.

 First of all you need to create an application in facebook to get the secret key out .