This repository has been archived by the owner on Aug 15, 2019. It is now read-only.
/
jquery.forrstapi.js
100 lines (80 loc) · 2.98 KB
/
jquery.forrstapi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
Author: Jack Franklin
HomePage: http://github.com/jackfranklin/Forrst-API-jQuery-Wrapper
License: Released under the CC Share-Alike license: http://creativecommons.org/licenses/by-sa/3.0/
version: v2
Thanks for looking at the source code! Half of what I know came from looking at code so feel free to have a good old look around! If you want to make any edits, please fork it on Github. And if you have any questions, Skype: jack_franklin.
For more information about the functions and parameters, please view the Github home page and read the README. You can't miss it. There's all the information you need, right there in that file.
*/
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]();
};
}
});