rams_concurrent.php

00001 <?php
00002 # Sample that explains you how to use the PHP RawsClient lib to communicate with the RAMS 'concurrent' resource
00003 #
00004 # Copyright (C) 2010 rambla.be
00005 
00006 # Licensed under the Apache License, Version 2.0 (the "License");
00007 # you may not use this file except in compliance with the License.
00008 # You may obtain a copy of the License at
00009 #
00010 #      http://www.apache.org/licenses/LICENSE-2.0
00011 #
00012 # Unless required by applicable law or agreed to in writing, software
00013 # distributed under the License is distributed on an "AS IS" BASIS,
00014 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 # See the License for the specific language governing permissions and
00016 # limitations under the License.
00017 
00018 require_once '../RawsClient/Raws/Rams.php';
00019 
00020 # Provide your own credentials here
00021 define('BASE', 'http://rams.mon01.rambla.be/');
00022 define('USER', 'XXX');
00023 define('PWD', 'XXX');
00024 
00025 try {
00026   # Initialize the HTTP connection object
00027   $rams = new Rams(USER, PWD, BASE);
00028 
00029   echo "->Retrieving a RAMS Concurrent Feed:\n";
00030   # Pass a Query-String to get all concurrent entries recorded on March 21 2010 of type "rtmp-live" (40 entries per page)
00031   $query = new Rams_ConcurrentQuery();
00032   $query->setFrom("2010-10-3-21-00");
00033   $query->setUntil("2010-10-3-22-00");
00034   $query->setType("rtmp-live");
00035   $query->setPaginateBy("50");
00036   # get the first page feed
00037   $feed = $rams->getConcurrentV1Feed($query);
00038   while($feed) # start a while loop, in case there are more than 50 results => multiple pages
00039   { 
00040     foreach ($feed as $entry) {
00041       # Retrieve the entry element's "type" attribute
00042       echo "Found " . $entry->type . " entry \n";
00043       # Retrieve the value of the params child elements
00044       echo "Path: " . $entry->content->params->path->text . "\n";
00045       echo "Hits: " . $entry->content->params->hits->text . "\n";
00046       echo "Timestamp: " . $entry->content->params->timestamp->text . "\n";
00047       echo "Datetime: " . $entry->content->params->datetime->text . "\n";
00048       echo "\n";
00049     }
00050     # Check if RAMS has any more results left
00051     echo "URL at which next page can be retrieved : " $rams->getNextLink($feed) . "\n";
00052     # Check how many pages are available
00053     echo "Number of the last page can be retrieved : " $rams->getLastNr($feed) . "\n";
00054     echo "URL at which last page can be retrieved : " $rams->getLastLink($feed) . "\n";
00055     # get next feed, by sending a new request to the next link inside this page
00056     $feed = $rams->getNextFeed($feed);
00057   }
00058 
00059 }
00060 catch(Zend_Gdata_App_Exception $e) {
00061     # Report the exception to the user
00062     echo "\nCaught exception: " . get_class($e) . "\n";
00063     echo "Message: " . $e->getMessage() . "\n";
00064     # get the HTTP status code
00065     echo "HTTP Status Code: " . $e->getResponse()->getStatus() . "\n";
00066     echo "Response Body with exception details: " . $e->getResponse()->getBody() . "\n";
00067     # get the raws:error elements
00068     $rawsResponse = Raws::parseRawsResponse($e->getResponse());
00069     echo "Raws Code: " . $rawsResponse->getCode() . "\n";
00070     echo "Raws Message: " . $rawsResponse->getMsg() . "\n";
00071     $reasons = $rawsResponse->getReasons();
00072     foreach ($reasons as $reason) {
00073       echo "Raws Reason: " . $reason . "\n";
00074     }
00075     $details = $rawsResponse->getDetails();
00076     foreach ($details as $key => $value) {
00077       echo "Raws Detail: " . $key . " -> " . $value . "\n";
00078     }
00079 }
00080 catch (Zend_Exception $e) {
00081     echo "Caught exception: " . get_class($e) . "\n";
00082     echo "Message: " . $e->getMessage() . "\n";
00083 }

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