Class: ShareCount::Facebook

Inherits:
Base
  • Object
show all
Defined in:
lib/share_count/facebook.rb

Constant Summary collapse

URL =
'https://graph.facebook.com/v3.0/'

Constants inherited from Base

Base::DEFAULT_OPEN_TIMEOUT, Base::DEFAULT_TIMEOUT

Instance Attribute Summary

Attributes inherited from Base

#checked_url

Instance Method Summary collapse

Methods inherited from Base

config=, #initialize, #shares

Methods included from StringHelper

#to_camel_case, #to_underscore

Constructor Details

This class inherits a constructor from ShareCount::Base

Instance Method Details

#shares!Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/share_count/facebook.rb', line 6

def shares!
  return raise "It's Seems that you have not initilized ' SocialShareFeature.facebook_token_for_count = Your App ID|Your App Secret' in intilizer to use facebook count you need to do this please see usages in README." unless SocialShareFeature.facebook_token_for_count.present?
  token = SocialShareFeature.facebook_token_for_count
  response = get(URL, params: {
                   id: checked_url,
                   fields: 'engagement',
                   access_token: token
  })
  json_response = JSON.parse(response)

  if json_response['engagement']
    json_response['engagement']['share_count'] || 0
  else
    0
  end
end