whos_using_what 0.0.6 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ class BaseApiClient
2
+
3
+ def starts_with?(string, prefix)
4
+ prefix = prefix.to_s
5
+ string[0, prefix.length] == prefix
6
+ end
7
+
8
+ def prepare_params_from_map_helper (base_url, params_map)
9
+
10
+ base_url = base_url << "?"
11
+ params_map.each do |key, value|
12
+ if starts_with?(key, "facet")
13
+ base_url = base_url << "&" << key << "," << value
14
+ else
15
+ base_url = base_url << "&" << key << "=" << value
16
+ end
17
+
18
+ end
19
+ base_url
20
+
21
+ end
22
+
23
+ end
@@ -1,12 +1,14 @@
1
1
  require 'oauth'
2
2
  require 'json'
3
3
  require_relative 'config_module'
4
+ require_relative 'base_api_client'
4
5
 
5
- class LinkedinClient
6
+ class LinkedinClient < BaseApiClient
6
7
 
7
8
  #the company industry codes to search for, see: https://developer.linkedin.com/documents/industry-codes
8
9
  attr :access_token, true
9
10
  attr :companyUrls
11
+ @@json_indicator = "format=json"
10
12
 
11
13
  include ConfigModule
12
14
 
@@ -26,41 +28,43 @@ class LinkedinClient
26
28
 
27
29
  end
28
30
 
29
-
30
- def self.parsePersonResult(result)
31
-
32
- result['people']['values'].each do |person|
33
- puts person['firstName'] + " " + person['lastName']
31
+ def add_json_to_map(key_field_name, raw_json_map, output_map)
32
+ raw_json_map.each do |value|
33
+ output_map[value[key_field_name]] = value
34
34
  end
35
35
  end
36
36
 
37
37
 
38
- def parseCompanyResults(result)
39
- results = Hash.new
40
- result['companies']['values'].each do |company|
41
- results[company['universalName']] = company['websiteUrl']
42
- end
43
- return results
38
+ #todo this should be put into module for re-use
39
+ def json_api_call_helper (base_url, params)
40
+ url = prepare_params_from_map_helper(base_url, params)
41
+ json = @access_token.get(url << "&" << @@json_indicator)
42
+
43
+ JSON.parse(json.body)
44
44
  end
45
45
 
46
+ # this method searches for people from a specified company for a specific job type
47
+ def people_search_for_company (location_code, title, company_name)
46
48
 
47
- #test method, remove eventually
48
- def apiCallLinkedin
49
- url = "http://api.linkedin.com/v1/company-search:(companies:(universal-name,website-url,locations:(address:(city,state))),facets,num-results)?facet=location,us:84&facet=industry," <<
50
- @linkedin_tech_industry_codes <<
51
- "&format=json" <<
52
- "&start=" << @start <<
53
- "&count=" << @numberResults
49
+ params = Hash.new
50
+ params["facet=location"] = "us:" <<location_code
51
+ params["current-company"]= "true"
52
+ params["title"]=title
53
+ params["company-name"] = company_name
54
54
 
55
- json = @access_token.get(url)
55
+ base_url = "http://api.linkedin.com/v1/people-search:(people,facets)"
56
56
 
57
- JSON.parse(json.body)
57
+ puts json_api_call_helper(base_url, params)['people']['values']
58
58
 
59
59
  end
60
60
 
61
61
 
62
62
  def gather_company_data(start, number_to_collect, industry_codes)
63
63
 
64
+ if number_to_collect == nil
65
+ number_to_collect = 20
66
+ end
67
+
64
68
  request_num = number_to_collect
65
69
  cnt = 0
66
70
  div = number_to_collect / @max_results
@@ -75,20 +79,16 @@ class LinkedinClient
75
79
  end
76
80
 
77
81
  while cnt < div do
78
- url = "http://api.linkedin.com/v1/company-search:(companies:(universal-name,website-url,locations:(address:(city,state))),facets,num-results)?facet=location,us:84&facet=industry," <<
79
- industry_codes <<
80
- "&format=json" <<
81
- "&start=" << (cnt * @max_results + 1).to_s <<
82
- "&count=" << @max_results.to_s
83
-
84
-
85
- json = @access_token.get(url)
82
+ base_url = "http://api.linkedin.com/v1/company-search:(companies:(universal-name,id,website-url,locations:(address:(city,state))),facets,num-results)"
86
83
 
87
- tmp_results = parseCompanyResults(JSON.parse(json.body))
84
+ params = Hash.new
85
+ params["start"] = (start * @max_results + 1).to_s
86
+ params["count"] = @max_results.to_s
87
+ params["facet=location"] = "us:84"
88
+ params["facet=industry"] = industry_codes
88
89
 
89
- tmp_results.each do |key, value|
90
- results[key] = value
91
- end
90
+ raw_json_map = json_api_call_helper(base_url, params)['companies']['values']
91
+ add_json_to_map("universalName", raw_json_map, results)
92
92
 
93
93
  cnt = cnt + 1
94
94
  end
@@ -74,29 +74,41 @@ class SearchClient
74
74
  end
75
75
 
76
76
 
77
- def search(site, query)
77
+ def search(query, site)
78
78
 
79
79
  url = "https://www.google.com/search?hl=en&as_q=" << query << "&as_epq=&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=" << site << "&as_occt=any&safe=off&tbs=&as_filetype=&as_rights="
80
80
 
81
- rawHtml = RestClient.get(url)
81
+ begin
82
+ rawHtml = RestClient.get(url)
83
+ rescue
84
+
85
+ end
82
86
 
83
87
  urls = extractUrls(rawHtml, site)
84
88
 
85
89
  isMatch = false
86
90
 
87
- urls.each do |url|
88
- if (determineIfUsesTechnology(query, RestClient.get(url)))
89
- isMatch = true
90
- break
91
+ at_least_one_nonexception_url = false
92
+
93
+ urls.each do |cur_url|
94
+ begin
95
+ html = RestClient.get(cur_url)
96
+ uses_technology = determineIfUsesTechnology(query, html)
97
+ at_least_one_nonexception_url = true
98
+ if (uses_technology)
99
+ isMatch = true
100
+ break
101
+ end
102
+ rescue Exception => exception
103
+ #raise exception
91
104
  end
92
105
  end
93
106
 
94
- if (isMatch)
95
- puts site << " uses " << query
96
- else
97
- puts site << " does not use " << query
107
+ if (!at_least_one_nonexception_url)
108
+ return false
98
109
  end
99
110
 
111
+ return isMatch
100
112
  end
101
113
 
102
114
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whos_using_what
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -81,6 +81,7 @@ executables: []
81
81
  extensions: []
82
82
  extra_rdoc_files: []
83
83
  files:
84
+ - lib/whos_using_what/base_api_client.rb
84
85
  - lib/whos_using_what/search_client.rb
85
86
  - lib/whos_using_what/linkedin_client.rb
86
87
  - lib/whos_using_what/config_module.rb