You are here

public function video_zencoder_api::create_user in Video 6.4

Same name and namespace in other branches
  1. 6.5 plugins/video_zencoder/video_zencoder.lib.inc \video_zencoder_api::create_user()
  2. 7 modules/video_zencoder/includes/zencoder.inc \video_zencoder_api::create_user()

Create Zencoder user account

File

plugins/video_zencoder/video_zencoder.lib.inc, line 169

Class

video_zencoder_api

Code

public function create_user($email) {
  if ($this->zencoder == NULL) {
    return FALSE;
  }
  try {

    // $result is Services_Zencoder_Account
    $result = $this->zencoder->accounts
      ->create(array(
      'terms_of_service' => '1',
      'email' => $email,
      'affiliate_code' => 'drupal-video',
    ));
    $params = array(
      'email' => $email,
      'api_key' => $result->api_key,
      'password' => $result->password,
    );
    variable_set('video_zencoder_api_key', $result->api_key);
    $message = drupal_mail('video_zencoder', 'video_zencoder', $email, language_default(), $params);
    if (!$message['result']) {
      drupal_set_message(t('Unable to send e-mail!. Your Zencoder Details are as below.<br/> <b>API Key</b> : !api_key<br/> <b>Password</b> : !password<br/>', array(
        '!api_key' => $results['api_key'],
        '!password' => $results['password'],
      )), 'status');
    }
    else {
      drupal_set_message(t('Your account has been created and is ready to start processing on Zencoder'));
    }
    return TRUE;
  } catch (Services_Zencoder_Exception $e) {
    $errors = '';
    foreach ($e
      ->getErrors() as $error) {
      if ($error == 'Email has already been taken') {
        drupal_set_message(t('Your account already exists on Zencoder. So !login to here and enter API key below.', array(
          '!login' => l(t('login'), 'https://app.zencoder.com/session/new'),
        )));
        variable_set('video_zencoder_api_key', 'Please enter your API Key');
        return TRUE;
      }
      $errors .= $error;
    }
    return $errors;
  }
}