not really known
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

sutmoblib-api-example.php 1.6 KiB

14年前
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. SutMobLib API server-side example
  4. by Adrian Short adrian.short@gmail.com
  5. 6 March 2010
  6. There are four possible outcomes of the API call:
  7. 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.
  8. 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.
  9. 3. The library is at a "normal" stop. We get the arrival/departure times and location for this.
  10. 4. The library is between stops or back at base.
  11. */
  12. define('ENDPOINT', 'http://projects.adrianshort.co.uk/sutmoblib/location.php');
  13. $result = json_decode(file_get_contents(ENDPOINT)) or die("Couldn't access the API");
  14. if (isset($result->exception))
  15. {
  16. $message = sprintf("%s: The library is not running today.", $result->exception);
  17. }
  18. elseif ('HOUSEBOUND' == $result->stop->type)
  19. {
  20. $message = sprintf("The library is currently visiting housebound readers around the borough until %s.",
  21. $result->stop->depart_12);
  22. }
  23. elseif ('NORMAL' == $result->stop->type)
  24. {
  25. $message = sprintf("The library is at %s, %s. It will be there until %s.",
  26. $result->stop->location->street,
  27. $result->stop->location->town,
  28. $result->stop->depart_12);
  29. }
  30. else
  31. {
  32. $message = "The library is between stops or back at base.";
  33. }
  34. ?>
  35. <html>
  36. <head>
  37. <title>Sutton Mobile Library API Example</title>
  38. </head>
  39. <body>
  40. <h1><?php echo $message ?></h1>
  41. <h2>API Result</h2>
  42. <pre><?php print_r($result) ?></pre>
  43. <p><a href="http://www.sutton.gov.uk/index.aspx?articleid=915">Sutton Mobile Library schedule</a></p>
  44. </body>
  45. </html>