Skip to content

Instantly share code, notes, and snippets.

View ahmdrefat's full-sized avatar
🏗️
I may be slow to respond.

Ahmed R. Hussein ahmdrefat

🏗️
I may be slow to respond.
View GitHub Profile
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
has_one :basic_profile
has_one :full_profile
has_one :linkedin_oauth_setting
belongs_to :user
<h1>Linkedin Application</h1>
<a href="/linkedin_oauth_url" class="btn btn-primary btn-larg">Connect to LinkedIn</a>
<li><%= link_to current_user.email, "/users/edit" %></li>
<li><%= link_to "Sign out", "/users/sign_out", :method => "DELETE" %></li>
resources :linkedin
match '/linkedin_profile'
match '/oauth_account' => "linkedin#oauth_account"
match '/linkedin_oauth_url' => 'linkedin#generate_linkedin_oauth_url'
root :to => 'linkedin#index'
def linkedin_profile
basic_profile = get_basic_profile
full_profile = get_full_profile
positions = get_positions
educations = get_educations
end
def index
unless LinkedinOauthSetting.find_by_user_id(current_user.id).nil?
redirect_to "/linkedin_profile"
end
end
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
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