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.

Refs
  https://github.com/peter-murach/github
  https://github.com/rest-client/rest-client

Gemfile

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 , http://careers.stackoverflow.com/  is my favorite among them , which does the job very brilliant. 

Refs

  https://github.com/pengwynn/linkedin
  http://developer.linkedin.com/documents/profile-fields
  https://gist.github.com/sreeharikmarar/6364970

Gemfile

  gem 'linkedin', '0.4.2', :git => "git://github.com/pengwynn/linkedin.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 http://developer.linkedin.com/documents/profile-fields


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