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
def get_basic_profile | |
bprofile = BasicProfile.find_by_user_id(current_user.id) | |
if bprofile.nil? | |
client = get_client | |
profile = client.profile(:fields => ["first-name", "last-name", "maiden-name", "formatted-name" ,:headline, :location, :industry, :summary, :specialties, "picture-url", "public-profile-url"]) | |
basic_profile = profile.to_hash | |
basic_profile[:location] = basic_profile["location"]["name"] | |
new_basic_profile = BasicProfile.new(basic_profile) | |
new_basic_profile.user = current_user |
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
has_one :basic_profile | |
has_one :full_profile | |
has_one :linkedin_oauth_setting |
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
belongs_to :user |
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
<h1>Linkedin Application</h1> | |
<a href="/linkedin_oauth_url" class="btn btn-primary btn-larg">Connect to LinkedIn</a> |
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
<li><%= link_to current_user.email, "/users/edit" %></li> | |
<li><%= link_to "Sign out", "/users/sign_out", :method => "DELETE" %></li> |
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
resources :linkedin | |
match '/linkedin_profile' | |
match '/oauth_account' => "linkedin#oauth_account" | |
match '/linkedin_oauth_url' => 'linkedin#generate_linkedin_oauth_url' | |
root :to => 'linkedin#index' |
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
def linkedin_profile | |
basic_profile = get_basic_profile | |
full_profile = get_full_profile | |
positions = get_positions | |
educations = get_educations | |
end |
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
def index | |
unless LinkedinOauthSetting.find_by_user_id(current_user.id).nil? | |
redirect_to "/linkedin_profile" | |
end | |
end |
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
def get_client | |
linkedin_oauth_setting = LinkedinOauthSetting.find_by_user_id(current_user.id) | |
client = LinkedIn::Client.new('iv6uehul4g5m', 'wtMfG2MbFerSULTC', @@config) | |
client.authorize_from_access(linkedin_oauth_setting.atoken, linkedin_oauth_setting.asecret) | |
client | |
end |
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
def oauth_account | |
client = LinkedIn::Client.new('your-api-key', 'your-secret-key', @@config) | |
pin = params[:oauth_verifier] | |
if pin | |
atoken, asecret = client.authorize_from_request(session[:rtoken], session[:rsecret], pin) | |
LinkedinOauthSetting.create!(:asecret => asecret, :atoken => atoken, :user_id => current_user.id) | |
end | |
redirect_to "/" | |
end |