Class: TheCount::Facebook::Comments

Inherits:
Countable
  • Object
show all
Defined in:
lib/thecount/countable/facebook.rb

Instance Attribute Summary

Attributes inherited from Countable

#service_name, #unit, #value

Instance Method Summary collapse

Constructor Details

#initializeComments

Returns a new instance of Comments.



33
34
35
36
37
# File 'lib/thecount/countable/facebook.rb', line 33

def initialize
  @service_name = "facebook"
  @unit = "comment"
  @value = 0
end

Instance Method Details

#count(data) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/thecount/countable/facebook.rb', line 39

def count(data)
  url = data[:url]
  query = CGI::escape("\"index_link_stat_url\":\"select url,commentsbox_count from link_stat where url=\\\"#{url}\\\"\"")
  url = "https://api-read.facebook.com/restserver.php?format=json&method=fql.multiquery&queries=%7B#{query}%7D"
  begin
    @value = JSON.parse(open(url).string)[0]["fql_result_set"][0]["commentsbox_count"].to_i
  rescue Exception => e
    @value = 0
  end
end