Class: LinkedinData
- Inherits:
-
Object
- Object
- LinkedinData
- Includes:
- GetRelated, Linkedin, ParseProfile
- Defined in:
- lib/linkedindata.rb
Instance Method Summary collapse
-
#getByKeywords(search_term) ⇒ Object
Gets all profiles in search results and returns in JSON.
-
#getSingleProfile(url) ⇒ Object
Gets one profile and the related profiles.
-
#initialize(todegree, proxylist) ⇒ LinkedinData
constructor
A new instance of LinkedinData.
-
#prepareResults ⇒ Object
Gets related profiles then adds relevance scores and any missing keys.
-
#scrape(url, curhops) ⇒ Object
Scrapes and parses individual profile.
-
#search(search_terms) ⇒ Object
Searches for profiles on Google.
-
#showAllKeys(data) ⇒ Object
Make sure all keys that occur occur in each item (even if nil).
Methods included from ParseProfile
#addPersonFields, #deleteDuplicatePics, #parseResume
Methods included from GetRelated
#addPointsToProfile, #downloadRelated, #fullProfileList, #getList, #getRelatedProfiles, #relScore
Constructor Details
#initialize(todegree, proxylist) ⇒ LinkedinData
Returns a new instance of LinkedinData.
16 17 18 19 20 21 22 23 |
# File 'lib/linkedindata.rb', line 16 def initialize(todegree, proxylist) @proxylist = IO.readlines(proxylist) @proxy_list_path = proxylist @usedproxies = Hash.new @output = Array.new @startindex = 10 @numhops = todegree end |
Instance Method Details
#getByKeywords(search_term) ⇒ Object
Gets all profiles in search results and returns in JSON
83 84 85 86 |
# File 'lib/linkedindata.rb', line 83 def getByKeywords(search_term) search(search_term) return prepareResults end |
#getSingleProfile(url) ⇒ Object
Gets one profile and the related profiles
77 78 79 80 |
# File 'lib/linkedindata.rb', line 77 def getSingleProfile(url) scrape(url, 0) return prepareResults end |
#prepareResults ⇒ Object
Gets related profiles then adds relevance scores and any missing keys
70 71 72 73 74 |
# File 'lib/linkedindata.rb', line 70 def prepareResults deleteDuplicatePics return JSON.pretty_generate(relScore(showAllKeys(@output))) end |
#scrape(url, curhops) ⇒ Object
Scrapes and parses individual profile
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/linkedindata.rb', line 34 def scrape(url, curhops) # Download profile and rescue on error begin url.gsub!("https", "http") profile = Linkedin::Profile.get_profile(url, curhops, @proxylist, @usedproxies) # Parse profile if returned and add to output @output.concat(parseResume(profile)) if profile rescue end end |
#search(search_terms) ⇒ Object
Searches for profiles on Google
26 27 28 29 30 31 |
# File 'lib/linkedindata.rb', line 26 def search(search_terms) g = GeneralScraper.new("site:linkedin.com/pub", search_terms, @proxy_list_path) JSON.parse(g.getURLs).each do |profile| scrape(profile, 0) end end |
#showAllKeys(data) ⇒ Object
Make sure all keys that occur occur in each item (even if nil)
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/linkedindata.rb', line 47 def showAllKeys(data) # Get all keys fields = Set.new data.map { |o| fields.merge(o.keys) } # Make sure all items have all keys datarr = Array.new data.each do |d| temphash = Hash.new fields.each do |f| if !d[f] temphash[f] = nil else temphash[f] = d[f] end end datarr.push(temphash) end return datarr end |