You are here

public static function ShareaholicUtilities::get_share_counts_api_status in Share Buttons, Related Posts, Content Analytics - Shareaholic 8

Same name and namespace in other branches
  1. 7.3 utilities.php \ShareaholicUtilities::get_share_counts_api_status()

Check the share counts API for empty response or missing services

1 call to ShareaholicUtilities::get_share_counts_api_status()
ShareaholicUtilities::share_counts_api_connectivity_check in ./utilities.php
Share Counts API Connectivity check

File

./utilities.php, line 864

Class

ShareaholicUtilities

Code

public static function get_share_counts_api_status($response) {
  if (!$response || !isset($response['body'])) {
    return 'FAIL';
  }
  $response['body'] = json_decode($response['body'], TRUE);
  if (!is_array($response['body'])) {
    return 'FAIL';
  }

  // Did it return at least 6 services?
  $has_majority_services = count(array_keys($response['body']['data'])) >= 5 ? true : false;
  $has_important_services = true;

  // Does it have counts for fb, pinterest?
  foreach (array(
    'facebook',
    'pinterest',
  ) as $service) {
    if (!isset($response['body']['data'][$service]) || !is_numeric($response['body']['data'][$service])) {
      $has_important_services = false;
    }
  }
  if (!$has_majority_services || !$has_important_services) {
    return 'FAIL';
  }
  return 'SUCCESS';
}