ruby-google-suggest 0.0.2

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/ruby-google-suggest.rb +90 -0
  3. metadata +43 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f317efd0be419a1086b809c04c46b70920a3f0341dc7d41776c1397e8e597e12
4
+ data.tar.gz: df32e30b26709f6b6f7d6a73395ebe5ca1e4e67f80a88fd3efc8998ca3d6171f
5
+ SHA512:
6
+ metadata.gz: ec12f9219997236d795193cc42b5ad9739abac02d7a04e8b3edb9da72dca83160eaf54add848d8bdcdcd7118bf18ca248040f68b921f9652802c93ceb0dbe07c
7
+ data.tar.gz: 46d44e4ccbb79eab7a70d15fc5752e41949e9c6eed78eed872b80cbb97f91b03507bbe6297a02d05aecee68d3ded576b037f57f8aa401bf707515a971e7b3cfb
@@ -0,0 +1,90 @@
1
+ require 'httparty'
2
+ require 'nokogiri'
3
+ require 'pry-byebug'
4
+
5
+ # Keywords that allow a deeper search
6
+ ALPHA = ("a".."z")
7
+
8
+ # Keywords that indicate that people are trying to learn more about the good or service
9
+ QUESTIONS = ["are", "what", "how", "where", "is", "who", "alternatives"]
10
+
11
+ # Keywords that indicate that people are trying to consider goods or services
12
+ # Excluded "and" because it does not generate useful results
13
+ CONSIDERATIONS = ["features", "benefits", "price", "on", "for", "near", "at", "versus", "vs", "compare"]
14
+
15
+ # Keywords that indicate that people are about to buy goods or services
16
+ DO = ["buy", "sale", "service", "consulting", "consulting", "discount", "promotion", "buy"]
17
+
18
+
19
+ module GoogleSuggest
20
+
21
+ # Deep search
22
+ def suggest_deep(query, country, language, negative_keywords)
23
+ deep_keywords = []
24
+ ALPHA.each do |letter|
25
+ puts "looking at '#{letter}' variations"
26
+ deep_keywords << suggest(query + " #{letter}", country, language, negative_keywords)
27
+ end
28
+ deep_keywords.flatten.uniq
29
+ end
30
+
31
+ # Search using question keywords
32
+ def suggest_with_questions(query, country, language, negative_keywords)
33
+ questions_keywords = []
34
+ QUESTIONS.each do |question|
35
+ puts "looking at '#{question}' variations"
36
+ questions_keywords << suggest(query + " #{question}", country, language, negative_keywords)
37
+ end
38
+ questions_keywords.flatten.uniq
39
+ end
40
+
41
+ # Search using consideration keywords
42
+ def suggest_with_considerations(query, country, language, negative_keywords)
43
+ considerations_keywords = []
44
+ CONSIDERATIONS.each do |consideration|
45
+ puts "looking at '#{consideration}' variations"
46
+ considerations_keywords << suggest(query + " #{consideration}", country, language, negative_keywords)
47
+ end
48
+ considerations_keywords.flatten.uniq
49
+ end
50
+
51
+ # Search using purchase / call-to-action keywords
52
+ def suggest_with_action(query, country, language, negative_keywords)
53
+ do_keywords = []
54
+ DO.each do |do_keyword|
55
+ puts "looking at '#{do_keyword}' variations"
56
+ do_keywords << suggest(query + " #{do_keyword}", country, language, negative_keywords)
57
+ end
58
+ do_keywords.flatten.uniq
59
+ end
60
+
61
+ # Main search function
62
+ def suggest(query, country, language, negative_keywords=[])
63
+ base_keywords = []
64
+ final_keywords = []
65
+
66
+ response = HTTParty.get("http://suggestqueries.google.com/complete/search?&output=toolbar&hl=#{language}&q=#{query}&gl=#{country}")
67
+ doc = Nokogiri::XML(response.body)
68
+
69
+ seed_keywords = doc.xpath("//suggestion").map { |xml| xml["data"]}
70
+
71
+ seed_keywords.each do |seed_keyword|
72
+ response = HTTParty.get("http://suggestqueries.google.com/complete/search?&output=toolbar&hl=#{language}&q=#{seed_keyword}&gl=#{country}")
73
+ doc = Nokogiri::XML(response.body)
74
+ base_keywords << doc.xpath("//suggestion").map { |xml| xml["data"]}
75
+ end
76
+
77
+ final_keywords = base_keywords.flatten.uniq.reject do |base_keyword|
78
+ states = []
79
+ negative_keywords.each do |negative_keyword|
80
+ states << base_keyword.include?(negative_keyword)
81
+ end
82
+ states.any?(true)
83
+ end
84
+
85
+ final_keywords
86
+ end
87
+
88
+ end
89
+
90
+ extend GoogleSuggest
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-google-suggest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Kenn Costales
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-10-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Uses the Google Suggest API to generate keywords
14
+ email: fxkennyfrc@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/ruby-google-suggest.rb
20
+ homepage: https://rubygems.org/gems/ruby-google-suggest
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubygems_version: 3.0.1
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: Google Suggest API Wrapper
43
+ test_files: []