Class: GoogleSuggest
- Inherits:
-
Object
- Object
- GoogleSuggest
- Defined in:
- lib/google_suggest.rb,
lib/google_suggest/region.rb,
lib/google_suggest/version.rb,
lib/google_suggest/configuration.rb
Defined Under Namespace
Modules: Region Classes: Configuration
Constant Summary collapse
- VERSION =
'1.0.2'.freeze
Instance Attribute Summary collapse
-
#home_language ⇒ Object
Returns the value of attribute home_language.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
-
#region ⇒ Object
Returns the value of attribute region.
Class Method Summary collapse
- .configuration ⇒ Object
- .configure {|configuration| ... } ⇒ Object
- .suggest_for(keyword, options = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ GoogleSuggest
constructor
A new instance of GoogleSuggest.
- #suggest_for(keyword) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ GoogleSuggest
Returns a new instance of GoogleSuggest.
26 27 28 29 30 |
# File 'lib/google_suggest.rb', line 26 def initialize( = {}) @home_language = self.class.configuration.home_language @proxy = self.class.configuration.proxy @region = [:region] || self.class.configure.region end |
Instance Attribute Details
#home_language ⇒ Object
Returns the value of attribute home_language.
8 9 10 |
# File 'lib/google_suggest.rb', line 8 def home_language @home_language end |
#proxy ⇒ Object
Returns the value of attribute proxy.
10 11 12 |
# File 'lib/google_suggest.rb', line 10 def proxy @proxy end |
#region ⇒ Object
Returns the value of attribute region.
9 10 11 |
# File 'lib/google_suggest.rb', line 9 def region @region end |
Class Method Details
.configuration ⇒ Object
18 19 20 |
# File 'lib/google_suggest.rb', line 18 def self.configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
12 13 14 15 16 |
# File 'lib/google_suggest.rb', line 12 def self.configure yield configuration if block_given? configuration end |
.suggest_for(keyword, options = {}) ⇒ Object
22 23 24 |
# File 'lib/google_suggest.rb', line 22 def self.suggest_for(keyword, = {}) new().suggest_for(keyword) end |
Instance Method Details
#suggest_for(keyword) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/google_suggest.rb', line 32 def suggest_for(keyword) query = { output: 'toolbar', hl: home_language, q: keyword } res = http_get('/complete/search', query) parse(res.body.to_s) end |