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
101
|
;var ShaderAPI = {}
ShaderAPI.limit = 50
// info - fetch a single shader
// id: shader id
ShaderAPI.info = function(id, cb){
ShaderAPI.fetch({
f: "info",
id: id
}, cb)
}
// all - fetch all shaders
ShaderAPI.all = function(cb){
ShaderAPI.fetch({
f: "all"
}, cb)
}
// range - fetch a pageful of results
// limit: number of shaders to fetch
// offset: number of results to skip
ShaderAPI.range = function(limit, offset, cb){
ShaderAPI.fetch({
f: "range",
limit: limit || ShaderAPI.limit,
last: offset
}, cb)
}
// latest - get the latest N shaders
// limit: number of shaders to fetch
ShaderAPI.latest = function(limit, cb){
if (! cb) {
cb = limit
limit = ShaderAPI.limit
}
ShaderAPI.fetch({
f: "range",
limit: limit || ShaderAPI.limit
}, cb)
}
// page - get a page of N results
// page: page number, start counting at 1
// limit: number of shaders to fetch
ShaderAPI.page = function(page, limit, cb){
ShaderAPI.fetch({
f: "range",
last: (page-1) * limit,
limit: limit || ShaderAPI.limit
}, cb)
}
// history - get all previous versions of a shader
// id: shader id
ShaderAPI.history = function(id, cb){
ShaderAPI.fetch({
f: "history",
id: id
}, cb)
}
// username - get all ids by a user
ShaderAPI.username = function(username, cb){
ShaderAPI.fetch({
f: "username",
username: username
}, cb)
}
// list_users - list all users
ShaderAPI.list_users = function(cb){
ShaderAPI.fetch({
f: "list_users"
}, cb)
}
// originals - get the earliest version of all named shaders
ShaderAPI.originals = function(cb){
ShaderAPI.fetch({
f: "originals"
}, cb)
}
// fetch - AJAX wrapper
ShaderAPI.fetch = function(params, cb){
$.ajax({
url: "http://asdf.us/cgi-bin/im/shader/view",
data: params,
dataType: "jsonp",
success: function(data){
if (data.SUCCESS) {
cb(null, data.data)
}
else if (data.ERROR) {
cb(data.ERROR, data.data)
}
}
})
}
|