示例#1
0
 /**
  * Get all presentations which are related to the prsentation id provided based on tag matching.
  * Optionally the resultset can be restricted by applying criteria
  *
  * @param int $id The id of the presentation we're relating to
  * @param array $criteria Find only presentations which meet the criteria provided
  * @return Videojuicer_Presentation_List_Response
  */
 public function find_all_related_to($id, $criteria = array())
 {
     $method = "presentations/{$id}/related_by_tag";
     $type = Videojuicer_Request::GET;
     $response_class = "Videojuicer_Presentation_Response";
     $exception_class = "Videojuicer_Presentation_Exception";
     $permission = Videojuicer_Permission::NONE;
     $request = new Videojuicer_Request($method, $type, $permission, $response_class, $exception_class);
     return Videojuicer::execute_call($request);
 }
示例#2
0
 /**
  * Update the presentation with ID provided to the attributes provided
  *
  * @param int $id
  * @param array $attributes
  */
 public static function update($asset_type, $id, $attributes, $token_value, $token_secret)
 {
     #TODO: Check if token value/secret is null and if so try to retrieve from VJ  (Videojuicer::get_access_token()->get_token(), Videojuicer::get_access_token()->get_secret())
     $method = "assets/{$asset_type}/{$id}";
     $type = Videojuicer_Request::PUT;
     $response_class = "Videojuicer_Asset_" . ucfirst($asset_type) . "_Update_Response";
     $exception_class = "Videojuicer_Asset_" . ucfirst($asset_type) . "_Update_Exception";
     $permission = Videojuicer_Permission::WRITE_USER;
     $attributes = Videojuicer_Request::wrap_vars($attributes, "asset");
     $request = new Videojuicer_Request($method, $type, $permission, $response_class, $exception_class);
     $request->set_vars($attributes);
     $request->set_authorized(true, $token_value, $token_secret);
     return Videojuicer::execute_call($request);
 }
示例#3
0
 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));
 }
示例#4
0
 /**
  * Find all Presentation objects that meet the conditionsv provided
  *
  * @param array $conditions 
  * @param int $related_to
  * 
  * @return Videojuicer_Presentation_List_Response
  */
 public static function find_all($conditions = array(), $related_to = null)
 {
     $method = "presentations";
     // If we want presentations related to another presentation
     if (is_numeric($related_to)) {
         $method .= "/{$related_to}/related_by_tag";
     }
     // Modify the conditions to be specific to presentations
     foreach ($conditions as $key => $val) {
         $conditions["presentation[{$key}]"] = $val;
     }
     // Make the call
     $response = Videojuicer::execute_call($method, $conditions);
     return $response;
 }
示例#5
0
 /**
  * Retrieve an authorized request token in preperation for retrieving an access token
  */
 public static function get_authorized_request_token($unauthorized_token_value = null, $unauthorized_token_secret = null)
 {
     // If we weren't given a token to use, retrieve it from Videojuicer class
     if (is_null($unauthorized_token_value) || is_null($unauthorized_token_secret)) {
         $token = Videojuicer::get_token();
         if ($token instanceof Videojuicer_Token_Unauthorized) {
             $unauthorized_token_value = $token->get_token();
             $unauthorized_token_secret = $token->get_secret();
         }
     }
     $method = "oauth/tokens";
     $type = Videojuicer_Request::GET;
     $response_class = "Videojuicer_Token_Authorized_Response";
     $exception_class = "Videojuicer_Token_Authorized_Exception";
     $permission = Videojuicer_Permission::NONE;
     $request = new Videojuicer_Request($method, $type, $permission, $response_class, $exception_class);
     $request->set_authorized(true, $unauthorized_token_value, $unauthorized_token_secret);
     $request->use_extension(false);
     return Videojuicer::execute_call($request);
 }
示例#6
0
 /**
  * Update the presentation with ID provided to the attributes provided
  *
  * @param int $id
  * @param array $attributes
  */
 public static function delete($id, $token_value, $token_secret)
 {
     #TODO: Check if token value/secret is null and if so try to retrieve from VJ  (Videojuicer::get_access_token()->get_token(), Videojuicer::get_access_token()->get_secret())
     $method = "presentations/{$id}";
     $type = Videojuicer_Request::DELETE;
     $response_class = "Videojuicer_Presentation_Delete_Response";
     $exception_class = "Videojuicer_Presentation_Delete_Exception";
     $permission = Videojuicer_Permission::WRITE_USER;
     $request = new Videojuicer_Request($method, $type, $permission, $response_class, $exception_class);
     $request->set_authorized(true, $token_value, $token_secret);
     return Videojuicer::execute_call($request);
 }
示例#7
0
 public static function set_access_token(Videojuicer_Token_Authorized $token)
 {
     self::$access_token = $token;
 }
示例#8
0
 /**
  * Create a token object from the data
  */
 public function __construct($data)
 {
     parent::__construct($data);
     $unauthorized_token = new Videojuicer_Token_Unauthorized($data);
     Videojuicer::set_request_token($unauthorized_token);
 }
示例#9
0
 /**
  * Create a token object from the data
  */
 public function __construct($data)
 {
     parent::__construct($data);
     $authorized_token = new Videojuicer_Token_Authorized($data);
     Videojuicer::set_access_token($authorized_token);
 }
示例#10
0
 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;
 }
示例#11
0
 public static function remove_role($id, $role, $token_value, $token_secret)
 {
     #TODO: Check if token value/secret is null and if so try to retrieve from VJ  (Videojuicer::get_access_token()->get_token(), Videojuicer::get_access_token()->get_secret())
     $method = "users/{$id}/remove_role";
     $type = Videojuicer_Request::POST;
     $response_class = "Videojuicer_User_RemoveRole_Response";
     $exception_class = "Videojuicer_User_RemoveRole_Exception";
     $permission = Videojuicer_Permission::NONE;
     $attributes = array("role" => $role);
     $request = new Videojuicer_Request($method, $type, $permission, $response_class, $exception_class);
     $request->set_authorized(true, $token_value, $token_secret);
     $request->set_vars($attributes);
     return Videojuicer::execute_call($request);
 }