whos_using_what 0.0.2 → 0.0.3

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.
@@ -1,7 +1,12 @@
1
- require_relative "whos_using_what/linkedin_client"
1
+ require_relative "whos_using_what/search_client"
2
2
 
3
3
  class WhosUsingWhat
4
4
 
5
+ if __FILE__ == $PROGRAM_NAME
5
6
 
7
+ client = SearchClient.new()
8
+ client.search( "37signals.com", "ruby")
9
+
10
+ end
6
11
 
7
12
  end
@@ -0,0 +1,64 @@
1
+ require "uri"
2
+ require "rest-client"
3
+
4
+ class SearchClient
5
+
6
+ attr :results
7
+
8
+ def initialize()
9
+
10
+
11
+ @negativeMatchUrlPatterns = Array.new.push("google.com").push("youtube.com")
12
+
13
+ @positiveMatchUrlPatterns = Array.new.push("http")
14
+
15
+
16
+ @results = Hash.new
17
+
18
+ end
19
+
20
+ def extractUrls (rawInput, mustContainUrl)
21
+
22
+ acceptedUrls = Array.new
23
+
24
+ urls = URI.extract(rawInput)
25
+ urls.each do |url|
26
+ add = true
27
+ @negativeMatchUrlPatterns.each do |token|
28
+
29
+ if (nil != url.index(token))
30
+ add = false
31
+ end
32
+ end
33
+
34
+ @positiveMatchUrlPatterns.each do |token|
35
+
36
+ if (nil == url.index(token) || url.index(token) > 0)
37
+ add = false
38
+ end
39
+ end
40
+
41
+ if (mustContainUrl != nil && url.index(mustContainUrl) == nil)
42
+ add = false
43
+ end
44
+
45
+ if (add)
46
+ acceptedUrls.push(url)
47
+ end
48
+
49
+
50
+ end
51
+
52
+ end
53
+
54
+ def search(site, query)
55
+
56
+ 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="
57
+
58
+ rawHtml = RestClient.get(url)
59
+
60
+ extractUrls(rawHtml, site)
61
+
62
+ end
63
+
64
+ 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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,12 +43,29 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rest_client
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  description: What companies are using what technologies
47
63
  email: r.dane1010@gmail.com
48
64
  executables: []
49
65
  extensions: []
50
66
  extra_rdoc_files: []
51
67
  files:
68
+ - lib/whos_using_what/search_client.rb
52
69
  - lib/whos_using_what/linkedin_client.rb
53
70
  - lib/whos_using_what.rb
54
71
  homepage: http://rubygems.org/gems/whos_using_what