Class: TheCount::Google::Plus

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

Instance Attribute Summary

Attributes inherited from Countable

#service_name, #unit, #value

Instance Method Summary collapse

Constructor Details

#initializePlus

Returns a new instance of Plus.



27
28
29
30
31
# File 'lib/thecount/countable/google.rb', line 27

def initialize
  @service_name = "google"
  @unit = "shares"
  @value = 0
end

Instance Method Details

#count(data) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/thecount/countable/google.rb', line 32

def count(data)
  url = "https://plusone.google.com/u/0/_/+1/fastbutton?url="
  url = "#{url}#{CGI::escape(data[:url])}"
  begin
    # like penut butter brittle
    @value = open(url).string.split('window.__SSR = {')[1].split('};')[0].split("'c':")[1].split(",")[0].strip.to_i
  rescue Exception => e
    puts e
    @value = 0
  end
end