Class: Linkedin::Topcompanies::LinkedInScraper
- Inherits:
-
Object
- Object
- Linkedin::Topcompanies::LinkedInScraper
- Defined in:
- lib/linkedin-topcompanies.rb
Instance Attribute Summary collapse
-
#industry ⇒ Object
readonly
Returns the value of attribute industry.
-
#keywords ⇒ Object
readonly
Returns the value of attribute keywords.
-
#linkedin_password ⇒ Object
readonly
Returns the value of attribute linkedin_password.
-
#linkedin_user ⇒ Object
readonly
Returns the value of attribute linkedin_user.
-
#postalcode ⇒ Object
readonly
Returns the value of attribute postalcode.
Instance Method Summary collapse
-
#initialize(args) ⇒ LinkedInScraper
constructor
A new instance of LinkedInScraper.
- #run ⇒ Object
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
#industry ⇒ Object (readonly)
Returns the value of attribute industry.
8 9 10 |
# File 'lib/linkedin-topcompanies.rb', line 8 def industry @industry end |
#keywords ⇒ Object (readonly)
Returns the value of attribute keywords.
8 9 10 |
# File 'lib/linkedin-topcompanies.rb', line 8 def keywords @keywords end |
#linkedin_password ⇒ Object (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_user ⇒ Object (readonly)
Returns the value of attribute linkedin_user.
9 10 11 |
# File 'lib/linkedin-topcompanies.rb', line 9 def linkedin_user @linkedin_user end |
#postalcode ⇒ Object (readonly)
Returns the value of attribute postalcode.
8 9 10 |
# File 'lib/linkedin-topcompanies.rb', line 8 def postalcode @postalcode end |
Instance Method Details
#run ⇒ Object
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.("../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 |