Class: Linkedin::Topcompanies::LinkedInScraper

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ LinkedInScraper

Returns a new instance of LinkedInScraper.



11
12
13
14
15
16
17
18
# File 'lib/linkedin-topcompanies.rb', line 11

def initialize(args)
  @keywords   = args.fetch(:keywords)
  @postalcode = args.fetch(:postalcode)
  @industry   = args.fetch(:industry)

  @linkedin_user     = args.fetch(:linkedin_user, ENV['LINKEDIN_USER'])
  @linkedin_password = args.fetch(:linkedin_password, ENV['LINKEDIN_PASSWORD'])
end

Instance Attribute Details

#industryObject (readonly)

Returns the value of attribute industry.



8
9
10
# File 'lib/linkedin-topcompanies.rb', line 8

def industry
  @industry
end

#keywordsObject (readonly)

Returns the value of attribute keywords.



8
9
10
# File 'lib/linkedin-topcompanies.rb', line 8

def keywords
  @keywords
end

#linkedin_passwordObject (readonly)

Returns the value of attribute linkedin_password.



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

def linkedin_password
  @linkedin_password
end

#linkedin_userObject (readonly)

Returns the value of attribute linkedin_user.



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

def linkedin_user
  @linkedin_user
end

#postalcodeObject (readonly)

Returns the value of attribute postalcode.



8
9
10
# File 'lib/linkedin-topcompanies.rb', line 8

def postalcode
  @postalcode
end

Instance Method Details

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/linkedin-topcompanies.rb', line 20

def run
  path        = File.expand_path("../js", File.dirname(__FILE__))
  script      = File.join(path, "linkedin.js")
  credentials = "LINKEDIN_USER='#{linkedin_user}' LINKEDIN_PASSWORD='#{linkedin_password}'"
  parameters  = "KEYWORDS='#{keywords}' POSTALCODE='#{postalcode}' INDUSTRY='#{industry}'"

  command     = %Q(#{credentials} #{parameters} casperjs #{script} "#{path}")
  result      = `#{command}`

  if $?.exitstatus == 0
    JSON.parse(result)
  else
    begin
      error = JSON.parse(result.gsub(/\e\[[0-9]*(;[0-9]+)*m/, ""))
      raise error["message"]
    rescue JSON::ParserError
      raise result
    end
  end
end