00001 <?php
00002 # Sample that explains you how to use the PHP RawsClient lib to communicate with the RAMS 'customer' resources ('payed', 'used' and 'users').
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:
00022 define('USER', 'XXX');
00023 define('PWD', 'XXX');
00024
00025 try {
00026 $rams = new Rams(USER, PWD, BASE);
00027
00028 echo "->Retrieving a RAMS Customer Payed feed:\n";
00029 # Pass a Query-String to limit the feed elements to files only
00030 $query = new Rams_PayedQuery();
00031 $query->setFrom("2010-1");
00032 $query->setUntil("2010-10");
00033 # get the feed
00034 $feed = $rams->getPayedFeed($query);
00035 foreach ($feed as $entry) {
00036 echo "Year: " . $entry->content->params->year->text . "\n";
00037 echo "Month: " . $entry->content->params->month->text . "\n";
00038 echo "Credits: " . $entry->content->params->credits->text . "\n";
00039 echo "Formula: " . $entry->content->params->formula->text . "\n";
00040 echo "\n";
00041 }
00042
00043 echo "->Retrieving a RAMS Customer Used feed:\n";
00044 # Pass a Query-String to limit the feed elements to files only
00045 $query = new Rams_UsedQuery();
00046 $query->setFrom("2010-1");
00047 $query->setUntil("2010-10");
00048 $query->setTotal("1"); # also receive the totals as part of the response
00049 # get the feed
00050 $feed = $rams->getUsedFeed($query);
00051 foreach ($feed as $entry) {
00052 echo "Credits: " . $entry->content->params->credits->text . "\n";
00053 echo "Product: " . $entry->content->params->product->text . "\n";
00054 echo "Name: " . $entry->content->params->name->text . "\n";
00055 echo "\n";
00056 }
00057
00058 echo "->Retrieving a RAMS Customer Users feed:\n";
00059 # get the feed
00060 $feed = $rams->getUsersFeed($query);
00061 foreach ($feed as $entry) {
00062 echo "Name: " . $entry->content->params->name->text . "\n";
00063 echo "Email: " . $entry->content->params->email->text . "\n";
00064 echo "\n";
00065 }
00066
00067
00068 }
00069 catch(Zend_Gdata_App_Exception $e) {
00070 # Report the exception to the user
00071 echo "\nCaught exception: " . get_class($e) . "\n";
00072 echo "Message: " . $e->getMessage() . "\n";
00073 # get the HTTP status code
00074 echo "HTTP Status Code: " . $e->getResponse()->getStatus() . "\n";
00075 echo "Response Body with exception details: " . $e->getResponse()->getBody() . "\n";
00076 # get the raws:error elements
00077 $rawsResponse = Raws::parseRawsResponse($e->getResponse());
00078 echo "Raws Code: " . $rawsResponse->getCode() . "\n";
00079 echo "Raws Message: " . $rawsResponse->getMsg() . "\n";
00080 $reasons = $rawsResponse->getReasons();
00081 foreach ($reasons as $reason) {
00082 echo "Raws Reason: " . $reason . "\n";
00083 }
00084 $details = $rawsResponse->getDetails();
00085 foreach ($details as $key => $value) {
00086 echo "Raws Detail: " . $key . " -> " . $value . "\n";
00087 }
00088 }
00089 catch (Zend_Exception $e) {
00090 echo "Caught exception: " . get_class($e) . "\n";
00091 echo "Message: " . $e->getMessage() . "\n";
00092 }