Adrian Short 14 years ago
commit
c73de9a7f7
1 changed files with 52 additions and 0 deletions
  1. +52
    -0
      sutmoblib-api-example.php

+ 52
- 0
sutmoblib-api-example.php View File

@@ -0,0 +1,52 @@
<?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>

Loading…
Cancel
Save