コード例 #1
0
ファイル: OAuth.php プロジェクト: videojuicer/vj-sdk-php
 public function build_signature($request, $consumer, $token)
 {
     $base_string = $request->get_signature_base_string();
     $request->base_string = $base_string;
     $key_parts = array($consumer->secret, $token ? $token->secret : "");
     $key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
     if (Videojuicer::debug_level() >= Videojuicer_Debug::ALL) {
         echo "BASE STRING: " . $base_string . "<br />\n";
     }
     $key = implode('&', $key_parts);
     if (Videojuicer::debug_level() >= Videojuicer_Debug::ALL) {
         echo "SIGNATURE_SECRET: " . $key . "<br />";
     }
     return base64_encode(hash_hmac('sha1', $base_string, $key, true));
 }
コード例 #2
0
 /**
  * Perform the retrieval using CURL
  *
  * @return SimpleXMLElement
  */
 private static function execute_call_curl($url, $type = "get", $post_vars = array(), $file = false)
 {
     // Determine how to make the request
     switch ($type) {
         // Make a POST request for POST, PUT and DELETE (not all servers support PUT and DELETE)
         case Videojuicer_Request::POST:
         case Videojuicer_Request::PUT:
         case Videojuicer_Request::DELETE:
             $make_post = true;
             break;
         case Videojuicer_Request::GET:
         default:
             $make_post = false;
             break;
     }
     if (Videojuicer::debug_level() >= Videojuicer_Debug::ALL) {
         echo "URL: {$url}<br />\n";
     }
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     // Tell cURL if we're making a post request
     if ($make_post) {
         if (Videojuicer::debug_level() >= Videojuicer_Debug::ALL) {
             echo "POST VARS BEFORE HTTP_BUILD_QUERY: " . print_r($post_vars, true);
         }
         // If there is a file o be included, add it to the array and make the post data an array so cURL multiparts the transfer
         if ($file) {
             $post_vars["asset[file]"] = "@{$file}";
             $post_data = $post_vars;
             curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
             // Else doesn't need to be multipart so build post data into a string
         } else {
             $post_data = http_build_query($post_vars);
         }
         if (Videojuicer::debug_level() >= Videojuicer_Debug::ALL) {
             echo "POST DATA: {$post_data}<br />\n";
         }
         curl_setopt($ch, CURLOPT_VERBOSE, 1);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
     }
     // Make the call
     $data = curl_exec($ch);
     if (curl_errno($ch)) {
         Videojuicer_ClassLoader::load("Videojuicer_Request_Exception");
         throw new Videojuicer_Request_Exception('execute_call_curl error: ' . curl_error($ch), curl_errno($ch));
     } else {
         curl_close($ch);
         if (!$data || strlen(trim($data)) < 2) {
             Videojuicer_ClassLoader::load("Videojuicer_Request_Exception");
             throw new Videojuicer_Request_Exception('API request error: No result returned.', 1);
         }
         return $data;
     }
 }
コード例 #3
0
ファイル: Helper.php プロジェクト: videojuicer/vj-sdk-php
 public function setup_components()
 {
     // Retrieve the request
     $req = $this->get_request();
     // Used in all requests
     $seed_name = Videojuicer::get_seed_name();
     $api_version = Videojuicer::get_api_version();
     // Create the basic url
     $url = $req->get_protocol() . "://" . Videojuicer::VJ_REST_URL . $req->get_method();
     // Setup the mandatory vars which must be passed with all requests
     $mandatory_vars = array("seed_name" => $seed_name, "api_version" => $api_version);
     // Now decide what url parameters and post parameter should be based on the submission type
     $get_vars = array();
     $post_vars = array();
     switch ($req->get_type()) {
         // GET
         case Videojuicer_Request::GET:
         default:
             $get_vars = array_merge($get_vars, $req->get_vars(), $mandatory_vars);
             $url_retrieval_method = "to_url";
             break;
             // POST
         // POST
         case Videojuicer_Request::POST:
             $post_vars = array_merge($post_vars, $req->get_vars(), $mandatory_vars);
             $url_retrieval_method = "get_normalized_http_url";
             break;
             // PUT and DELETE
         // PUT and DELETE
         case Videojuicer_Request::PUT:
         case Videojuicer_Request::DELETE:
             $post_vars["_method"] = strtoupper($req->get_type());
             $post_vars = array_merge($post_vars, $req->get_vars(), $mandatory_vars);
             $url_retrieval_method = "get_normalized_http_url";
             break;
     }
     // Determine whether to sign it
     if ($req->is_authorized()) {
         // If we're appending the extension, do so
         if ($req->use_extension()) {
             $url .= "." . Videojuicer::get_response_format_extension();
         }
         if (sizeof($get_vars)) {
             $url .= "?" . http_build_query($get_vars);
         }
         $token_value = $req->get_token();
         // Retrieve a token (if any) assigned to this user
         $token_secret = $req->get_token_secret();
         $token = new OAuthToken($token_value, $token_secret);
         // Determine the custom parameters which need signing
         $sign_params = sizeof($post_vars) ? $post_vars : $get_vars;
         // Create a consumer we're receiving a token for
         $consumer = new OAuthConsumer(Videojuicer::get_api_key(), Videojuicer::get_api_secret());
         // Generate the request object
         $oauth_req = OAuthRequest::from_consumer_and_token($consumer, $token, strtoupper($req->get_safe_type()), $url, $sign_params);
         // Use SHA encryption
         $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
         // Sign the request
         $oauth_req->sign_request($hmac_method, $consumer, $token);
         $post_vars = $oauth_req->get_parameters();
         uksort($post_vars, 'strcmp');
         if (Videojuicer::debug_level() >= Videojuicer_Debug::ALL) {
             echo "POST VARS: " . print_r($post_vars, true) . "<br />\n";
         }
         $url = $oauth_req->{$url_retrieval_method}();
         // It it is a plain call
     } else {
         $url .= "." . Videojuicer::get_response_format_extension();
         if (sizeof($get_vars)) {
             $url .= "?" . http_build_query($get_vars);
         }
         // If this request need to be made as an OEmbed request we need to construct a new url using the previous one as a parameter
         if ($req->is_oembed()) {
             $oembed_vars = $mandatory_vars;
             $oembed_vars["maxwidth"] = $req->get_oembed_maxwidth();
             $oembed_vars["maxheight"] = $req->get_oembed_maxheight();
             $oembed_vars["format"] = $req->get_oembed_format();
             $oembed_vars["embed"] = $req->get_oembed_embed_attributes();
             $oembed_vars["flashvars"] = $req->get_oembed_flashvar_attributes();
             $oembed_vars["url"] = $url;
             $url = $req->get_protocol() . "://" . Videojuicer::VJ_REST_URL . "oembed?" . http_build_query($oembed_vars);
         }
     }
     // Store the results
     $this->url = $url;
     $this->post_vars = $post_vars;
 }