WIP: StackExchange API jQuery Library
by Adam Patridge
HTML
<ul>
<li><a id="get-questions" href="#">Get questions</a></li>
<li><a id="get-users" href="#">Get users</a></li>
</ul>
<ul id="results"></ul>
<script type="text/javascript" src="http://dl.dropbox.com/u/6593594/cdn/JSLINQ.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="http://jquery-jsonp.googlecode.com/files/jquery.jsonp-2.1.4.min.js"></script>
<script type="text/javascript" src="http://dl.dropbox.com/u/6593594/cdn/uri.js"></script>
JavaScript
/***Let JSLint know what the expected global variables are***/
/*global jQuery, $, google, JSLINQ, URI */
(function ($) {
"use strict";
var apiHost = "api.stackexchange.com";
$.stackExchangeApi = {};
$.stackExchangeApi.buildUrl = function () {
var urlSoFar = URI("https://api.stackexchange.com/2.0/"),
maxIdsCount = 1,
limitToIds = function (ids) {
if (ids && ids.length && ids.length > maxIdsCount) {
console.warn("Max IDs exceeded, limiting to " + maxIdsCount);
ids.splice(maxIdsCount, ids.length - maxIdsCount);
}
urlSoFar.filename(ids.join(";"));
},
justPage = function (pageNumber) {
urlSoFar.addSearch("page", pageNumber);
},
itemsPerPage = function (perPageCount) {
urlSoFar.addSearch("pagesize", count);
},
startingFromDate = function (unixEpochTime) {
urlSoFar.addSearch("fromdate", unixEpochTime);
},
upToDate = function (unixEpochTime) {
urlSoFar.addSearch("todate", unixEpochTime);
},
orderedByQuestions = function () {
return {
byActivity: function () {
urlSoFar.addSearch("order", "activity");
},
byDateCreated: function () {
urlSoFar.addSearch("order", "creation");
},
byVoteScore: function () {
urlSoFar.addSearch("order", "votes");
},
byRecentHottest: function () {
urlSoFar.addSearch("order", "hot");
},
byWeeklyHottest: function () {
urlSoFar.addSearch("order", "week");
},
byMonthlyHottest: function...