You are here

function brightcove_try_client in Brightcove Video Connect 7.6

Same name and namespace in other branches
  1. 7.7 brightcove.module \brightcove_try_client()
2 calls to brightcove_try_client()
brightcove_media_file_formatter_image_view in brightcove_media/brightcove_media.module
The brightcove_media_image file formatter view callback.
brightcove_media_file_uri_to_object in brightcove_media/brightcove_media.module
Helper function MediaInternetBrightcoveHandler class getFileObject method.

File

./brightcove.module, line 3380
Brightcove module is an integration layer between any modules using Brightcove API. It makes all necessary checks for the API and makes settings available to the user.

Code

function brightcove_try_client($account_id, callable $try, callable $catch = NULL, $logtype = NULL) {
  brightcove_load_lib();
  $account_candidates = entity_load('brightcove_client', FALSE, [
    'account_id' => $account_id,
  ]);
  if (!$account_candidates) {
    return FALSE;
  }
  foreach ($account_candidates as $client) {
    try {
      $result = $try($client);
      return $result;
    } catch (\Brightcove\API\Exception\APIException $ex) {
      if ($ex
        ->getCode() === 401) {
        continue;
      }
      drupal_set_message(t('Brightcove API call failed: %message', [
        '%message' => _brightcove_try_json_message($ex
          ->getResponseBody()),
      ]), 'error');
      watchdog_exception($logtype ?: 'brightcove_api', $ex);
      if ($catch) {
        $catch($ex);
      }
    } catch (\Brightcove\API\Exception\AuthenticationException $ex) {
      drupal_set_message(t('Failed to authorize with Brightcove'), 'error');
      watchdog_exception($logtype ?: 'brightcove_auth', $ex);
      if ($catch) {
        $catch($ex);
      }
    }
  }
  return NULL;
}