Class: GoogleSuggest

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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(options = {})
  @home_language = self.class.configuration.home_language
  @proxy = self.class.configuration.proxy
  @region = options[:region] || self.class.configure.region
end

Instance Attribute Details

#home_languageObject

Returns the value of attribute home_language.



8
9
10
# File 'lib/google_suggest.rb', line 8

def home_language
  @home_language
end

#proxyObject

Returns the value of attribute proxy.



10
11
12
# File 'lib/google_suggest.rb', line 10

def proxy
  @proxy
end

#regionObject

Returns the value of attribute region.



9
10
11
# File 'lib/google_suggest.rb', line 9

def region
  @region
end

Class Method Details

.configurationObject



18
19
20
# File 'lib/google_suggest.rb', line 18

def self.configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



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, options = {})
  new(options).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