Created
July 20, 2010 08:48
-
-
Save adrianshort/482702 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
SutMobLib API server-side example | |
by Adrian Short adrian.short@gmail.com | |
6 March 2010 | |
There are four possible outcomes of the API call: | |
1. The library is not running today due to an "exception", eg. a bank holiday. The API returns the reason for this exception in $result->exception. | |
2. The library is visiting various housebound readers at home. This is on the schedule so the times of this activity are specified but the location is not. | |
3. The library is at a "normal" stop. We get the arrival/departure times and location for this. | |
4. The library is between stops or back at base. | |
*/ | |
define('ENDPOINT', 'http://projects.adrianshort.co.uk/sutmoblib/location.php'); | |
$result = json_decode(file_get_contents(ENDPOINT)) or die("Couldn't access the API"); | |
if (isset($result->exception)) | |
{ | |
$message = sprintf("%s: The library is not running today.", $result->exception); | |
} | |
elseif ('HOUSEBOUND' == $result->stop->type) | |
{ | |
$message = sprintf("The library is currently visiting housebound readers around the borough until %s.", | |
$result->stop->depart_12); | |
} | |
elseif ('NORMAL' == $result->stop->type) | |
{ | |
$message = sprintf("The library is at %s, %s. It will be there until %s.", | |
$result->stop->location->street, | |
$result->stop->location->town, | |
$result->stop->depart_12); | |
} | |
else | |
{ | |
$message = "The library is between stops or back at base."; | |
} | |
?> | |
<html> | |
<head> | |
<title>Sutton Mobile Library API Example</title> | |
</head> | |
<body> | |
<h1><?php echo $message ?></h1> | |
<h2>API Result</h2> | |
<pre><?php print_r($result) ?></pre> | |
<p><a href="http://www.sutton.gov.uk/index.aspx?articleid=915">Sutton Mobile Library schedule</a></p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment