-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.apib
More file actions
557 lines (355 loc) · 13.4 KB
/
docs.apib
File metadata and controls
557 lines (355 loc) · 13.4 KB
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
FORMAT: 1A
HOST: http://35.177.199.115/development
# FloBot Server API
This document outlines the routes for the FloBot web server, stored on AWS. Most routes require the user to be authenticated.
Authentication is checked by validating the bearer token in `Authorization` header.
# Data Structures
## Delivery
+ id: `23` (required, number)
+ state (enum) - Represents the state of the delivery
+ IN_QUEUE - Delivery has not been started
+ MOVING_TO_SOURCE - Robot is in transit to source target
+ AWAITING_AUTHENTICATION_SENDER - Robot is waiting for the sender to authenticate
+ AWAITING_PACKAGE_LOAD - Robot is awaiting the sender to signal they are done loading the package
+ PACKAGE_LOAD_COMPLETE - Sender has signalled they are done loading the package
+ MOVING_TO_DESTINATION - Robot is in transit to destination target
+ AWAITING_AUTHENTICATION_RECEIVER - Robot is waiting for the receiver to authenticate
+ AWAITING_PACKAGE_RETRIEVAL - Robot is awaiting the receiver to signal they are done picking up the package
+ PACKAGE_RETRIEVAL_COMPLETE - Receiver has signalled they are done picking up the package
+ COMPLETE - Delivery has been completed
+ UNKNOWN - Error state
+ priority: `0` (number, required)
+ from (required, Target)
+ to (required, Target)
+ sender: `jdoe` (required, string)
+ receiver: `drseuss` (required, string)
+ packageList (array[Package])
+ robot: `0` (number) - Once the delivery is underway, this contains the robot it has been assigned to.
## UserCore
+ username: `jsmith` (required, string)
## PackageCore
+ name: `Blood sample` (required, string)
+ description: `Blood sample for patient Jane Doe` (string)
+ priority: 0 (number, required) - The lower, the higher the priority
## Package (PackageCore)
+ id: `11` (required, number)
## Target
+ id: `54` (required, number) - ID of the target
+ name: `Reception` (required, string) - Name of the target
+ description: `The first-floor reception in Block A` (string) - Description of the target
+ color: `red` (required, nullable) - Color of the target
## BadRequestError
+ code: `400` (number, required)
+ error: `Your request is malformed` (string, required)
## UnauthenticatedError
+ code: `401` (number, required)
+ error: `You must authenticate in order to access this resource` (string, required)
## ForbiddenError
+ code: `403` (number, required)
+ error: `You do not have permission to access this resource` (string, required)
## NoResourceError
+ code: `404` (number, required)
+ error: `The requested resource does not exist` (string, required)
# Group Deliveries
This resource group exposes the routes required by the app to access, modify, create and delete deliveries.
## All deliveries [/deliveries]
This resource collects data on deliveries.
### Gets list of deliveries [GET]
+ Response 200
+ Attributes (array[Delivery])
### Creates a delivery [POST]
This request takes in the IDs for the source and destination Targets and creates
a new delivery in the server.
The user must provide a valid bearer token, matching the sender's currently active token,
to submit a delivery.
The server responds with the newly created package object.
+ Request
+ Headers
Authorization: Bearer 8aHjr65ULEZItDm7eEeoHwO55CDnbgdJ
+ Attributes (PackageCore)
+ from: `23` (required, number) - ID of departure Target
+ to: `12` (required, number) - ID of arrival Target
+ sender: `jdoe` (required, string) - Username of sender User
+ receiver: `drseuss` (required, string) - Username of receiver User
+ Response 200
+ Attributes (Delivery)
+ Response 400
+ Attributes (BadRequestError)
+ friendly: `There's no user with that username`
+ Response 403
+ Attributes (ForbiddenError)
+ friendly: `The sender has to be yourself`
### Clear queue [DELETE]
+ Response 200
## Delivery [/delivery/{id}]
+ Parameters
+ id: `12` - ID of the delivery object being retrieved
### Get delivery information [GET]
+ Response 200
+ Attributes (Delivery)
+ Response 404
+ Attributes (BadRequestError)
+ friendly: `There's no delivery with that ID!`
### Partially update delivery [PATCH]
Partially updates the resource, replacing the supplied fields with the new ones.
Valid fields to update are: `state`.
+ Request for a delivery in queue that is now underway
+ Attributes
+ state: `MOVING_TO_SOURCE`
+ robot: `0`
+ Request for other patches, except authentications
+ Attributes
+ state: `MOVING_TO_SOURCE`
+ robot: `0`
+ Response 200
+ Attributes (Delivery)
+ Response 400
+ Attributes (BadRequestError)
+ friendly: `This robot is already delivering something.`
+ Response 403
+ Attributes (ForbiddenError)
+ friendly: `Illegal state transition attempted.`
+ Response 404
+ Attributes (NoResourceError)
+ friendly: `There's no delivery with that ID!`
### Delete delivery [DELETE]
+ Response 200
+ Response 404
+ Attributes (BadRequestError)
+ friendly: `There's no delivery with that ID!`
# Group Users
This resource group exposes the routes required by the app to obtain the user list.
## All users [/users]
This resource collects data on the whole collection of users.
### Gets list of users [GET]
+ Response 200
+ Attributes (array[UserCore])
# Group Targets
## Targets [/targets]
### Get all targets [GET]
+ Response 200
+ Attributes (array[Target])
### Add target [POST]
+ Request
+ Attributes
+ name: `Dr. Jack's office` (string, required)
+ description (string, nullable)
+ color: `red` (string)
+ Response 200
+ Attributes (array[Target])
+ Response 400
+ Attributes (BadRequestError)
+ friendly: `Target information is badly formatted`
### Clear targets [DELETE]
+ Response 200
## Target [/target/{id}]
+ Parameters
+ id: `4` - ID of target
### Retrieve target [GET]
+ Response 200
+ Attributes (array[Target])
+ Response 404
+ Attributes (NoResourceError)
+ friendly: `This target does not exist`
### Partially update target [PATCH]
+ Request update colour mapping
+ Attributes
+ color: `red` (string)
+ Response 200
+ Attributes (Target)
+ Response 400
+ Attributes (BadRequestError)
+ friendly: `Target information is badly formatted`
+ Response 404
+ Attributes (NoResourceError)
+ friendly: `This target does not exist`
### Delete target [DELETE]
+ Response 200
+ Response 404
+ Attributes (NoResourceError)
+ friendly: `This target does not exist`
# Group Authentication
## Login [/login]
Allows the user to login. Returns a bearer token if successful.
### POST
+ Request
+ Attributes
+ username: `jdoe` (required, string)
+ password: `password123` (required, string)
+ Response 200
+ Attributes
+ bearer: `c6e1f9d0-a241-4e29-8baa-2625f1e3a779`
+ Response 401
+ Attributes (UnauthenticatedError)
+ friendly: `Incorrect user/password combination`
## Register [/register]
Allows the user to register. Returns a bearer token if successful.
### POST
+ Request
+ Attributes
+ username: `jdoe` (required, string)
+ name: `Dr. John Doe` (required, string)
+ password: `password123` (required, string)
+ Response 200
+ Attributes
+ bearer: `c6e1f9d0-a241-4e29-8baa-2625f1e3a779`
+ Response 401
+ Attributes (UnauthenticatedError)
+ friendly: `Incorrect user/password combination`
# Group Robot
This resource group exposes the required routes for the vision system to interface with the robot. All robot routes require passing a robot ID. In the current system, there's only one robot available (ID 0).
## Batch updates [/robot/{robotid}/batch]
### Batch retrieval [GET]
Makes a single, batch retrieval of all robot fields. This route is mean to avoid the overhead of two requests being issued by the robot, seeing that it has very limited connectivity capabilities.
+ Parameters
+ robotid: `0` (number, required) - ID of the robot
+ Response 200
+ Attributes
+ angle: `50.0`
+ correction: `4.5`
+ motor: true
+ distance: `250.0`
+ delivery - Shown only if the robot is currently tasked with transporting a delivery
+ senderAuthToken: `GgkWGPKyCz` - The QR token that is shown to the sender for authentication
+ receiverAuthToken: `5wx7kAhRaY` - The QR token that is shown to the receiver for authentication
+ state: `MOVING_TO_SOURCE` - Current state of the delivery object the robot is carrying. The robot can monitor this so it knows when it should show the QR (and which one it should show)
### Batch update [POST]
Makes a batch update on some of the robots fields. Fields that can be updated in this way are: `correction`, `angle`, `motor` and `distance`.
+ Parameters
+ robotid: `0` (number, required) - ID of the robot
+ Request with a single field
+ Attributes
+ angle: `50.0`
+ Request with all fields
+ Attributes
+ angle: `50.0`
+ correction: `4.5`
+ motor: true
+ distance: `250.0`
+ Response 200
+ Attributes
+ angle: `50.0`
+ correction: `4.5`
+ motor: true
+ distance: `250.0`
+ delivery - Shown only if the robot is currently tasked with transporting a delivery
+ senderAuthToken: `GgkWGPKyCz` - The QR token that is shown to the sender for authentication
+ receiverAuthToken: `5wx7kAhRaY` - The QR token that is shown to the receiver for authentication
+ state: `MOVING_TO_SOURCE` - Current state of the delivery object the robot is carrying. The robot can monitor this so it knows when it should show the QR (and which one it should show)
## Correction [/robot/{robotid}/correction]
Exposes a mechanism to issue angle corrections to the robot.
### Retrieve correction [GET]
+ Parameters
+ robotid: `0` (number, required) - ID of the robot
+ Response 200
+ Attributes
+ correction: `4.5`
### Issue a correction [POST]
Issues a new correction to the angle of the robot. If a correction has already been issued, returns an error.
+ Parameters
+ robotid: `0` (number, required) - ID of the robot
+ Request
+ Attributes
+ correction: `4.5`
+ Response 200
+ Attributes
+ correction: `4.5`
+ Response 400
+ Attributes (BadRequestError)
+ friendly: `Invalid correction angle.`
## Angle [/robot/{robotid}/angle]
Exposes a mechanism to issue angles to the robot.
### Retrieve angle [GET]
+ Parameters
+ robotid: `0` (number, required) - ID of the robot
+ Response 200
+ Attributes
+ angle: `100.0`
### Issue an angle [POST]
+ Parameters
+ robotid: `0` (number, required) - ID of the robot
+ Request
+ Attributes
+ angle: `100.0`
+ Response 200
+ Attributes
+ angle: `100.0`
+ Response 400
+ Attributes (BadRequestError)
+ friendly: `Invalid angle supplied.`
## Distance [/robot/{robotid}/distance]
Exposes a mechanism to issue moving distances to the robot.
### Retrieve distance [GET]
+ Parameters
+ robotid: `0` (number, required) - ID of the robot
+ Response 200
+ Attributes
+ distance: `40.0`
### Issue a distance [POST]
+ Parameters
+ robotid: `0` (number, required) - ID of the robot
+ Request
+ Attributes
+ distance: `40.0`
+ Response 200
+ Attributes
+ distance: `40.0`
+ Response 400
+ Attributes (BadRequestError)
+ friendly: `Invalid distance supplied.`
## Motor [/robot/{robotid}/motor]
Exposes a mechanism to turn the robot on and off.
### Retrieve motor state [GET]
+ Parameters
+ robotid: `0` (number, required) - ID of the robot
+ Response 200
+ Attributes
+ motor: false
### Issue a new motor state [POST]
+ Parameters
+ robotid: `0` (number, required) - ID of the robot
+ Request
+ Attributes
+ motor: true
+ Response 200
+ Attributes
+ motor: true
+ Response 400
+ Attributes (BadRequestError)
+ friendly: `Invalid motor state supplied.`
## Locking [/robot/{robotid}/lock]
Exposes the state of the locking mechanism, for reading or modification.
### Gets lock state [GET]
+ Parameters
+ robotid: `0` (number, required) - ID of the robot
+ Response 200
+ Attributes
+ lock: `false` - Boolean value indicating whether the lock is engaged.
### Updates the lock state [POST]
+ Parameters
+ robotid: `0` (number, required) - ID of the robot
+ Request
+ Attributes
+ lock: `false` - Boolean value indicating whether the lock is engaged.
+ Response 200
+ Attributes
+ lock: `false` - Boolean value indicating whether the lock is engaged.
## Verify [/robot/{robotid}/verify]
This resource exposes the QR verification challenge route.
### Send challenge [POST]
This route sends the token read from the QR code alongside a bearer token in the authorization
header.
+ Parameters
+ robotid: `0` (number, required) - ID of the robot
+ Request with challenge token
+ Headers
Authorization: Bearer 8aHjr65ULEZItDm7eEeoHwO55CDnbgdJ
+ Attributes
+ token: `4qMNg0gToH`
+ Response 200
+ Response 400
+ Attributes (BadRequestError)
+ friendly: `Invalid delivery state`
+ Response 403
+ Attributes(ForbiddenError)
+ friendly: `Challenge failed. Check your bearer and challenge tokens`