rams_geo.php

00001 <?php
00002 # Sample that explains you how to use the PHP RawsClient lib to communicate with the RAMS 'geo' resources ('host', 'domain' and 'city').
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 Domain Feed:\n";
00030   $query = new Rams_GeoQuery();
00031   $query->setPaginateBy("50"); # retrieve 50 results in a single response
00032   $query->setOrder("desc"); # results with highest volume are returned first
00033   $feed = $rams->getGeoDomainFeed($query);
00034   foreach ($feed as $entry) {
00035     # Retrieve the entry element's "type" attribute
00036     echo "Found " . $entry->type . " entry \n";
00037     # Retrieve the value of the params child elements
00038     echo "Domain: " . $entry->content->params->domain->text . "\n";
00039     echo "Volume: " . $entry->content->params->volume->text . "\n";
00040     echo "Hits: " . $entry->content->params->hits->text . "\n";
00041     echo "Last Modified: " . $entry->content->params->last_modified->text . "\n";
00042     echo "\n";
00043   }
00044   
00045   echo "->Retrieving a RAMS City Feed:\n";
00046   # Pass a Query-String to limit the feed elements to files only
00047   $query = new Rams_GeoQuery();
00048   $query->setYear("2010");
00049   $query->setMonth("9");
00050   $query->setType("rtmp");
00051   $query->setPaginateBy("100");
00052   $query->setOrder("asc");
00053   # get the feed
00054   $feed = $rams->getGeoCityFeed($query);
00055   foreach ($feed as $entry) {
00056     # Retrieve the entry element's "type" attribute
00057     echo "Found " . $entry->type . " entry \n";
00058     # Retrieve the value of the params child elements
00059     echo "Country: " . $entry->content->params->country->text . "\n";
00060     echo "Region: " . $entry->content->params->region->text . "\n";
00061     echo "City: " . $entry->content->params->city->text . "\n";
00062     echo "Volume: " . $entry->content->params->volume->text . "\n";
00063     echo "Hits: " . $entry->content->params->hits->text . "\n";
00064     echo "Last Modified: " . $entry->content->params->last_modified->text . "\n";
00065     echo "\n";
00066   }
00067   
00068   echo "->Retrieving a RAMS Host Feed:\n";
00069   $query = new Rams_GeoQuery();
00070   $query->setYear("2010");
00071   $query->setMonth("9");
00072   $query->setPaginateBy("100");
00073   $query->setOrder("desc");
00074   $feed = $rams->getGeoHostFeed($query);
00075   foreach ($feed as $entry) {
00076     # Retrieve the entry element's "type" attribute
00077     echo "Found " . $entry->type . " entry \n";
00078     # Retrieve the value of the params child elements
00079     echo "Host: " . $entry->content->params->host->text . "\n";
00080     echo "Volume: " . $entry->content->params->volume->text . "\n";
00081     echo "Hits: " . $entry->content->params->hits->text . "\n";
00082     echo "Last Modified: " . $entry->content->params->last_modified->text . "\n";
00083     echo "\n";
00084   }
00085   
00086 
00087   
00088 }
00089 catch(Zend_Gdata_App_Exception $e) {
00090     # Report the exception to the user
00091     echo "\nCaught exception: " . get_class($e) . "\n";
00092     echo "Message: " . $e->getMessage() . "\n";
00093     # get the HTTP status code
00094     echo "HTTP Status Code: " . $e->getResponse()->getStatus() . "\n";
00095     echo "Response Body with exception details: " . $e->getResponse()->getBody() . "\n";
00096     # get the raws:error elements
00097     $rawsResponse = Raws::parseRawsResponse($e->getResponse());
00098     echo "Raws Code: " . $rawsResponse->getCode() . "\n";
00099     echo "Raws Message: " . $rawsResponse->getMsg() . "\n";
00100     $reasons = $rawsResponse->getReasons();
00101     foreach ($reasons as $reason) {
00102       echo "Raws Reason: " . $reason . "\n";
00103     }
00104     $details = $rawsResponse->getDetails();
00105     foreach ($details as $key => $value) {
00106       echo "Raws Detail: " . $key . " -> " . $value . "\n";
00107     }
00108 }
00109 catch (Zend_Exception $e) {
00110     echo "Caught exception: " . get_class($e) . "\n";
00111     echo "Message: " . $e->getMessage() . "\n";
00112 }

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