Class: LinkedIn

Inherits:
Object
  • Object
show all
Includes:
Searchy
Defined in:
lib/esearchy/SocialNetworks/linkedin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Searchy

#clean, #fix, #hash_url, #maxhits=, #print_emails, #search_depth, #search_docs, #search_emails, #search_office_xml, #search_pdfs, #search_txts

Constructor Details

#initialize(maxhits = 0) ⇒ LinkedIn

Returns a new instance of LinkedIn.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/esearchy/SocialNetworks/linkedin.rb', line 8

def initialize(maxhits = 0)
  @totalhits = maxhits
  @pages = 1
  @emails = []
  @lock = Mutex.new
  @start = 0
  @threads = []
  @lock = Mutex.new
  @username = String.new
  @password = String.new
  @company_name = nil
  @cookie = nil
end

Instance Attribute Details

#company_nameObject

Returns the value of attribute company_name.



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

def company_name
  @company_name
end

#emailsObject

Returns the value of attribute emails.



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

def emails
  @emails
end

#passwordObject

Returns the value of attribute password.



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

def password
  @password
end

#peopleObject

Returns the value of attribute people.



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

def people
  @people
end

#usernameObject

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

#create_emailsObject



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/esearchy/SocialNetworks/linkedin.rb', line 116

def create_emails
  @domain = @query.match(/@/) ? @query : ("@" + @query)
  @people.each do |person|
    name,last = person 
    @emails << "#{name.split(' ')[0]}.#{last.split(' ')[0]}#{@domain}"
    @emails << "#{name[0,1]}#{last.split(' ')[0]}#{@domain}"
    #@emails.concat(fix(search_person(name,last)))
    @emails.uniq!
  end 
  print_emails(@emails)
end

#loginObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/esearchy/SocialNetworks/linkedin.rb', line 23

def 
  begin
    http = Net::HTTP.new("www.linkedin.com",443)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    http.start do |http|
      request = Net::HTTP::Post.new("/secure/login",
                                    {'Content-Type' => "application/x-www-form-urlencoded"})
      request.body = "session_key=#{@username}" +
                     "&session_password=#{@password}" +
                     "&session_login=Sign+In&session_login=&session_rikey="
      response = http.request(request)
      case response
      when Net::HTTPSuccess, Net::HTTPRedirection
        return response['Set-Cookie']
      else
        return response.error!
      end
    end
  rescue Net::HTTPFatalError
    ESearchy::LOG.puts "Error: Something went wrong with the HTTP request"
  end
end

#parse(string) ⇒ Object



95
96
97
# File 'lib/esearchy/SocialNetworks/linkedin.rb', line 95

def parse(string)
  @totalhits = string.scan(/<p class="summary>"<strong>(.*)<\/strong>/) if @totalhits == 0
end

#search(query) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/esearchy/SocialNetworks/linkedin.rb', line 47

def search(query)
  @query = query
  begin 
      @cookie = 
  rescue
    ESearchy::LOG.puts "Unable to parse LinkedIn. Something went Wrong with the Credentials"
    return nil
  end
  begin
    http = Net::HTTP.new("www.linkedin.com",80)
    http.start do |http|
      #request = Net::HTTP::Get.new("/search?search=&viewCriteria=1&currentCompany=co" + 
      #          "&searchLocationType=Y&newnessType=Y" +
      #          "&proposalType=Y&pplSearchOrigin=ADVS&company=#{CGI.escape(@company_name)}" +
      #          "&sortCriteria=Relevance&page_num=#{@pages}", {'Cookie' => @cookie} )
      
      headers = {'Cookie' => @cookie, 'User-Agent' => UserAgent::fetch}
      request = Net::HTTP::Get.new("/search?search=&company=" + 
                                   CGI.escape(@company_name) +
                                   "&currentCompany=currentCompany" + 
                                   "&trk=coprofile_in_network_see_more" + 
                                   "&page_num=" + @pages.to_s, headers)
      response = http.request(request)
      case response
      when Net::HTTPSuccess, Net::HTTPRedirection
        parse(response.body)
        @start = @start + 10
        if @totalhits > @start
          @pages = @pages + 1
          ESearchy::LOG.puts "Searching in: #{self.class} up to point #{@start}"
          search_people(response.body)
          create_emails
          sleep(ESearchy::DELAY)
          search(@query)
        else
          ESearchy::LOG.puts "Searching in: #{self.class} up to point #{@start}"
          search_people(response.body)
          create_emails
        end
      else
        return response.error!
      end
    end
  rescue Net::HTTPFatalError
    ESearchy::LOG.puts "Error: Something went wrong with the HTTP request"
  end
end

#search_people(string) ⇒ Object



99
100
101
102
# File 'lib/esearchy/SocialNetworks/linkedin.rb', line 99

def search_people(string)
  @people = string.scan(/title="View profile">[\n\s]+<span class="given-name">(.*)<\/span>\
[\n\s]+<span class="family-name">(.*)<\/span>/)
end

#search_person(name, last) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/esearchy/SocialNetworks/linkedin.rb', line 103

def search_person(name,last)
  email = []
  # Search Yahoo
  y = Yahoo.new(50)
  y.search("first:\"#{name}\" last:\"#{last}\"")
  emails.concat(y.emails).uniq!
  # Search Google
  #g = Google.new(50)
  #g.search("#{name} #{last}")
  #emails.concat(g.emails).uniq!
  return emails
end