You are here

class ZencoderCURL in Video 7

Hierarchy

Expanded class hierarchy of ZencoderCURL

File

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

View source
class ZencoderCURL {
  var $options = array(
    CURLOPT_RETURNTRANSFER => 1,
    // Return content of the url
    CURLOPT_HEADER => 0,
    // Don't return the header in result
    CURLOPT_HTTPHEADER => array(
      "Content-Type: application/json",
      "Accept: application/json",
    ),
    CURLOPT_CONNECTTIMEOUT => 0,
    // Time in seconds to timeout send request. 0 is no timeout.
    CURLOPT_FOLLOWLOCATION => 1,
  );
  var $connected;
  var $results;
  var $status_code;
  var $error;

  // Initialize
  function ZencoderCURL($url, $json, $options = array()) {

    // Add library details to request
    $this->options[CURLOPT_HTTPHEADER][] = "Zencoder-Library-Name: " . ZENCODER_LIBRARY_NAME;
    $this->options[CURLOPT_HTTPHEADER][] = "Zencoder-Library-Version: " . ZENCODER_LIBRARY_VERSION;

    // If posting data
    if ($json) {
      $this->options[CURLOPT_POST] = 1;
      $this->options[CURLOPT_POSTFIELDS] = $json;
    }

    // Add cURL options to defaults (can't use array_merge)
    foreach ($options as $option_key => $option) {
      $this->options[$option_key] = $option;
    }

    // Initialize session
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    // Set transfer options
    curl_setopt_array($ch, $this->options);

    // Execute session and store returned results
    $this->results = curl_exec($ch);

    // Store the HTTP status code given (201, 404, etc.)
    $this->status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    // Check for cURL error
    if (curl_errno($ch)) {
      $this->error = 'cURL connection error (' . curl_errno($ch) . '): ' . htmlspecialchars(curl_error($ch)) . ' <a href="http://www.google.com/search?q=' . urlencode("curl error " . curl_error($ch)) . '">Search</a>';
      $this->connected = false;
    }
    else {
      $this->connected = true;
    }

    // Close session
    curl_close($ch);
  }

}

Members