Class: SocialButterfly::Services::GooglePlusService

Inherits:
AbstractService show all
Defined in:
lib/social_butterfly/services/google_plus_service.rb

Class Method Summary collapse

Methods inherited from AbstractService

share

Class Method Details

.share_button_url(content, service_options = {}) ⇒ Object



6
7
8
# File 'lib/social_butterfly/services/google_plus_service.rb', line 6

def self.share_button_url(content, service_options={})
  "https://plus.google.com/share?url=" + content[:url]
end

.track(content, service_options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/social_butterfly/services/google_plus_service.rb', line 10

def self.track(content, service_options={})
  stats = {}
  jsonstring = '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' + content[:url] +'","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]'
  c = Curl::Easy.http_post("https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ", jsonstring) do |curl|
    curl.headers['Accept'] = 'application/json'
    curl.headers['Content-Type'] = 'application/json'
    curl.headers['Api-Version'] = '2.2'
  end

  response = JSON.parse(c.body_str)
  if !response[0].present? || response[0]['error'].present?
    stats[:shares] = 0
  else
    stats[:shares] = response[0]['result']['metadata']['globalCounts']['count'].round
  end
  stats
end