Created
July 17, 2013 19:55
-
-
Save dbarrionuevo/6023895 to your computer and use it in GitHub Desktop.
LinkedIn Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
class ConexionesController < ApplicationController | |
def linkedin | |
client = LinkedIn::Client.new(ENV['LINKEDIN_API_KEY'], ENV['LINKEDIN_SECRET'], {:request_token_path => '/uas/oauth/requestToken?scope=r_fullprofile+r_emailaddress'}) | |
request_token = client.request_token(:oauth_callback => "http://#{request.host_with_port}/conexiones/callback") | |
session[:rtoken] = request_token.token | |
session[:rsecret] = request_token.secret | |
redirect_to client.request_token.authorize_url | |
end | |
def callback | |
client = LinkedIn::Client.new(ENV['LINKEDIN_API_KEY'], ENV['LINKEDIN_SECRET']) | |
if session[:atoken].nil? | |
pin = params[:oauth_verifier] | |
atoken, asecret = client.authorize_from_request(session[:rtoken], session[:rsecret], pin) | |
session[:atoken] = atoken | |
session[:asecret] = asecret | |
else | |
client.authorize_from_access(session[:atoken], session[:asecret]) | |
end | |
profile = client.profile(fields: %w(email-address educations positions)) | |
current_usuario.importar_positions(profile) | |
redirect_to current_usuario, notice: "Importación Realizada exitosamente" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment