Help - Search - Members - Calendar
Full Version: Code Examples... Working
The Planet Forums > API > API Support
avantvision.net
I got it i got stats:

you can check the example at:

https://secure.avantvision.net/portlet/api/test

Updated.. Download now full bandwidth graphics. search the forum.


And the code is:

config.php
CODE
<?php

$paramsurl = array(
"login" => "orbitapiusername",
"password" => "orbitapipassword"
);

$hwid = "hardwareid5digitcode";

?>


index.php
CODE
<?php

echo '<h2>Todays bandwidth:</h2>';
include ("today.php");
echo '<h2>Last 7 days:</h2>';
include ("week.php");
echo '<h2>This month:</h2>';
include ("month.php");

?>


today.php
CODE
<?php

ini_set('soap.wsdl_cache_enabled', false);

$gb_url = 'https://api.theplanet.com/Svc/HardwareBandwidthService.svc?WSDL';

include("config.php");

$hw_bw_svc = new SoapClient($gb_url, $paramsurl);

$bwdaily = $hw_bw_svc->GetBandwidth(new SoapParam($hwid, 'HardwareID'));

$bwtoday = ($bwdaily->ActualUsage);
$bwallowed = ($bwdaily->AllowedUsage);

echo '<p>';
echo 'Allowed Usage by Month:&nbsp;';
echo (($bwallowed)/1000000000);
echo 'GB';
echo '</p>';

echo '<p>';
echo 'Todays bandwidth:&nbsp;';
echo ($bwtoday/1000000);
echo 'MB';
echo '</p>';


echo '<p>';
echo '<img src="imagetoday.php">';
echo '</p>';



?>



week.php
CODE
<?php

ini_set('soap.wsdl_cache_enabled', false);

$gb_url = 'https://api.theplanet.com/Svc/HardwareBandwidthService.svc?WSDL';

include("config.php");

$params= array(
"HardwareID" => "5digitcode", //insert your hardware id here
"StartDate" => date('Y-m-d',strtotime("-7 days")),
"EndDate" => date("Y-m-d")
);

$hw_bw_svc = new SoapClient($gb_url, $paramsurl);

$bwbyrange = $hw_bw_svc->GetBandwidthTotalByRange(new SoapParam($params,"params"));

$bwthismonth = ($bwbyrange->ActualUsage);
$bwallowed = ($bwbyrange->AllowedUsage);

echo '<p>';
echo 'Bandwidth used last 7 days:&nbsp;';
echo ($bwthismonth/1000000);
echo 'MB';
echo '</p>';

echo '<p>';
echo 'Period:&nbsp;';
echo date('Y-m-d',strtotime("-7 days"));
echo '&nbsp;-&nbsp;';
echo date("Y-m-d");
echo '</p>';




echo '<p>';
echo '<img src="imageweekly.php">';
echo '</p>';
?>



month.php
CODE
<?php

ini_set('soap.wsdl_cache_enabled', false);

$gb_url = 'https://api.theplanet.com/Svc/HardwareBandwidthService.svc?WSDL';

include("config.php");

$params= array(
"HardwareID" => "xxxxx", //Insert your hardware id here
"StartDate" => date('Y-m-01'),
"EndDate" => date("Y-m-d")
);

$hw_bw_svc = new SoapClient($gb_url, $paramsurl);

$bwbyrange = $hw_bw_svc->GetBandwidthTotalByRange(new SoapParam($params,"params"));

$bwthismonth = ($bwbyrange->ActualUsage);
$bwallowed = ($bwbyrange->AllowedUsage);

echo '<p>';
echo 'Bandwidth this month:&nbsp;';
echo ($bwthismonth/1000000);
echo 'MB';
echo '</p>';

echo '<p>';
echo 'Period:&nbsp;';
echo date('Y-m-01');
echo '&nbsp;-&nbsp;';
echo date("Y-m-d");
echo '</p>';


echo '<p>';
echo '<img src="imagemonth.php">';
echo '</p>';
?>



The graphics are generated as binary only attaching headers....

imagetoday.php
CODE
<?php

ini_set('soap.wsdl_cache_enabled', false);

$gb_url = 'https://api.theplanet.com/Svc/HardwareBandwidthService.svc?WSDL';

include("config.php");

$hw_bw_svc = new SoapClient($gb_url, $paramsurl);

$bwdaily = $hw_bw_svc->GetBandwidth(new SoapParam($hwid, 'HardwareID'));

$bwtoday = ($bwdaily->ActualUsage);
$bwallowed = ($bwdaily->AllowedUsage);
$bwimg = ($bwdaily->Image);


header('Content-type: image/png');

echo $bwimg;

?>



imageweekly.php
CODE
<?php

ini_set('soap.wsdl_cache_enabled', false);

$gb_url = 'https://api.theplanet.com/Svc/HardwareBandwidthService.svc?WSDL';

include("config.php");

$params= array(
"HardwareID" => "xxxxx", //insert your hardware id here
"StartDate" => date('Y-m-d',strtotime("-7 days")),
"EndDate" => date("Y-m-d")
);

$hw_bw_svc = new SoapClient($gb_url, $paramsurl);

$bwbyrange = $hw_bw_svc->GetBandwidthTotalByRange(new SoapParam($params,"params"));

$bwthismonth = ($bwbyrange->ActualUsage);
$bwallowed = ($bwbyrange->AllowedUsage);
$bwimg = ($bwbyrange->Image);

header('Content-type: image/png');

echo $bwimg;

?>



imagemonth.php
CODE
<?php

ini_set('soap.wsdl_cache_enabled', false);

$gb_url = 'https://api.theplanet.com/Svc/HardwareBandwidthService.svc?WSDL';

include("config.php");

$params= array(
"HardwareID" => "xxxxx", //Insert your hardware id here
"StartDate" => date('Y-m-01'),
"EndDate" => date("Y-m-d")
);

$hw_bw_svc = new SoapClient($gb_url, $paramsurl);

$bwbyrange = $hw_bw_svc->GetBandwidthTotalByRange(new SoapParam($params,"params"));

$bwthismonth = ($bwbyrange->ActualUsage);
$bwallowed = ($bwbyrange->AllowedUsage);
$bwimg = ($bwbyrange->Image);


header('Content-type: image/png');

echo $bwimg;


?>



i put a zip file in english for everyone to use and test and expand

i will work on reboot now.. hope ticket guys don's hate me lol

peace.
avantvision.net
Heres the zip file all bandwidth graphics.. day month week.....

Edited view this instead:

http://forums.theplanet.com/index.php?showtopic=91240
Kevin Hazard
QUOTE (avantvision.net @ Jan 17 2009, 01:54 AM) *
Heres the zip file all bandwidth graphics.. day month week.....

Edited view this instead:

http://forums.theplanet.com/index.php?showtopic=91240


That's awesome!

Thanks for sharing and I'm glad we got your account settings all straightened out.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.