lib/virility/strategies/facebook.rb in virility-0.3.1 vs lib/virility/strategies/facebook.rb in virility-0.4.0

- old
+ new

@@ -1,23 +1,27 @@ module Virility class Facebook < Strategy - BASE_URL = "https://api.facebook.com/method/links.getStats?urls=" + BASE_URL = 'https://graph.facebook.com/?fields=share,og_object{engagement,title}&id='.freeze + def census - self.class.get("#{BASE_URL}#{@url}") + self.class.get("#{BASE_URL}#{@url}", http_proxyaddr: @http_proxyaddr, http_proxyport: @http_proxyport) end def outcome - @response.parsed_response["links_getStats_response"]["link_stat"] + response = @response.parsed_response.dig('share') + engagement = @response.parsed_response.dig('og_object', 'engagement') + response['engagement_count'] = engagement.dig('count') + response['social_sentence'] = engagement.dig('social_sentence') + response end def count - results["total_count"] || 0 + results.dig('engagement_count') || 0 end private def valid_response_test - @response.respond_to?(:parsed_response) and @response.parsed_response.is_a?(Hash) and !@response.parsed_response["links_getStats_response"].nil? and !@response.parsed_response["links_getStats_response"]["link_stat"].nil? + @response.respond_to?(:parsed_response) && @response.parsed_response.is_a?(Hash) && !@response.parsed_response['share'].nil? end - end end