Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Two Examples of methods that parse data from LinkedIn in order to get the Job and Education information for a user.
def linkedin
@user=current_user
client = LinkedIn::Client.new("API Key", "Secret Key")
client.authorize_from_access(current_user.link_token, current_user.link_secret)
#breakdown LinkedIn Hash into pieces in order to obtain data
@profile = client.profile
@school = client.profile(:fields => %w(educations))
@schools = @school.educations.all.map{|t| t}
@schools.each do |s|
@edate = s.end_date.map{|t,x| x}
@sdate = s.start_date.map{|t, x| x}
#Use information from LinkedIn and assign values to education attributes
ed = @user.educations.build(school_name: s.school_name, degree: s.degree,
field_of_study: s.field_of_study, start_date: @sdate[0],
end_date: @edate[0])
ed.save!
end
flash[:success] = "Your Schools have been successfully imported"
redirect_to @user
end
def linkedin
@user=current_user
client = LinkedIn::Client.new("API Key", "Secret Key")
client.authorize_from_access(current_user.link_tok, current_user.link_sec)
#breakdown LinkedIn Hash into pieces in order to obtain data
@profile = client.profile
@job = client.profile(:fields => %w(positions))
@jobs = @job.positions.all.map{|t| t}
@jobs.each do |s|
#Format Dates from Hashes.
if s.end_date.present?
@edate = s.end_date.map{|t, v| v}
@edate = @edate.join('/')
else
#If end date is not present then it is the users current job.
@edate = "Current"
end
@sdate = s.start_date.map{|t, v| v}
#using data parsed from linkedin hash set variables for job
jb = @user.jobs.build(title: s.title, summary: s.summary, company: s.company.name,
start_date: @sdate.join('/'), end_date: @edate)
jb.save!
end
flash[:success] = "Your Jobs have been successfully imported"
redirect_to @user
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment