You are here

function KalturaClientBase::hit in Kaltura 5

Same name and namespace in other branches
  1. 6 kaltura_client/kaltura_client_base.php \KalturaClientBase::hit()
89 calls to KalturaClientBase::hit()
KalturaClient::addDownload in kaltura_client/kaltura_client.php
KalturaClient::addDvdEntry in kaltura_client/kaltura_client.php
KalturaClient::addDvdJob in kaltura_client/kaltura_client.php
KalturaClient::addEntry in kaltura_client/kaltura_client.php
KalturaClient::addKShow in kaltura_client/kaltura_client.php

... See full list

File

kaltura_client/kaltura_client_base.php, line 120

Class

KalturaClientBase

Code

function hit($method, $session_user, $params) {
  $start_time = microtime(true);
  $this
    ->log("service url: [" . $this->config->serviceUrl . "]");
  $this
    ->log("trying to call method: [" . $method . "] for user id: [" . $session_user->userId . "] using session: [" . $this->ks . "]");

  // append the basic params
  $params["kaltura_api_version"] = KALTURA_API_VERSION;
  $params["partner_id"] = $this->config->partnerId;
  $params["subp_id"] = $this->config->subPartnerId;
  $params["format"] = $this->config->format;
  $params["uid"] = $session_user->userId;
  $this
    ->addOptionalParam($params, "user_name", $session_user->screenName);
  $this
    ->addOptionalParam($params, "ks", $this->ks);
  $url = $this->config->serviceUrl . "/index.php/partnerservices2/" . $method;
  $this
    ->log("full reqeust url: [" . $url . "]");
  if (function_exists("curl_init")) {
    $this
      ->log("using curl");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Kaltura PHP4 Client (API version " . KALTURA_API_VERSION . "; curl; PHP " . phpversion() . ")");
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    $signature = $this
      ->signature($params);
    $params["kalsig"] = $signature;
    $http_result = curl_exec($ch);
    $curl_error = curl_error($ch);
  }
  else {
    $this
      ->log("not using curl");
    $curl_error = "";
    $params_string = $this
      ->http_parse_query($params);
    $http_result = $this
      ->do_post_request($url, $params_string);
  }
  if ($curl_error) {
    $result["error"] = array(
      array(
        "code" => "CURL_ERROR",
        "desc" => $curl_error,
      ),
    );
  }
  else {
    $this
      ->log("result (serialized): [" . $http_result . "]");
    if ($this->config->format == KALTURA_SERVICE_FORMAT_PHP) {
      $result = @unserialize($http_result);
      if (!$result) {
        $result["result"] = null;
        $result["error"] = array(
          array(
            "code" => "SERIALIZE_ERROR",
            "desc" => "failed to serialize server result",
          ),
        );
      }

      //$dump = print_r($result, true);

      //$this->log("result (object dump): " . $dump);
    }
    else {
      $result["error"] = array(
        array(
          "code" => "UNSUPPORTED_FORMAT",
          "desc" => "unsuppoted format [" . $this->config->format . "]",
        ),
      );
    }
  }
  $end_time = microtime(true);
  $this
    ->log("execution time for method [" . $method . "]: [" . ($end_time - $start_time) . "]");
  return $result;
}