rams_storage.php

00001 <?php
00002 # Sample that explains you how to use the PHP RawsClient lib to communicate with the RAMS 'storage' 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 "\n->Retrieving a RAMS Storage Feed:\n";
00030   # Pass a Query-String to limit the feed elements to files only
00031   $query = new Rams_StorageQuery();
00032   $query->setMonth("all");
00033   $query->setYear("2010");
00034   # get the feed
00035   $feed = $rams->getStorageFeed("/", $query);
00036   foreach ($feed as $entry) {
00037     # Retrieve the entry element's "month" and "year" attributes
00038     echo "Found entry with year = " . $entry->year . " and month = " . $entry->month . "\n";
00039     # Retrieve the value of the params child elements
00040     echo "Volume: " . $entry->content->params->volume->text . "\n";
00041     echo "Location: " . $entry->content->params->location->text . "\n";
00042     echo "Updated: " . $entry->content->params->updated->text . "\n";
00043   }
00044 
00045 }
00046 catch(Zend_Gdata_App_Exception $e) {
00047     # Report the exception to the user
00048     echo "\nCaught exception: " . get_class($e) . "\n";
00049     echo "Message: " . $e->getMessage() . "\n";
00050     # get the HTTP status code
00051     echo "HTTP Status Code: " . $e->getResponse()->getStatus() . "\n";
00052     echo "Response Body with exception details: " . $e->getResponse()->getBody() . "\n";
00053     # get the raws:error elements
00054     $rawsResponse = Raws::parseRawsResponse($e->getResponse());
00055     echo "Raws Code: " . $rawsResponse->getCode() . "\n";
00056     echo "Raws Message: " . $rawsResponse->getMsg() . "\n";
00057     $reasons = $rawsResponse->getReasons();
00058     foreach ($reasons as $reason) {
00059       echo "Raws Reason: " . $reason . "\n";
00060     }
00061     $details = $rawsResponse->getDetails();
00062     foreach ($details as $key => $value) {
00063       echo "Raws Detail: " . $key . " -> " . $value . "\n";
00064     }
00065 }
00066 catch (Zend_Exception $e) {
00067     echo "Caught exception: " . get_class($e) . "\n";
00068     echo "Message: " . $e->getMessage() . "\n";
00069 }

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