-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdocumentation.js
329 lines (286 loc) · 8.45 KB
/
documentation.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
// Collection Schema:
{
title: String,
url: String, // the url is the title scraped of invalid url characters (this is a relative reference on our site)
description: String,
stars: Number,
user: {
provider: String, // for third-party authentication
id: String, // id of user on third-party authientication system
fullName: String,
givenName: String
},
links: [
{
url: String, // external url of the link
title: String,
description: String
} // More links here...
]
}
// Note: Nothing in the API is set in stone. If anyone has any suggestions to
// make it better, more convient, or any other feedback on it, please express it.
// Thanks.
// Postman link to example queries:
'https://www.getpostman.com/collections/478b3030a71770ebf8c4'
// Endpoints:
'--------------------------------------------------------------';
'POST to /api/collection/create';
// Create a new collection
// Example POST data:
{
"title": "A New Collection",
"description": "So many good links",
"user": { // populated by userManagement Factory
"provider": "github",
"id": "1234",
"fullName": "John Johnson",
"givenName": "John"
},
"links": [
{
"url": "http://www.duck.com",
"title": "Ducks!",
"description": "So one might think"
}
]
};
// Note: the user data is currently populated by the userManagement Factory:
$scope.collection.user = userManagement.user;
// On success, returns a collection data object:
{
"__v":0, // This is the model version generated by mongoose (it can ignore it for our current objectives)
"_id":"540791bd17e7918007c35f5c", // This is the unique collection id generated by MongoDB. Very useful for doing fast lookups
"title":"A New Collection",
"url":"anewcollection", // Unique url, relative to our domain. With Angular: 'ourDomain.io/#/:url'
"description":"So many good links",
"stars":0, // Defaults to 0
"updatedAt":"2014-09-03T22:10:05.680Z",
"createdAt":"2014-09-03T22:10:05.679Z",
"user": {
"givenName":"John",
"fullName":"John Johnson",
"id":"1234",
"provider":"github"
},
"links": [
{
"url":"http://www.duck.com",
"title":"Ducks!",
"description":"So one might think",
"_id":"540791bd17e7918007c35f5d" // MongoDB generated unique id of this link
}
]
};
// Example failed create. This is probably due to another collection with the same url
// The server enforces unique urls
null;
'--------------------------------------------------------------';
'POST to /api/collection/update';
// Updates a collection
// This endpoint is flexible on its inputs. If you'd like, you can have the client edit
// the actual collection object and send the entire object (don't have to worry about diffs).
// Example:
{
"_id":"540791bd17e7918007c35f5c",
"title": "A New Collection",
"description": "I've changed the description.", // THIS HAS CHANGED
"user": {
"provider": "github",
"id": "1234",
"fullName": "John Johnson",
"givenName": "John"
},
"links": [
{
"url": "http://www.duck.com",
"title": "Ducks!",
"description": "Nope, no ducks" // THIS HAS CHANGED
}
]
};
// Returns a collection data object with the updated fields, everything else remains the same
{
"__v":0
,"_id":"540791bd17e7918007c35f5c",
"description":"I've changed the description.", // THIS HAS BEEN UPDATED
"title":"A New Collection",
"url":"anewcollection",
"user":{
"givenName":"John",
"fullName":"John Johnson",
"id":"1234",
"provider":"github"
},
"stars":0,
"updatedAt":"2014-09-03T22:30:21.363Z",
"createdAt":"2014-09-03T22:10:05.679Z", // THIS HAS BEEN UPDATED
"links":[
{
"url":"http://www.duck.com",
"title":"Ducks!",
"description":"Nope, no ducks", // THIS HAS BEEN UPDATED
"_id":"5407967d017c7988022579ba"
}
]
};
// If the update fails, it returns null
// It is also possible to just send the data you would like to update
// Here we are just adding a link.
{
"_id":"540791bd17e7918007c35f5c",
"links": [
{
"url": "http://www.duck.com",
"title": "Ducks!",
"description": "Nope, no ducks"
},
{
"url": "http://www.duckduckgo.com",
"title": "Real Ducks",
"description": "Yay"
}
]
}
// Currently, the only way to add a link is with an update. High on the
// todo list is an endpoint to add a link directly.
// Another example, updating stars:
{
"_id":"540791bd17e7918007c35f5c",
"stars": 1
};
// You can also update by title rather than _id.
// This is much slower than by _id, and since the client should have the id
// so this will not likely ever be used.
{
"title":"A New Collection",
"stars": 100
}
// Note: Currently there is no validation on updates. This is on the todo.
// We must enforce no updates to immutable fields!
var immutableFields = [
"_id",
"title",
"url",
"user",
"__v"
]; // The user should not be allowed to change these fields
'--------------------------------------------------------------';
'POST to /api/collection/addlink';
// Add a link to a collection
// Expects data of a specific format.
// Data must have an _id property refering to the target collections _id
// and a links property refering to an array of links to add to the
// collection
{
"_id":"5405f70e23089aac14e47c53",
"links": [
{
"url": "http://www.google.com",
"title": "A duck alternative",
"description": "Why no ducks?"
}
]
}
// Returns an updated collection data object
'--------------------------------------------------------------';
'GET to /api/collection/:url';
// Retrieves a collection
// A request to:
'http://localhost:3000/api/collection/anewcollection'
// Returns a collection data object:
{
"__v":0,
"_id":"540791bd17e7918007c35f5c",
"description":"I've changed the description.",
"title":"A New Collection",
"url":"anewcollection",
"user":{
"givenName":"John",
"fullName":"John Johnson",
"id":"1234",
"provider":"github"
},
"stars":100,
"updatedAt":"2014-09-03T22:49:01.329Z",
"createdAt":"2014-09-03T22:10:05.679Z",
"links":[
{
"url":"http://www.duck.com",
"title":"Ducks!",
"description":"Nope, no ducks",
"_id":"54079820fa1e5048175724e4"
},{
"url":"http://www.duckduckgo.com",
"title":"Real Ducks",
"description":"Yay",
"_id":"54079820fa1e5048175724e3"
}
]
};
// A request to:
'http://localhost:3000/api/collection/DoesNotExist'
// Returns:
null;
'--------------------------------------------------------------';
'GET to /api/user/:userProvider/:userId';
// Retrieves the meta data for all the users collections
// Note: if it is more convenient, this can be refactored to return
// all the collection data, not just the meta data
// A request to:
'http://localhost:3000/api/user/github/1234'
// Returns an array of collection meta data objects:
[
{
"_id":"540791bd17e7918007c35f5c",
"description":"I've changed the description.",
"title":"A New Collection",
"url":"anewcollection",
"user":{
"givenName":"John",
"fullName":"John Johnson",
"id":"1234",
"provider":"github"
},
"stars":100
}
// There would be more collections here if this example user had more collections
];
// A request to:
'http://localhost:3000/api/user/NoSuchProvider/NonExistentUser'
// Returns an empty array:
[];
'--------------------------------------------------------------';
'GET to /api/all';
// Retrieves the meta data for all collections in the db
// This will probably be impractable if the db gets to be a good size
// A request to:
'http://localhost:3000/api/all'
// Returns an array of collection meta data objects:
[
{
"_id":"540629a19850458c1ec42c60",
"description":"Angular Tutorials",
"title":"Angular",
"url":"angular",
"user":{
"givenName":"Oslo",
"fullName":"Oslo Bar",
"id":"Oslo",
"provider":"test"
},
"stars":0
},{
"_id":"54065ce927cc69d4045015e4",
"description":"The cutest",
"title":"Puppies",
"url":"puppies",
"user":{
"provider":"test",
"fullName":"Oslo",
"id":"Oslo",
"givenName":"Oslo"
},
"stars":0
}
];