-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapiary.apib
572 lines (413 loc) · 16.3 KB
/
apiary.apib
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
FORMAT: 1A
HOST: http://api.dobigcrossword.com/
# DoBigCrossword
This API is able to handle the functionality of a multiuser crossword creator site
## Authentication Account [/auth/account/]
### Register a user [POST]
Use this function if you want to create a new user. Returns
- 200 if the registration was successful
- 403 if the email address is already in use
- 403 if the password is wrong (too short, too long, too simple, etc.)
+ Request (application/json)
{
"email": "[email protected]",
"password": "abc123",
"displayed_name": "Pocak"
}
+ Response 200 (application/json)
{
"result": "OK"
}
+ Response 403 (application/json)
{
"result": "ERROR",
"message": "Email address already in use."
}
+ Response 403 (application/json)
{
"result": "ERROR",
"message": "The password doesn't meet the requirements."
}
### Check if email address exists [GET]
With this function the client can check whether a given email address is already in use or not. It returns
- 200 if the email address is a valid email address, in this case the `is_existing` field contains the boolean value whether the email address is already used or not
- 400 if the email address is invalid
+ Request (application/json)
{
"email": "[email protected]",
}
+ Response 200 (application/json)
{
"result": "OK",
"is_existing": false
}
+ Response 400 (application/json)
{
"result": "ERROR",
"message": "The email address in invalid."
}
## Login [/auth/login/]
### Log in a user [POST]
Use this function to log in a user.
- 200 if the registration was successful. In this case a token is returned which has to be used for the further communication and identification of the user.
- 403 if the email address and/or the password are wrong
+ Request (application/json)
{
"email": "[email protected]",
"password": "abc123",
}
+ Response 200 (application/json)
{
"result": "OK",
"token": "a546b362c73d84f95f003c66ab3ed0c9"
}
+ Response 403 (application/json)
{
"result": "ERROR",
"message": "Email address or password is wrong."
}
### Logout [DELETE]
Use this function to invalidate the user's token (DELETE the is-logged-in status).
- 200 if the invalidation was successful (the user was logged in and is not logged in anymore).
- 403 if the user was not logged in
+ Request (application/json)
{
"token": "a546b362c73d84f95f003c66ab3ed0c9"
}
+ Response 200 (application/json)
{
"result": "OK",
}
+ Response 403 (application/json)
{
"result": "ERROR",
"message": "There was no logged in user with this token."
}
## Password Reset [/auth/password_reminder/]
### Password reminder [POST]
Use this function to request a password reminder email.
- 200 if the email address exists. It returns the normalised form of the email address where the password reminder email has been sent to. The email contains a link to the password reset page and a verification code. If the user visits the password reset page then they should provide the email address, the verification code and the new password. Then the new password is set for the user.
- 403 if the email address doesn't exist
+ Request (application/json)
{
"email": " [email protected] "
}
+ Response 200 (application/json)
{
"result": "OK",
"email": "[email protected]"
}
+ Response 403 (application/json)
{
"result": "ERROR",
"message": "Unknown email address."
}
### Password reminder [PUT]
Use this function to adjust a new password.
- 200 if the email address exists and based on the verification code, the new password for that user has been set succesfully.
- 403 if the email address doesn't exist.
- 401 is the email address exists but the verification code is incorrect.
+ Request (application/json)
{
"email": "[email protected]",
"verification_code": "2wd8y4j9fw6dc8",
"new_password": "abCD@1234"
}
+ Response 200 (application/json)
{
"result": "OK",
"email": "[email protected]"
}
+ Response 403 (application/json)
{
"result": "ERROR",
"message": "Unknown email address."
}
+ Response 401 (application/json)
{
"result": "ERROR",
"message": "Wrong verification code"
}
## Crosswords [/crosswords/]
### List of crosswords [GET]
Returns the list of the crosswords the user is allowed to list. The user is determined from the token.
The `title_filter` can contain asterisk symbols as wildcards standing for zero or more characters. If not given then there is no filtering based on title. The matching is not case sensitive.
The `order_by` specifies in what order the results are to return. Default is `-creation_time`.
Possible orders:
- `creation_time`: when the crossword was created
- `last_edited`: when the crossword was changed last time
- `title`: title of the crossword
- `num_cells`: number of the cells within the crossword (=width*height)
- `manager`: the crossword manager's name
The `order_by` value means ascending order, or can be prefixed by minus symbol to indicate descending order.
Example: `"order_by": ["-manager", "title"]`
The elements of the `order_by` value mean primary, secondary, etc. ordering rules.
+ Request (application/json)
{
"title_filter": "*ssword of S*",
"order_by": ["creation_time"],
}
+ Response 200 (application/json)
{
"result": "OK",
"crosswords": [
{
"crossword_id": 1,
"title": "Crossword for Sati",
"last_edited": "2016-12-31 23:59:59",
"manager_id": 1,
"manager_name": "Pocak"
},
{
"crossword_id": 2,
"title": "Another crossword",
"last_edited": "2017-12-31 23:59:59",
"manager_id": 1,
"manager_name": "Pocak"
}
]
}
## Crossword [/crossword/]
### Create a new crossword [POST]
Creates a new crossword. The `join_policy` may have the following values with the corresponsing meaning:
- `opened`: everybody can join if want
- `approved`: the user may send a request to the crossword manager who can approve or disprove the join request
- `invitation`: the crossword manager can send invitations to other users in email who can join to this crossword if they want
+ Request (application/json)
{
"width": 64,
"height": 48,
"title": "Birthday Crossword for Sati #90",
"join_policy": "everybody"
}
+ Response 200 (application/json)
{
"result": "OK",
"crossword_id": 1
}
### Modify an existing crossword [PUT]
Changes some attributes of a crossword.
The `resize_method_*` are ignored if the corresponding `width` and `height` parameters are not given. Their possible values are the followings:
- `centre`: the central column/row of the new crossword will be the central column/row of the old crossword. For the rounding rules, see below.
- `change-top`: the topmost rows will be removed or empty rows will be inserted there
- `change-left`: the leftmost columns will be removed or empty columns will be inserted there
- `change-bottom`: the bottommost rows will be removed or empty rows will be inserted there
- `change-right`: the rightmost columns will be removed or empty columns will be inserted there
In case of `centre` resize_methods, the following rounding rules are to be applied:
- If the number of new columns/rows to insert is an odd number then below/right from the old content will be one more column inserted. That is, the old content will be shifted by half cell towards the upper left corner.
- If the number of new columns/rows to delete is an odd number then above/left from the old content will be one more column deleted. That is, the old content will be shifted by half cell towards the upper left corner.
Examples:
- If the crossword has 1*1 cell and the following structure arrives:
{
"width": 10,
"height": 8,
"resize_method_horizontal": "change-left",
"resize_method_vertical": "centre"
}
then the new crossword will have 10 columns and 8 rows (adding 9 columns and 7 rows) and the original cell will have 9 new cells on its left, 3 cells above it and 4 below.
- If the crossword has 4*4 cell and the following structure arrives:
{
"width": 3,
"height": 1,
"resize_method_horizontal": "change-left",
"resize_method_vertical": "centre"
}
then the new crossword will have 3 columns and 1 row (deleting one column and 3 rows). In this case the three cells of the new crossword will be last three cells of the second row of the original crossword.
Like this:
ABCD
EFGH => FGH
IJKL
MNOP
If the `manager_id` field is present then the new manager will get a notification email that they are invited to be the new manager of the crossword. They have to accept this invitation via the invitation API. Until it is accepted, the manager is still theold manager.
+ Request (application/json)
{
"width": 64,
"height": 48,
"resize_method_horizontal": "centre",
"resize_method_vertical": "change-top",
"title": "Birthday Crossword for Sati #90",
"join_policy": "everybody",
"manager_id": 2
}
+ Response 200 (application/json)
{
"result": "OK",
"crossword_id": 1
}
### Return details of a crossword [GET /{crossword_id}]
Return details of the requested crossword.
- `width` and `height` are the dimensions of the crossword
- `num_black` is the number of cells that are set to black
- `num_letters` is the number of the cells that have assigned a letter
The following fields are not returned because they can be derived from other values:
- `num_white` = `width` * `height` - `num_black`
- `filled_ratio` = ( `num_black` + `num_letters` ) / ( `width` * `height` )
The timestamps are returned in UTC.
+ Request (application/json)
{
}
+ Response 200 (application/json)
{
"result": "OK",
"crossword_id": 1,
"width": 20,
"height": 10,
"num_black": 30,
"num_letters": 40,
"creation_at": "2000-12-31 23:59:59",
"lasd_modified_at": "2001-12-31 23:59:59",
"manager": {
"user_id": 1,
"user_name": "pocak"
}
}
+ Response 404 (application/json)
{
"result": "Error",
"message": "The crossword doesn't exist."
}
+ Response 401 (application/json)
{
"result": "Error",
"message": "There is no permission the create allocations for the user"
}
### Return users of a crossword and their statistics [GET /{crossword_id}/users]
Returns the users of the given crossword. For each user it tells how many letters and how many black cells are defined by them.
+ Request (application/json)
{
}
+ Response 200 (application/json)
{
"result": "OK",
"users": [
{
"user_id": 1,
"user_name": "pocak",
"registered_at": "2000-12-31 23:59:59",
"num_letters": 12,
"num_black": 23
},
{
"user_id": 2,
"user_name": "ciri",
"registered_at": "2000-12-31 23:59:59",
"num_letters": 12,
"num_black": 23
}
]
}
+ Response 404 (application/json)
{
"result": "Error",
"message": "The crossword doesn't exist."
}
+ Response 401 (application/json)
{
"result": "Error",
"message": "There is no permission the create allocations for the user"
}
## Allocations [/allocation/]
### Create an allocation [POST]
Creates a new allocation for a user (and unallocate the previous one if it exists) in the given crossword.
If the user is not given then the user defined by the token is used. If the user is given and is different from the token's user then the requester has to be the manager of the crossword.
The `allocations` member of the response is an N-digit-long string where N = `width` * `height` from the request and which contains `1`s for each successfully allocated cells and `0`s for the unsuccessfull ones, row by row. A cell allocation may be unsuccessful if the cell is alreaady allocated by someone else.
- 200 if the allocation is partly or completely successful (0 or more cells were successfull allocated)
- 404 if the requester has no right to allocate cells for the user.
+ Request (application/json)
{
"crossword_id": 1,
"user_id": 1,
"x": 0,
"y": 10,
"width": 20,
"height": 15
}
+ Response 200 (application/json)
{
"result": "OK",
"x": 0,
"y": 10,
"width": 2,
"height": 3,
"allocations": "111100"
}
+ Response 404 (application/json)
{
"result": "Error",
"message": "The crossword doesn't exist."
}
+ Response 401 (application/json)
{
"result": "Error",
"message": "There is no permission the create allocations for the user"
}
### Delete the allocation of a user [DELETE]
Deletes the current allocation of the user. If the user is not given then the user belonging to the token is used.
+ Request (application/json)
{
"crossword_id": 1,
"user_id": 1
}
+ Response 200 (application/json)
{
"result": "OK"
}
+ Response 404 (application/json)
{
"result": "Error",
"message": "There is no permission to delete allocations for the user"
}
## Cells [/cells/]
### Returns the current values of the cells within an area [GET]
Returns the cells of the given crossword within the requested area.
- The "letters" in the response contain the letters of the subsequent cells row-by-row. Empty cells are represented by spaces, black cells by chr(127).
- The "allocators" is the user_ids of the users who allocated each cells (in same order as "letters").
- The "definitions" is the list of the cells in random order that have horizontal and/or vertical definition.
+ Request (application/json)
{
"crossword_id": 1,
"x": 0,
"y": 10,
"width": 20,
"height": 15
}
+ Response 200 (application/json)
{
"result": "OK",
"x": 0,
"y": 10,
"width": 3,
"height": 2,
"letters": "AB CDE",
"allocators": [
1000,
1000,
1000,
1001
null,
999
],
"definitions": [
{
"x": 0,
"y": 0,
"v_def": "Vertical definition",
"h_def": "Horizontal definition"
},
{
"x": 0,
"y": 1,
"v_def": "Capital of Australia"
},
]
}
+ Response 401 (application/json)
{
"result": "Error",
"message": "The user is not allowed to read the crossword data."
}
+ Response 404 (application/json)
{
"result": "Error",
"message": "The crossword doesn't exist."
}