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