rass_meta_vocabs.php

00001 <?php
00002 # Sample script for RAWS tutorial 12: see http://rambla.eu/ for more info.
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 require_once '../RawsClient/Raws/Rass.php';
00018 
00019 # Provide your own RASS credentials here
00020 define('USER', 'xxx'); # your user account name
00021 define('PWD', 'xxx'); # your user account pwd
00022 define('CDN', "cdn0x"); # your sub-cdn (e.g. "cdn01")
00023 
00024 define('BASE', 'http://rass.' . CDN . '.rambla.be/');
00025 
00026 
00027 # all RASS API methods (except HEAD) will raise an exception if they don't return an HTTP SUCCESS CODE (200,201,204)
00028 try {
00029   
00030   # Instantiate an object that manages the RASS connection, passing it your login credentials and the base service uri
00031   $rass = new Rass(USER, PWD, BASE);
00032 
00033   # Manage vocabularies
00034   echo "Getting feed of existing vocabularies:";
00035   $feed = $rass->getVocabFeed();
00036   foreach ($feed as $entry) {
00037     echo "\n\nName: " . $entry->content->params->name->text;
00038     echo "\nXML Namespace: " . $entry->content->params->xml_namespace->text;
00039     echo "\nDescription: " . $entry->content->params->description->text;
00040   }
00041 
00042   echo "\n\nCreating vocabulary:";
00043   $entry = $rass->createVocab("megamix", "http://megamix.org/meta/");
00044   echo "\n\nName: " . $entry->content->params->name->text;
00045   echo "\nXML Namespace: " . $entry->content->params->xml_namespace->text;
00046   echo "\nDescription: " . $entry->content->params->description->text;
00047 
00048   echo "\n\nGetting single vocabulary by name:";
00049   $entry = $rass->getVocabEntry("megamix");
00050   echo "\n\nName: " . $entry->content->params->name->text;
00051   echo "\nXML Namespace: " . $entry->content->params->xml_namespace->text;
00052   echo "\nDescription: " . $entry->content->params->description->text;
00053 
00054   echo "\n\nUpdating existing vocabulary:";
00055   $entry = $rass->updateVocab("megamix", "http://megamix.net/meta/", "supacatchatroopa");
00056   echo "\n\nName: " . $entry->content->params->name->text;
00057   echo "\nXML Namespace: " . $entry->content->params->xml_namespace->text;
00058   echo "\nDescription: " . $entry->content->params->description->text;
00059   
00060   // echo "\n\nDeleting vocabulary.";
00061   // $entry = $rass->deleteVocab("megamix");
00062 
00063 }
00064 catch(Zend_Gdata_App_Exception $e) {
00065     # Report the exception to the user
00066     echo "\nCaught exception: " . get_class($e) . "\n";
00067     echo "Message: " . $e->getMessage() . "\n";
00068     # get the HTTP status code
00069     echo "HTTP Status Code: " . $e->getResponse()->getStatus() . "\n";
00070     echo "Response Body with exception details: " . $e->getResponse()->getBody() . "\n";
00071     # get the raws:error elements
00072     $rawsResponse = Raws::parseRawsResponse($e->getResponse());
00073     echo "Raws Code: " . $rawsResponse->getCode() . "\n";
00074     echo "Raws Message: " . $rawsResponse->getMsg() . "\n";
00075     $reasons = $rawsResponse->getReasons();
00076     foreach ($reasons as $reason) {
00077       echo "Raws Reason: " . $reason . "\n";
00078     }
00079     $details = $rawsResponse->getDetails();
00080     foreach ($details as $key => $value) {
00081       echo "Raws Detail: " . $key . " -> " . $value . "\n";
00082     }
00083 }
00084 catch (Zend_Exception $e) {
00085     echo "Caught exception: " . get_class($e) . "\n";
00086     echo "Message: " . $e->getMessage() . "\n";
00087 }

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