You are here

function ZencoderRequest::ZencoderRequest in Video 7

File

modules/video_zencoder/includes/Zencoder.php, line 125

Class

ZencoderRequest

Code

function ZencoderRequest($url, $api_key = "", $params = "") {

  // Add api_key to url if supplied
  if ($api_key) {
    $url .= "?api_key=" . $api_key;
  }

  // Get JSON
  if (is_string($params)) {
    $json = trim($params);
  }
  else {
    if (is_array($params)) {
      $json = json_encode($params);
    }
    else {
      $json = false;
    }
  }

  // Create request
  $request = new ZencoderCURL($url, $json);

  // Check for connection errors
  if ($request->connected == false) {
    $this->errors[] = $request->error;
    return;
  }
  $status_code = intval($request->status_code);
  $this->raw_results = $request->results;

  // Parse returned JSON
  $this->results = json_decode($this->raw_results, true);

  // Return based on HTTP status code
  if ($status_code >= 200 && $status_code <= 206) {
    $this->successful = true;
  }
  else {

    // Get job request errors if any
    if (is_array($this->results["errors"])) {
      foreach ($this->results["errors"] as $error) {
        $this->errors[] = $error;
      }
    }
    else {
      $this->errors[] = "Unknown Error\n\nHTTP Status Code: " . $request->status_code . "\n" . "Raw Results: \n" . $request->raw_results;
    }
  }
}