Class: Sistrix::Keyword

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/sistrix/keyword.rb,
lib/sistrix/keyword/us.rb,
lib/sistrix/keyword/sem.rb,
lib/sistrix/keyword/seo.rb,
lib/sistrix/keyword/domain/us.rb,
lib/sistrix/keyword/domain/sem.rb,
lib/sistrix/keyword/domain/seo.rb

Defined Under Namespace

Modules: Domain Classes: Record, Sem, Seo, Us

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Base

#base_uri, #fetch, #method_name

Constructor Details

#initialize(options = {}) ⇒ Keyword

Returns a new instance of Keyword.



10
11
12
13
14
15
16
17
18
19
# File 'lib/sistrix/keyword.rb', line 10

def initialize(options = {})
  @options = {
    'kw' => nil,
    'api_key' => Sistrix.config.api_key,
  }.merge(options)

  if Sistrix.config.proxy
    RestClient.proxy = Sistrix.config.proxy
  end
end

Instance Attribute Details

#creditsObject (readonly)

Returns the value of attribute credits.



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

def credits
  @credits
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#call(options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sistrix/keyword.rb', line 21

def call(options = {})
  data = fetch(options)

  @credits = data.xpath('//credits').first['used'].to_i
  @options = []
  data.xpath('//answer/option').each do |o|
    @options << Record.new(o)
  end

  self
end