rams_total.php

00001 <?php
00002 # Sample that explains you how to use the PHP RawsClient lib to communicate with the RAMS 'total' 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   $rams = new Rams(USER, PWD, BASE);
00027 
00028   echo "->Retrieving a RAMS Total Feed:\n";
00029   # Pass a Query-String to limit the feed elements to files only
00030   $query = new Rams_TotalQuery();
00031   $query->setYear("2010");
00032   $query->setMonth("11");
00033   # get the feed
00034   $feed = $rams->getTotalFeed($query);
00035   foreach ($feed as $entry) {
00036     # Retrieve the entry element's "type" attribute
00037     echo "Found " . $entry->type . " entry \n";
00038     # Retrieve the value of the params child elements
00039     echo "Unique: " . $entry->content->params->unique->text . "\n";
00040     echo "Hits: " . $entry->content->params->hits->text . "\n";
00041     echo "Events: " . $entry->content->params->events->text . "\n";
00042     echo "Volume: " . $entry->content->params->volume->text . "\n";
00043     echo "Last Modified: " . $entry->content->params->last_modified->text . "\n";
00044     echo "\n";
00045   }
00046 
00047   
00048 }
00049 catch(Zend_Gdata_App_Exception $e) {
00050     # Report the exception to the user
00051     echo "\nCaught exception: " . get_class($e) . "\n";
00052     echo "Message: " . $e->getMessage() . "\n";
00053     # get the HTTP status code
00054     echo "HTTP Status Code: " . $e->getResponse()->getStatus() . "\n";
00055     echo "Response Body with exception details: " . $e->getResponse()->getBody() . "\n";
00056     # get the raws:error elements
00057     $rawsResponse = Raws::parseRawsResponse($e->getResponse());
00058     echo "Raws Code: " . $rawsResponse->getCode() . "\n";
00059     echo "Raws Message: " . $rawsResponse->getMsg() . "\n";
00060     $reasons = $rawsResponse->getReasons();
00061     foreach ($reasons as $reason) {
00062       echo "Raws Reason: " . $reason . "\n";
00063     }
00064     $details = $rawsResponse->getDetails();
00065     foreach ($details as $key => $value) {
00066       echo "Raws Detail: " . $key . " -> " . $value . "\n";
00067     }
00068 }
00069 catch (Zend_Exception $e) {
00070     echo "Caught exception: " . get_class($e) . "\n";
00071     echo "Message: " . $e->getMessage() . "\n";
00072 }

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