Class: Sistrix::Keyword::Domain::Seo

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

Defined Under Namespace

Classes: Record

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Base

#base_uri, #fetch, #method_name

Constructor Details

#initialize(options = {}) ⇒ Seo

Returns a new instance of Seo.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sistrix/keyword/domain/seo.rb', line 12

def initialize(options = {})
  @options = {
    'domain' => nil,
    'num'  => 5,
    'date' => 'today',
    'search' => nil,
    'host' => nil,
    'url' => nil,
    'path' => nil,
    'from_pos' => nil,
    'to_pos' => 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.



10
11
12
# File 'lib/sistrix/keyword/domain/seo.rb', line 10

def credits
  @credits
end

#dateObject (readonly)

Returns the value of attribute date.



10
11
12
# File 'lib/sistrix/keyword/domain/seo.rb', line 10

def date
  @date
end

#resultsObject (readonly)

Returns the value of attribute results.



10
11
12
# File 'lib/sistrix/keyword/domain/seo.rb', line 10

def results
  @results
end

Instance Method Details

#call(options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sistrix/keyword/domain/seo.rb', line 31

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

  @credits = data.xpath('/response/credits').first['used'].to_i
  @date    = Time.parse(data.xpath('/response/date').first.to_s)

  @results = []
  data.xpath('/response/answer/result').each do |r|
    @results << Record.new(r)
  end

  self
end