<?php
/**
* Class to interface with the capescience weather services
* This is a SOAP based class
* @author Paul Scott
* @version 0.9
* @package phpclasses
* @example
* include("weatherservice_class_inc.php");
* $w = new weatherservice();
* $list = $w->getCountryList();
* print_r($list);
*
* NOTE: If you are behind a proxxy, please add the following to your call:
* $client = new soapclient('http://live.capescience.com/wsdl/GlobalWeather.wsdl',true,'proxy
server','proxyport',proxypassword');
* Taking note of the proxy authentication in the soapclient instantiation!
*/
class weatherservice
{
/**
* Method to retrieve country list of available weather services
* @author Paul Scott
* @return array countryList
*/
function getCountryList()
{
// Pull in the NuSOAP code
require_once('lib/nusoap/nusoap.php');
// Create the client instance
$client = new soapclient('http://live.capescience.com/wsdl/GlobalWeather.wsdl',true);
$err = $client->getError();
if ($err) {
// Display the error
return $err;
// At this point, you know the call that follows will fail
}
$result = $client->call('listCountries',array());
return $result;
}//end function countrylist
/**
* Method to return an array of the locations (stations) within a country
* @param (string)$country
* @return array result
*/
function searchByCountry($country)
{
// Pull in the NuSOAP code
require_once('lib/nusoap/nusoap.php');
// Create the client instance
$client = new soapclient('http://live.capescience.com/wsdl/GlobalWeather.wsdl',true);
$err = $client->getError();
if ($err) {
// Display the error
return $err;
// At this point, you know the call that follows will fail
}
$result = $client->call('searchByCountry',array($country));
return $result;
}//end function
/**
*Method to retrieve the weather report for a given station
* @param $locationCode
* @return array report
*/
function getWeatherReport($locationCode)
{
// Pull in the NuSOAP code
require_once('lib/nusoap/nusoap.php');
// Create the client instance
$client = new soapclient('http://live.capescience.com/wsdl/GlobalWeather.wsdl',true);
$err = $client->getError();
if ($err) {
// Display the error
return $err;
// At this point, you know the call that follows will fail
}
$result = $client->call('getWeatherReport',array($locationCode));
return $result;
}//end function
/**
* Method to display the weather report as a string
* @param string $locationCode
* @return string $string
*/
function showAll($locationCode)
{
$ar = $this->getWeatherReport($locationCode);
$string = $ar['station']['string'];
$string .= "<br>";
$string .= $ar['temperature']['string'];
return $string;
}
}//end class
?>