Class: TheCount::Twitter

Inherits:
Countable show all
Defined in:
lib/thecount/countable/twitter.rb

Instance Attribute Summary

Attributes inherited from Countable

#service_name, #unit, #value

Instance Method Summary collapse

Constructor Details

#initializeTwitter

Returns a new instance of Twitter.



7
8
9
10
11
# File 'lib/thecount/countable/twitter.rb', line 7

def initialize
  @service_name = "twitter"
  @unit = "tweet"
  @value = 0
end

Instance Method Details

#count(data) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/thecount/countable/twitter.rb', line 13

def count(data)
  url = data[:url]
  begin
    url = "http://urls.api.twitter.com/1/urls/count.json?url=#{url}"
    @value = JSON.parse(open(url).string)["count"].to_i
  rescue Exception => e
    p e
    @value = 0
  end
end