Skip to content

Instantly share code, notes, and snippets.

@Retozi
Last active August 29, 2015 14:02
Show Gist options
  • Save Retozi/957aba405c8e611f5ec9 to your computer and use it in GitHub Desktop.
Save Retozi/957aba405c8e611f5ec9 to your computer and use it in GitHub Desktop.
function makeDigestFun(key, callback) {
return function (err, res) {
clearRequestQueue(key);
if (err && err.timeout === TIMEOUT) {
callback(ASYNC.TIMEOUT);
} else if (res.status === 400) {
Api.logout();
} else if (!res.ok) {
callback(ASYNC.ERROR);
} else {
callback(res);
}
};
}
function get(url) {
return request
.get(url)
.timeout(TIMEOUT)
.query({authtoken: _token});
}
Api = {
getUserLists: function(callback) {
var key = 'user-lists';
startRequest(key, callback);
_pendingRequests[key] = get(makeUrl("/user-lists")).end(makeDigestFun(key, callback));
},
function activateEntity (id) {
if (id) {
Api.getEntityData(id, function(res) {
if (ASYNC.isAny(res)) {
updateEntityData(res);
} else {
updateEntityData(res.body.entity);
}
});
} else {
updateEntityData(null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment