The old and unloved blog of Chris Keene, Brighton, UK.

Talis Aspire is a new-ish Reading List system used at the University of Sussex Library.

On Aspire, a url for a Department looks like this:
http://liblists.sussex.ac.uk/departments/anthropology.html

A page for a course looks like this (for course l6061):
http://liblists.sussex.ac.uk/courses/l6061.html

The nice thing is that you can replace the ‘.html’ with .json or .rdf – while the html only has a link to the related list, the json and rdf expose other links and relationships, such as the department.

For us, most (but not all) courses only have one list. URLs for lists are not predictable in the same way as the courses URL. E.g.
http://liblists.sussex.ac.uk/lists/EEC1E2AA-C350-DAFC-BDE4-1E9EF5EC69E5.html

So what if you want to link to a list from an external system.

The University has a portal which includes for students a list of their courses and provides a link to those that have a reading list. Two issues: it needs to know which courses have a reading list on Talis Aspire, and it needs a way to link to them.

Sussex Direct, links to reading lists

The easiest way to achieve the former is for the central admin/portal server to query (make a http request) for each course provided by the University, if it gets a 404, no list exists for that course. It can then flag each course that has a list (using a field in the database).

And what about linking to a list. We actually have three options. The first is to simply link to the course link above (second link from the top), this will show any lists for that course, but will normally require the user to click on the single reading list link to see the list items, which isn’t ideal. The second method is to process the json data in the step above (where we were checking for the existence of a course page), the data will include the URL for the list(s) which could then be stored in the portal DB.

But the third option is the easiest. Turns out there is a nice URL you can use, similar to the one above, which will take the user directly to a list for a course, if there is only one, if there is more than more it will show a list (of, ummm, lists) instead, and this URL is predictable for any given course code.

Here’s an example of both scenarios. Thanks for Chris Clarke at Talis for the information on this.

http://liblists.sussex.ac.uk/courses/l6061/lists.html [one list, norm]
http://liblists.sussex.ac.uk/courses/v1367/lists.html (json) [two lists]

Finally, I knocked up some bad php to demonstrate this. It queries the url above, and returns either the urls of the list(s) or a message to say there is no course or lists for that course code.

http://www.lib.sussex.ac.uk/coursechecker.php?course=v1367
http://www.lib.sussex.ac.uk/coursechecker.php?course=l6066
http://www.lib.sussex.ac.uk/coursechecker.php?course=abc [doesn’t exist]

<?php

# This script is past a course code
# it returns any reading lists attached to that coursecode

$baseurl = “http://liblists.sussex.ac.uk”;

$coursecode = $_GET[“course”];
if ($coursecode == “” OR $coursecode == null) {
echo “no course”;
exit;
}

# this url will exist if there are lists for this course,
# and will not exist (404) if there are not
$url = $baseurl . “/courses/” . $coursecode . “/lists.json”;
# …also available in html and rdf

# Get webpage using curl
$ch      = curl_init( $url );
# OPTION: don’t put it on screen
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($ch);
$header  = curl_getinfo( $ch );
curl_close($ch);
$statuscode = $header[‘http_code’];

# if status code 404 then no page
if ($statuscode == ‘404’) {
echo ‘NOREADINGLIST’;
}

# we have a page for this course
elseif ($statuscode == ‘200’) {
# use json to return url to list(s), though if only one the original url,
# ending in html, will take you to it.
get_list_url($page);
}

# or maybe we have another status code
else {
echo ‘NOTSURE’;
}

function get_list_url ($page) {
# JSON
$data = json_decode($page, true); #true=array

foreach ($data as $listurl => $stuff) {
# we only want lists. not courses or departments
if (preg_match(“//lists//”, $listurl)) {
echo “$listurl<br>n”;
}
}

}

?>

So once a week, the central portal will query Talis Aspire for each course to see if there is a reading list, and store the result. And it will link to lists using the URL http://liblists.sussex.ac.uk/courses/{coursecode}/lists.html

Tags