You are here

private function BynderMediaApi::__construct in Bynder 7

File

includes/BynderMediaApi.inc, line 18
Manages the Bynder media browser functionality

Class

BynderMediaApi

Code

private function __construct() {
  try {
    $tokens = $this
      ->hasAccessToken();
    $settings = array(
      'consumerKey' => variable_get('bynder_oauth_consumer', ''),
      'consumerSecret' => variable_get('bynder_oauth_consumer_secret', ''),
      'token' => !$tokens ? variable_get('bynder_oauth_token', '') : $tokens['oauth_token'],
      'tokenSecret' => !$tokens ? variable_get('bynder_oauth_token_secret', '') : $tokens['oauth_token_secret'],
      'baseUrl' => variable_get('bynder_url', ''),
    );
    if (!variable_get('bynder_url')) {
      $settings = variable_get('temp_derivatives_settings');
    }
    if ($proxyUrl = variable_get('bynder_proxy_url')) {
      $proxyUrl = str_replace([
        'tcp://',
        'https://',
      ], 'http://', $proxyUrl);
      $settings['requestOptions'] = [
        'proxy' => $proxyUrl,
      ];
    }
    $this->bynderApi = BynderApiFactory::create($settings);
    $this->assetBankManager = $this->bynderApi
      ->getAssetBankManager();
  } catch (Exception $e) {
    watchdog('bynder', $e
      ->getMessage());
  }
}