Skip to content

Instantly share code, notes, and snippets.

@jackfranklin
Created June 16, 2011 17:08
Show Gist options
  • Save jackfranklin/1029705 to your computer and use it in GitHub Desktop.
Save jackfranklin/1029705 to your computer and use it in GitHub Desktop.
jQuery.extend({
forrstApi: function(method,callback,params,options) {
var defaults = {
apiVersion: 'v2',
debugMode: false,
url: 'http://forrst.com/api/v2/'
},
callback = callback || undefined,
params = (params===undefined ? {} : params),
params = jQuery.param(params),
options = $.extend({}, defaults, options),
methods = {
stats: function() {
$.ajax({
url: options.url + 'stats/',
dataType: 'jsonp',
success: function(d) {
callback(d);
}
});
},
usersinfo: function() {
$.ajax({
url: options.url+"users/info/?" + params,
dataType: 'jsonp',
success: function(d) {
callback(d);
}
});
},
userposts: function() {
$.ajax({
url: options.url+"users/posts/?" + params,
dataType: 'jsonp',
success: function(d) {
callback(d);
}
});
},
postsshow: function() {
$.ajax({
url: options.url+"posts/show/?" + params,
dataType: 'jsonp',
success: function(d) {
callback(d);
}
})
},
postsall: function() {
$.ajax({
url: options.url+"posts/all/?" + params,
dataType: 'jsonp',
success: function(d) {
callback(d);
}
})
},
postslist: function() {
$.ajax({
url: options.url+"posts/list/?" + params,
dataType: 'jsonp',
success: function(d) {
callback(d);
}
})
}
};
if(typeof methods[method] == 'function') {
methods[method]();
};
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment