You are here

public function video_zencoder_api::create_user in Video 6.5

Same name and namespace in other branches
  1. 6.4 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 120
Class file to handle amazon s3 transfers.

Class

video_zencoder_api

Code

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

    // $result is Services_Zencoder_Account
    $result = $this->zencoder->accounts
      ->create(array(
      'terms_of_service' => '1',
      'email' => $mail,
      'affiliate_code' => 'drupal-video',
    ));
    $params = array(
      'email' => $mail,
      'api_key' => $result->api_key,
      'password' => $result->password,
    );
    variable_set('video_zencoder_api_key', $result->api_key);
    $message = drupal_mail('video_zencoder', 'video_zencoder', $mail, 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) {
    $exerrors = $e
      ->getErrors();
    if (is_array($exerrors) || $exerrors instanceof Services_Zencoder_Error) {
      $errors = '';
      foreach ($exerrors as $error) {
        if ($error == 'Email has already been taken') {
          drupal_set_message(t('Your account already exists on Zencoder. So <a href="@login-url">login</a> to here and enter API key below.', array(
            '@login-url' => 'https://app.zencoder.com/session/new',
          )));
          variable_set('video_zencoder_api_key', 'Please enter your API Key');
          return TRUE;
        }
        $errors .= $error;
      }
      return $errors;
    }
    return $e
      ->getMessage();
  }
}