Class: LinkedinScraper::Linkedin

Inherits:
Object
  • Object
show all
Defined in:
lib/linkedin/linkedin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLinkedin

Initializes mechnaize



42
43
44
# File 'lib/linkedin/linkedin.rb', line 42

def initialize
  @agent = Mechanize.new { |agent| agent.user_agent_alias = USER_AGENTS.sample }
end

Instance Attribute Details

#connectionObject

Total number of profile’s connection e.g “44”



21
22
23
# File 'lib/linkedin/linkedin.rb', line 21

def connection
  @connection
end

#contact_forObject

Purposes for which profile can be contacted to (if provided)



37
38
39
# File 'lib/linkedin/linkedin.rb', line 37

def contact_for
  @contact_for
end

#current_companyObject

Current company of profile e.g “Pajama Labs”



15
16
17
# File 'lib/linkedin/linkedin.rb', line 15

def current_company
  @current_company
end

#current_job_descriptionObject

Current job description as available on linkedin



17
18
19
# File 'lib/linkedin/linkedin.rb', line 17

def current_job_description
  @current_job_description
end

#current_titleObject

Current title of profile e.g “Ceo”



11
12
13
# File 'lib/linkedin/linkedin.rb', line 11

def current_title
  @current_title
end

#educationObject

Schools profile has attended



35
36
37
# File 'lib/linkedin/linkedin.rb', line 35

def education
  @education
end

#experienceObject

Experience description if mentioned



29
30
31
# File 'lib/linkedin/linkedin.rb', line 29

def experience
  @experience
end

#full_nameObject

Full name of profile e.g “John Smith”



7
8
9
# File 'lib/linkedin/linkedin.rb', line 7

def full_name
  @full_name
end

#groupsObject

Groups a profile is associated with



31
32
33
# File 'lib/linkedin/linkedin.rb', line 31

def groups
  @groups
end

#industryObject

All companies including current and past



27
28
29
# File 'lib/linkedin/linkedin.rb', line 27

def industry
  @industry
end

#linkedin_urlObject

Linkedin url of profile e.g “www.linkedin.com/pub/in/john+smith



9
10
11
# File 'lib/linkedin/linkedin.rb', line 9

def linkedin_url
  @linkedin_url
end

#locationObject

Current location of profile “San Fransisco”



23
24
25
# File 'lib/linkedin/linkedin.rb', line 23

def location
  @location
end

#past_companyObject

Past companies of profile e.g “Google, Inc”



33
34
35
# File 'lib/linkedin/linkedin.rb', line 33

def past_company
  @past_company
end

#past_titleObject

Past title of profile e.g “VP Business”



13
14
15
# File 'lib/linkedin/linkedin.rb', line 13

def past_title
  @past_title
end

#recommendationObject

Total number of profile’s recommendation e.g “44”



25
26
27
# File 'lib/linkedin/linkedin.rb', line 25

def recommendation
  @recommendation
end

#summaryObject

Profile’s summary as available on linkedin



19
20
21
# File 'lib/linkedin/linkedin.rb', line 19

def summary
  @summary
end

#websitesObject

Websites associated with Profile



39
40
41
# File 'lib/linkedin/linkedin.rb', line 39

def websites
  @websites
end

Instance Method Details

#data(page) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/linkedin/linkedin.rb', line 77

def data page
  self.full_name = li_full_name(page)
  self.linkedin_url = page.uri.to_s
  self.current_title = li_current_title(page)
  self.past_title = li_past_title(page)
  self.current_company = li_current_companies(page)
  self.current_job_description = li_current_job_description(page)
  self.summary = li_summary(page)
  self.connection = li_connection(page)
  self.location = li_location(page)
  self.recommendation = li_recommendation(page)
  self.industry =  li_current_companies(page) + li_past_companies(page)
  self.experience = li_experience(page)
  self.groups = li_groups(page)
  self.past_company = li_past_companies(page)
  self.education = li_education(page)
  self.contact_for = li_contact_for(page)
  self.websites = li_websites(page)
end

#get_profile_data(options) ⇒ Object

Get data of the required profile

options contains the key :name *Required :name - name of profile/contact e.g “John Smith” options contains the key :company *Required :company - current or past company of profile/contact e.g “Google” options contains the key :country *Optional (see list of supported countries in Readme) :country - preferred country of profile to be found in

Raises error if profile is not found or does not exist in linkedin or is not public profile Raises error if :name or :company or both are not defined Returns self

Raises:

  • ("TypeError")


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/linkedin/linkedin.rb', line 58

def get_profile_data options
  @options = options
  raise "TypeError", "Invalid Arguments" unless options.is_a?(Hash) 
  argument_error("name") unless options.has_key?(:name) 
  argument_error("company") unless options.has_key?(:company) 
  query = build_query
  duck = LinkedinScraper::DuckDuckGo.new(query: query)
  results = duck.search
  raise "No Profile, Profile not found or does not exist" if results.empty?
  page = get_li_page(results[0])
  raise "No Profile, Profile not found or does not exist" unless page
  if verify_profile(@options[:name], @options[:company], page)
    self.data page
    return self
  else
    raise "No Profile, Profile not found or does not exist"
  end
end