This will display a link to a random database from your AZ list in LibGuides. You can narrow your results by subject if you like. Every time the page is loaded this code will show a different database.
You might wish to place this on a research guide or even in your discovery tool. FYI, you don’t need to include the text “Have you considered?” You can easily just use the database link itself.
Works with: APIs for Librarians: Springshare Auth Server
The API call, which is written in jQuery, sends a request to a proxy server that handles authorization for the API and then grabs the data and then returns it to our code. You’re welcome to use the Springshare Auth Server mentioned just above or roll your own.
The code takes a look at the returned list of databases and randomly selects one to display. You can easily limit the possible databases to specific subjects or it can be from your entire AZ list.
#random-database
1
2
3
4
<div id="random-database-container">
<h4 id="random-database-header">Have you considered?</h4>
<div id="random-database"></div>
</div>
1
2
3
4
#random-database-container {font-family: 'Martel', serif;font-size: 1.2em;text-align: center;}
#random-database-header {margin-bottom: 0px;}
#random-database {margin: 10px 0;}
#random-database a {text-decoration: none;}
YOUR_SERVER_HERE.herokuapp.com
will be replaced with your Heroku server’s URL or whatever proxy server you’re using to handle authentication. It’s free and easy to use the one I built for you: APIs for Librarians: Springshare Auth Server/az?subject_ids=41905
can be customized based on the requirements of the LibGuides API. If you want to work with all of your AZ List you can make this: /az
1
2
3
4
5
6
7
8
9
10
11
12
13
14
var apis4librarians_randomDatabase = (function() {
var getRandomDatabase = function() {
$.getJSON(
"https://YOUR_SERVER_HERE.herokuapp.com/springshare/libguides/passthrough?what=/az?subject_ids=41905",
function(result) {
console.log(result);
var entry = result[Math.floor(Math.random() * result.length)];
var randomDatabase = '<a href="' + entry.url + '">' + entry.name + "</a>";
$("#random-database").html(randomDatabase);
}
);
};
getRandomDatabase();
})();