Skip to content

Instantly share code, notes, and snippets.

@hemanth
Forked from tomdepplito/linkedin_parse.rb
Created July 10, 2012 05:03
Show Gist options
  • Save hemanth/3081190 to your computer and use it in GitHub Desktop.
Save hemanth/3081190 to your computer and use it in GitHub Desktop.
Linkedin Parsing Example
require 'oauth'
require 'launchy'
require 'nokogiri'
class User
def authenticate(consumer_key, consumer_secret, site)
consumer = OAuth::Consumer.new(consumer_key, consumer_secret, site)
request_token = consumer.get_request_token
puts "Authorize Follower and then paste in the PIN:"
printf "> "
Launchy.open(request_token.authorize_url)
verification_code = gets.chomp
request_token.get_access_token(:oauth_verifier => verification_code)
end
def follow_linkedin(access_token, email)
path = 'https://api.linkedin.com/v1/people/~/mailbox'
body = "{
\"recipients\": {
\"values\": [
{
\"person\": {
\"_path\": \"/people/email=#{email}\",
\"first-name\":\"\",
\"last-name\":\"\"
}
}
]
},
\"subject\": \"Invitation to connect.\",
\"body\": \"Say yes!\",
\"item-content\":{
\"invitation-request\":{
\"connect-type\":\"friend\"
}
}
}"
access_token.post(path, body, "Content-Type" => "application/json")
end
def get_skills(access_token)
skill_array = []
path = 'http://api.linkedin.com/v1/people/~:(skills)'
result = Nokogiri::XML(access_token.get(path).body)
result.xpath("//skill//name").each { |node| skill_array << node.content }
return skill_array
end
def get_jobs(access_token)
job_array = []
path = 'http://api.linkedin.com/v1/people/~:(positions)'
return access_token.get(path).body
#result = Nokogiri::XML(access_token.get(path).body)
# result.xpath("//skill//name").each { |node| job_array << node.content }
# return job_array
end
def get_specialties(access_token)
specialities_array = []
path = 'http://api.linkedin.com/v1/people/~:(specialties)'
result = Nokogiri::XML(access_token.get(path).body)
result.xpath("//specialties").each { |node| specialities_array << node.content }
return specialities_array.to_s
end
def search_jobs(access_token)
jobs_array = []
path = "http://api.linkedin.com/v1/job-search?job-title=Ruby+Developer&location=San+Francisco+Bay+Area"
result = Nokogiri::XML(access_token.get(path).body)
result.xpath("//facet//name").each { |node| jobs_array << node.content }
return jobs_array.to_s
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment