rats_quicktest.php

00001 <?php
00002 # Demo for using the RATS PHP Client Library (based on the Zend GData libraries).
00003 # This demo only demonstrates uploading a src file and using it to request a transcoding job, as well as retrieving some feeds and entries.
00004 #
00005 # Copyright (C) 2008 rambla.be
00006 #
00007 # Licensed under the Apache License, Version 2.0 (the "License");
00008 # you may not use this file except in compliance with the License.
00009 # You may obtain a copy of the License at
00010 #
00011 #      http://www.apache.org/licenses/LICENSE-2.0
00012 #
00013 # Unless required by applicable law or agreed to in writing, software
00014 # distributed under the License is distributed on an "AS IS" BASIS,
00015 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016 # See the License for the specific language governing permissions and
00017 # limitations under the License.
00018 
00019 require_once '../RawsClient/Raws/Rats.php';
00020 # transient states -> processing not complete
00021 define("REQUEST_RECEIVED", 1);
00022 define("IMPORT_IN_PROGRESS", 2);
00023 define("IMPORT_SUCCEEDED", 3);
00024 define("TRANS_IN_PROGRESS", 4);
00025 define("TRANS_SUCCEEDED", 5);
00026 define("EXPORT_IN_PROGRESS", 6);
00027 # final states
00028 define("FINISHED", 7);
00029 define("IMPORT_FAILED", 8);
00030 define("TRANS_FAILED", 9);
00031 define("EXPORT_FAILED", 10);
00032 # fixed data
00033 define('BASE', 'http://rats.enc01.rambla.be/');
00034 define('SRC_FILENAME', 'test_one_srcfile.mp4'); # src_location
00035 define('TGT_FILENAME', 'test_one.mp4'); # tgt_location
00036 
00037 # Provide your own credentials here
00038 define('USER', 'xxx');
00039 define('PWD', 'xxx');
00040 # provide a path to your local file to be used as transcoding src
00041 define('LOCAL_FILE', '../test_resources/bla.mp4');
00042 # you should specify your transcoding format ID here
00043 define('FORMAT_PROFILE', ''); # E.g. "12"
00044 # if you want to use an existing input profile, you should fill in its ID here, otherwise leave blank
00045 define('INPUT_PROFILE', ''); # E.g. "14"
00046 # if you want to use an existing output profile, you should fill in its ID here, otherwise leave blank
00047 define('OUTPUT_PROFILE', ''); # E.g. "14"
00048 
00049 
00050 # Note that all REST methods (except HEAD) will raise an exception if they don't return an HTTP SUCCESS CODE (200,201,204)
00051 try {
00052   # Create a Rats instance, passing it your login credentials and the base service uri
00053   $rats = new Rats(USER, PWD, BASE);
00054   
00055   # upload a src file and create a src instance
00056   $src_entry = $rats->createSrc(SRC_FILENAME, LOCAL_FILE);
00057   echo "\nUploaded a src file: \n";
00058   echo "Location of uploaded src: " . $src_entry->id->text . "\n";
00059   echo "Filename on the RATS svr: " . $src_entry->content->params->filename->text . "\n";
00060   echo "File will be removed: " . $src_entry->content->params->to_be_removed->text . "\n";
00061     
00062   # use the entry's id, to retrieve the entry once more
00063   $src_entry = $rats->getSrcEntry($src_entry->id->text);
00064   echo "\nRetrieving a src entry:\n";
00065   echo "Retrieved entry: " . $src_entry->id->text . "\n";
00066   
00067   # the filename can also be used to retrieve the entry
00068   $src_entry = $rats->getSrcEntryFromFilename($src_entry->content->params->filename->text);
00069   echo "\nRetrieving a src entry, using its filename:\n";
00070   echo "Retrieved entry from filename: " . $src_entry->content->params->filename->text . "\n";
00071   
00072   # retrieve the feed of all srcs for this user
00073   $src_feed = $rats->getSrcFeed();
00074   echo "\nRetrieving a feed of all existing src entries:\n";
00075   foreach ($src_feed as $src_entry) {
00076     echo "---\n";
00077     echo "location of the src: " . $src_entry->id->text . "\n";
00078     echo "filename: " . $src_entry->content->params->filename->text . "\n";
00079     echo "to be removed: " . $src_entry->content->params->to_be_removed->text . "\n";
00080   }
00081 
00082   # create a new Job, using fixed format profile
00083   $job_entry = $rats->createJobForExistingSrc(OUTPUT_PROFILE, FORMAT_PROFILE, $src_entry->content->params->filename->text, TGT_FILENAME);
00084   $job_id = $job_entry->content->params->id->text;
00085   echo "\nCreating a job to transcode the job:\n";
00086   echo "job ID: " . $job_id . "\n";
00087   echo "job Status: " . $job_entry->content->params->status->text . "\n";
00088   echo "job's format ID: " . $job_entry->content->params->format->text . "\n";
00089 
00090   # find out if it's there
00091   $job_entry = $rats->getJobEntry($job_entry->id->text);
00092   echo "\nRetrieving the job entry from the server:\n";
00093   echo "job ID: " . $job_entry->content->params->id->text . "\n";
00094   echo "job Status: " . $job_entry->content->params->status->text . "\n";
00095   echo "job's format ID: " . $job_entry->content->params->format->text . "\n";
00096   # for a better understanding, you may want to take look at the xml
00097   echo "\nComplete job entry in xml format:\n" . $job_entry->getXML() . "\n\n";
00098   
00099   # get a feed of all jobs
00100   $job_feed = $rats->getJobFeed();
00101   echo "\nRetrieving a feed of all existing job entries:\n";
00102   foreach ($job_feed as $job_entry) {
00103     echo "---\n";
00104     echo "location of the job: " . $job_entry->id->text . "\n";
00105     echo "ID: " . $job_entry->content->params->id->text . "\n";
00106     echo "status: " . $job_entry->content->params->status->text . "\n";
00107   }
00108 
00109 }
00110 catch(Zend_Gdata_App_Exception $e) {
00111     # Report the exception to the user
00112     echo "\nCaught exception: " . get_class($e) . "\n";
00113     echo "Message: " . $e->getMessage() . "\n";
00114     # get the HTTP status code
00115     echo "HTTP Status Code: " . $e->getResponse()->getStatus() . "\n";
00116     echo "Response Body with exception details: " . $e->getResponse()->getBody() . "\n";
00117     # get the raws:error elements
00118     $rawsResponse = Raws::parseRawsResponse($e->getResponse());
00119     echo "Raws Code: " . $rawsResponse->getCode() . "\n";
00120     echo "Raws Message: " . $rawsResponse->getMsg() . "\n";
00121     $reasons = $rawsResponse->getReasons();
00122     foreach ($reasons as $reason) {
00123       echo "Raws Reason: " . $reason . "\n";
00124     }
00125     $details = $rawsResponse->getDetails();
00126     foreach ($details as $key => $value) {
00127       echo "Raws Detail: " . $key . " -> " . $value . "\n";
00128     }
00129 }
00130 catch (Zend_Exception $e) {
00131     echo "Caught exception: " . get_class($e) . "\n";
00132     echo "Message: " . $e->getMessage() . "\n";
00133 }

Generated on Mon Mar 28 15:03:20 2011 for RawsClient PHP by  doxygen 1.5.3