Class: Sistrix::Domain::Social::Url

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/sistrix/domain/social/url.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 = {}) ⇒ Url

Returns a new instance of Url.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/sistrix/domain/social/url.rb', line 12

def initialize(options = {})
  @options = {
    'domain' => nil,
    'history' => 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.



9
10
11
# File 'lib/sistrix/domain/social/url.rb', line 9

def credits
  @credits
end

#facebookObject (readonly)

Returns the value of attribute facebook.



9
10
11
# File 'lib/sistrix/domain/social/url.rb', line 9

def facebook
  @facebook
end

#googleplusObject (readonly)

Returns the value of attribute googleplus.



9
10
11
# File 'lib/sistrix/domain/social/url.rb', line 9

def googleplus
  @googleplus
end

#historyObject (readonly)

Returns the value of attribute history.



9
10
11
# File 'lib/sistrix/domain/social/url.rb', line 9

def history
  @history
end

#totalObject (readonly)

Returns the value of attribute total.



9
10
11
# File 'lib/sistrix/domain/social/url.rb', line 9

def total
  @total
end

#twitterObject (readonly)

Returns the value of attribute twitter.



9
10
11
# File 'lib/sistrix/domain/social/url.rb', line 9

def twitter
  @twitter
end

#urlObject (readonly)

Returns the value of attribute url.



9
10
11
# File 'lib/sistrix/domain/social/url.rb', line 9

def url
  @url
end

Instance Method Details

#call(options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sistrix/domain/social/url.rb', line 24

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

  @credits = data.xpath('//credits').first['used'].to_i
  @votes = []

  current_node = data.xpath('/response/answer/current').first
  @url = current_node['url']
  @total = current_node['total'].to_i
  @facebook = current_node['facebook'].to_i
  @twitter = current_node['twitter'].to_i
  @googleplus = current_node['googleplus'].to_i

  @history = []
  data.xpath('/response/answer/timeline/history').each do |o|
    @history << Record.new(o)
  end

  self
end