Using the API
The Airbana API now has extensive documentation on it’s own site: http://api.airbana.net/using-the-api/
The old how to is below;
The Airbana API allows other websites or even desktop widgets to access all the information in the Airbana database. You will need the API files file and an API Key to get started!
1. Quick Start
2. Getting a List of Sites in the Airbana database
3. Getting information about an individual site
4. Getting Event Dates
5. Getting GPS Information
6. API Reference
Quick Start
The AirBana API is neatly packaged up in a single php file (zip contains documentation and some examples too!) and is designed to be easy to learn. To start with lets instantiate the class and print out the Airbana version of ‘Hello World’:
<?
include('Airbana.php');
$API = new AirbanaAPI("Your_API_KEY");
print($API->Test());
?>
As you will see its quite easy!
Lets take this a step further and get a list of all the ID’s of Skirmish sites available in the DB:
<?
include('Airbana.php');
$API = new AirbanaAPI("Your_API_KEY");
print($API->GetSiteIDsByType(2);
?>
This will return an XML formatted list of all the SiteID’s in the database that are Skirmish Sites, the XML code will look something similar to this:
<Airbana>
<Site>1</Site>
<Site>2</Site>
<Site>3</Site>
<Site>4</Site>
</Airbana>
With this info you can parse the XML and then get all the information about the chosen Site:
<?
include('Airbana.php');
$API = new AirbanaAPI("Your_API_KEY");
print($API->GetIndivSiteBasic(1);
?>
The fields that will be returned are as below:
<Airbana>
<AirbanaSite id="1">
<Latitude>51.3292</Latitude>
<Longitude>-0.87466</Longitude>
<SiteName>Ambush Eversley7</SiteName>
<Website>www.ambushwargames.com</Website>
</AirbanaSite>
</Airbana>
In some cases you don’t want to have to parse the XML and pull out what you require which is why some functions have HTML alternatives:
<?
include('Airbana.php');
$API = new AirbanaAPI("Your_API_KEY");
print($API->GetIndivSiteBasic_HTML(1);
?>
This will return the following code:
<div id="Airbana_Site">
<h3>Example Name</h3>
<span id="Airbana_Site_Address">
Address Line 1<br/>
Address Line 2<br/>
AA1 0ZZ<br/>
</span>
<span id="Airbana_Site_Email">
name@example.com<br/>
</span>
<span id="Airbana_Site_Phone">
01234 567890<br/>
</span>
<span id="Airbana_Site_Features">
UKARA_Image<br/>
UKASGB_Image<br/>
Environment_Image<br/>
OnSiteShop_Image<br/>
Explosives_Image<br/>
BatteryCharge_Image<br/>
Repair_Image<br/>
</span>
</div>
This will allow you to define the AirbanaSite class in your sites CSS and format it as required.
Hopefully this quick start will show you the benefits of the Airbana API, good luck with your experimenting!
Getting a List of Sites in the Airbana database
This was briefly touched on in the Quick Start however there are several functions in the API for getting the list of sites, many of these are designed to allow filtering or attributes so you don’t have to!
Sites in Airbana are designated a ‘Type’ Field to determine what they are. At the moment an entry can be one of the following:
Skirmish 1
Retailer – 2
As covered briefly above this allows you to filter straight away between Airsoft Retailers and Skirmish Sites. To get this information out of Airbana use the following code:
<?
include('Airbana.php');
$API = new AirbanaAPI("Your_API_KEY");
print($API->GetSiteIDsByType(2);
?>
The resulting XML is not very useful but you could then use it to pull information about each site in the DB:
<?
include('Airbana.php');
$API = new AirbanaAPI("Your_API_KEY");
$ReturnedXML = $API->GetSiteIDsByType(2);
$xml = @simplexml_load_string($ReturnedXML);
if ($xml)
{
$XMLArray = XMLToArray($xml);
}
else
{
$array = false;
}
foreach($XMLArray as $AirbanaSite)
{
foreach($AirbanaSite as $Site)
{
print($API->GetIndivSiteBasic($Site['SiteID']));
}
}
function XMLToArray($xml)
{
if (!($xml->children()))
{
return (string) $xml;
}
foreach ($xml->children() as $child)
{
$name=$child->getName();
if (count($xml->$name)==1)
{
$element[$name] = XMLToArray($child);
} else
{
$element[][$name] = XMLToArray($child);
}
}
return $element;
}
?>
Getting information about an individual site
Once you have identified a site that you want to work with in more detail the Airbana API comes into its own. There are several functions that allow you to get additional info about a site:
<?
include('Airbana.php');
$API = new AirbanaAPI("Your_API_KEY");
print($API->GetIndivSiteDetail(1));
print($API->GetWikiEntry(1));
print($API->GetPrices(1));
?>
Getting Event Dates
Its all well and good knowing where sites are but maybe you want to pull the information about when they are! With the Airbana API this is easy. To get all the Events between today and 7 days away simply use this code:
<?
include('Airbana.php');
$API = new AirbanaAPI("Your_API_KEY");
$StartDate = date("Y-m-d");
$EndDate = date("Y-m-d", mktime(0, 0, 0, date("m") , date("d")+7, date("Y")));
print($API->GetGameDates($StartDate,$EndDate));
?>
Getting GPS Information
All this information is well and good but your Garmin or TomTom device don’t know how to use any of this information so the Airbana API can pump out all the information you need straight to TomTom and Garmin friendly file formats!
<?
include('Airbana.php');
$API = new AirbanaAPI("Your_API_KEY");
print($API->GetGarmin());
?>
or
<?
include('Airbana.php');
$API = new AirbanaAPI("Your_API_KEY");
print($API->GetTomTom());
?>
API Reference
Read the full documentation here: http://api.airbana.co.uk/api-documentation/