rams_set_traffic_limit.php

00001 <?php
00002 require_once '../RawsClient/Raws/Rams.php';
00003 require_once '../RawsClient/Raws/Rass.php';
00004 
00005 define('RAMS_BASE', 'http://rams.mon01.rambla.be/');
00006 define('RASS_BASE', 'http://rass.cdn01.rambla.be/');
00007 define('USER', 'xxx');
00008 define('PWD', 'xxx');
00009 define('FILEPATH', '/path/to/file.mp4');
00010 
00011 
00012 try {
00013   $rams = new Rams(USER, PWD, RAMS_BASE);
00014 
00015   # get all http traffic for FILEPATH for the current month
00016   $query = new Rams_TrafficQuery();
00017   $query->setType("http");
00018   $query->setMonth("curr");
00019   $query->setYear("curr");
00020   $feed = $rams->getTrafficFeed(FILEPATH, $query);
00021   # RAMS should return a feed containing a single entry
00022   foreach ($feed as $entry) {
00023     echo "Volume: " . $entry->content->params->volume->text . "\n";
00024     echo "Hits: " . $entry->content->params->hits->text . "\n";
00025     # if traffic volume exceeds 0.5 Gb -> delete file from CDN
00026     if ($entry->content->params->volume->text > 0.5) {
00027       $rass = new Rass(USER, PWD, RASS_BASE);
00028       $rass->deleteItem(FILEPATH);
00029       echo "File deleted\n";
00030     }
00031   }    
00032 
00033 }
00034 catch(Zend_Gdata_App_Exception $e) {
00035     # Report the exception to the user
00036     echo "\nCaught exception: " . get_class($e) . "\n";
00037     echo "Message: " . $e->getMessage() . "\n";
00038     # get the HTTP status code
00039     echo "HTTP Status Code: " . $e->getResponse()->getStatus() . "\n";
00040     echo "Response Body with exception details: " . $e->getResponse()->getBody() . "\n";
00041     # get the raws:error elements
00042     $rawsResponse = Raws::parseRawsResponse($e->getResponse());
00043     echo "Raws Code: " . $rawsResponse->getCode() . "\n";
00044     echo "Raws Message: " . $rawsResponse->getMsg() . "\n";
00045     $reasons = $rawsResponse->getReasons();
00046     foreach ($reasons as $reason) {
00047       echo "Raws Reason: " . $reason . "\n";
00048     }
00049     $details = $rawsResponse->getDetails();
00050     foreach ($details as $key => $value) {
00051       echo "Raws Detail: " . $key . " -> " . $value . "\n";
00052     }
00053 }
00054 catch (Zend_Exception $e) {
00055     echo "Caught exception: " . get_class($e) . "\n";
00056     echo "Message: " . $e->getMessage() . "\n";
00057 }

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