-
Notifications
You must be signed in to change notification settings - Fork 0
/
apiary.apib
534 lines (374 loc) · 13 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
FORMAT: 1A
# Payback API
Payback API is a service to track and optimize debts between a group of friends.
## Authentication
Currently the Payback API does not provide authenticated access.
Authentication will be implemented using OAuth, with logins by username and password, Facebook, Google and other services.
## Digital Signature
To prevent tampering of the data, a digital signature is included as a header in every request.
The header name is X-Checksum and it is calculated using HMAC-SHA1 of the JSON representation of an object
including url, query parameters and request body.
## Media Types
Where applicable this API uses the JSON media-type to represent resources states and affordances.
Requests with a message-body are using plain JSON to set or update resource states.
## Error States
The common [HTTP Response Status Codes](https://github.com/for-GET/know-your-http-well/blob/master/status-codes.md) are used.
# Payback API Root [/]
Payback API entry point.
This resource does not have any attributes.
## Retrieve the Entry Point [GET]
+ Response 204
# Group User
Users related resources of the **Payback API**
## User [/users/{id}]
A single User object. The User resource is the central resource in the Payback API. It represents one user of the service.
The User resource has the following attributes:
- id -- Username of the User
- email -- Email of the User
+ Parameters
+ id (string, required, `john`) ... ID of the User
+ Model (application/json)
```js
{
"id": "johndoe",
"email": "[email protected]"
}
```
### Retrieve a single User [GET]
This method is only available for the authenticated user.
+ Response 200 (application/json)
[User][]
+ Response 403 (application/json)
{ "error": "No permission" }
or
{ "error": "Invalid checksum" }
+ Response 404 (application/json)
{ "error": "User 'johndoe' does not exist." }
### Update a single User [PATCH]
This method is only available for the authenticated user.
*email* is the only modifiable field.
+ Request (application/json)
{
"email": "[email protected]"
}
+ Response 200 (application/json)
[User][]
+ Response 403 (application/json)
{ "error": "No permission" }
or
{ "error": "Cannot update field 'whatever'" }
or
{ "error": "Invalid checksum" }
or
{ "error": "Email '[email protected]' already exists." }
+ Response 404 (application/json)
{ "error": "User 'johndoe' does not exist." }
### Delete a User [DELETE]
This method is only available for the authenticated user.
+ Response 204
+ Response 403 (application/json)
{ "error": "No permission" }
or
{ "error": "Invalid checksum" }
+ Response 404 (application/json)
{ "error": "User 'johndoe' does not exist." }
## Debt [/users/{id}/debts/{debtId}{?currency}]
A single Debt object. The Debt resource represents a debt that a User has on another User.
A positive *value* means that this User owes something to another User, a negative *value* means that this User is owed by another User.
The Debt resource has the following attributes:
- debtId -- Id of a Debt of a User (read-only)
- creditor -- User that credits the debt (read-only)
- debtor -- User that owes the creditor (read-only)
- originalValue -- Money that we owe or are owed by the User above (read-only)
- value -- Money that we owe or are owed by the User above
- currency -- Money currency of the value (read-only)
- created -- Date (ISO 8601) the Debt was created (read-only)
- modified -- Date (ISO 8601) the Debt was last modified (read-only, not const)
+ Parameters
+ id (string, required, `john`) ... ID of the User
+ debtId (number, required, `1`) ... ID of the Debt of a User
+ Model (application/json)
```js
{
"debtId": 1,
"creditor": "john",
"debtor": "janeroe",
"originalValue": 100,
"value": 0,
"currency": "EUR",
"created": "2014-04-14T11:29Z",
"modified": "2014-04-15T09:10Z"
}
```
### Retrieve a single Debt [GET]
This method is only available for the authenticated user.
+ Parameters
+ currency (string, optional, `EUR`) ... Currency
+ Response 200 (application/json)
[Debt][]
+ Response 403 (application/json)
{ "error": "No permission" }
or
{ "error": "Invalid checksum" }
+ Response 404 (application/json)
{ "error": "Debt '2' for user 'johndoe' does not exist." }
### Update a single Debt [PATCH]
This method is only available for the authenticated user.
The only modifiable field is *value*.
+ Request (application/json)
{
"value": 0,
"currency": "EUR"
}
+ Response 200 (application/json)
[Debt][]
+ Response 403 (application/json)
{ "error": "No permission" }
or
{ "error": "Cannot update field 'whatever'" }
or
{ "error": "Invalid checksum" }
+ Response 404 (application/json)
{ "error": "Debt '2' for user 'johndoe' does not exist." }
### Delete a Debt [DELETE]
This method is only available for the authenticated user.
+ Response 204
+ Response 403 (application/json)
{ "error": "No permission" }
or
{ "error": "Invalid checksum" }
+ Response 404 (application/json)
{ "error": "Debt '2' for user 'johndoe' does not exist." }
## Debts Collection [/users/{id}/debts{?currency}]
Collection of all Debts that another User owes this User.
The Debts Collection resource has the following attribute:
- total -- Total number of Debts
- balance -- Total balance between owed money
- credit -- Money owed to this User
- debit -- Money that this User owes to the other Users
- currency -- Currency of *balance*, *debit* and *credit*
- debts -- Array of Debts
+ Parameters
+ id (string, required, `john`) ... ID of the User
+ Model (application/json)
```js
{
"total": 2,
"balance": -3.4,
"credit": 0,
"debit": 3.4,
"currency": "EUR",
"debts":
[
{
"debtId": 1,
"creditor": "john",
"debtor": "janeroe",
"originalValue": 100,
"value": 0,
"currency": "EUR",
"created": "2014-04-14T11:29Z",
"modified": "2014-04-15T09:10Z"
},
{
"debtId": 2,
"creditor": "smith",
"debtor": "john",
"user": "smith",
"originalValue": 5.4,
"value": 3.4,
"currency": "EUR",
"created": "2014-04-16T08:30Z",
"modified": "2014-04-17T10:30Z"
}
]
}
```
### List all Debts of a User [GET]
This method is only available for the authenticated user.
+ Parameters
+ currency (string, optional, `EUR`) ... Currency
+ Response 200 (application/json)
[Debts Collection][]
+ Response 403 (application/json)
{ "error": "No permission" }
or
{ "error": "Invalid checksum" }
### Create a new Debt [POST]
This method is only available for the authenticated user.
+ Request (application/json)
{
"user": "johndoe",
"value": 100,
"currency": "EUR"
}
+ Response 201 (application/json)
{
"created": [
{
"debtId": 2,
"creditor": "smith",
"debtor": "john",
"user": "smith",
"originalValue": 5.4,
"value": 3.4,
"currency": "EUR",
"created": "2014-04-16T08:30Z",
"modified": "2014-04-17T10:30Z"
}
],
"updated": [
{
"debtId": 1,
"creditor": "john",
"debtor": "janeroe",
"originalValue": 100,
"value": 0,
"currency": "EUR",
"created": "2014-04-14T11:29Z",
"modified": "2014-04-15T09:10Z"
}
]
}
+ Response 403 (application/json)
{ "error": "No permission" }
or
{ "error": "Invalid checksum" }
+ Response 404 (application/json)
{ "error": "User 'johndoe' does not exist." }
or
{ "error": "Value '0.0001' is invalid." }
## Friend [/users/{id}/friends/{friendId}]
A single Friend object. The Friend resource represents a friend of a User.
The Friend resource has the following attributes:
- id -- Username of a Friend
+ Parameters
+ id (string, required, `john`) ... ID of the User
+ friendId (string, required, `jane`) ... ID of a Friend of a User
+ Model (application/json)
```js
{
"id": "johndoe"
}
```
### Retrieve a single Friend [GET]
This method is only available for the authenticated user.
+ Response 200 (application/json)
[Friend][]
+ Response 403 (application/json)
{ "error": "No permission" }
or
{ "error": "Invalid checksum" }
+ Response 404 (application/json)
{ "error": "User 'johndoe' does not exist or is not a friend." }
### Delete a single Friend [DELETE]
This method is only available for the authenticated user.
+ Response 204
+ Response 403 (application/json)
{ "error": "No permission" }
or
{ "error": "Invalid checksum" }
+ Response 404 (application/json)
{ "error": "User 'johndoe' does not exist or is not a friend." }
## Friends Collection [/users/{id}/friends]
Collection of all Users that are Friends of a User.
This is a one-way only friendship and it is used to provide quick access to Users that are commonly used in the transactions.
The Friends Collection resource has the following attributes:
- total -- Total number of Friends
- friends -- Array of Friends (not detailed)
+ Parameters
+ id (string, required, `john`) ... ID of the User
+ Model (application/json)
```js
{
"total": 2,
"friends":
[
{ "id": "janeroe" },
{ "id": "smith" }
]
}
```
### List all Friends of a User [GET]
This method is only available for the authenticated user.
+ Response 200 (application/json)
[Friends Collection][]
+ Response 403 (application/json)
{ "error": "No permission" }
or
{ "error": "Invalid checksum" }
### Create a Friend of a User [POST]
This method is only available for the authenticated user.
+ Request (application/json)
{ "id": "johndoe" }
+ Response 201 (application/json)
{ "id": "johndoe" }
+ Response 403 (application/json)
{ "error": "User 'johndoe' already friended." }
or
{ "error": "No permission" }
or
{ "error": "Invalid checksum" }
+ Response 404 (application/json)
{ "error": "User 'johndoe' does not exist." }
### Delete all Friends of a User [DELETE]
This method is only available for the authenticated user.
+ Response 204
+ Response 403 (application/json)
{ "error": "No permission" }
or
{ "error": "Invalid checksum" }
## Users Collection [/users{?search}]
Collection of all Users.
The User Collection resource has the following attributes:
- total -- Total number of Users
- Users -- Array of Users (not detailed)
### List all Users [GET]
+ Parameters
+ search (string, optional, `jo`) ... Fuzzy search. Only users that have an *id* or *email* related to the *search* parameter are returned.
+ Response 200 (application/json)
{
"total": 2,
"users":
[
{ "id": "johndoe" },
{ "id": "janeroe" }
]
}
+ Response 403 (application/json)
{ "error": "No permission" }
or
{ "error": "Invalid checksum" }
### Create a User [POST]
+ Parameters
+ search (string, optional, `jo`) ... Fuzzy search. Only users that have an *id* or *email* related to the *search* parameter are returned.
+ Request (application/json)
{ "id": "john", "email": "[email protected]", "passwordHash": "abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd" }
+ Response 201 (application/json)
{ "id": "john", "email": "[email protected]" }
+ Response 403 (application/json)
{ "error": "User 'john' already exists." }
or
{ "error": "Email '[email protected]' already exists." }
or
{ "error": "Invalid checksum" }
## Exchange Rates Collection [/exchangeRates]
Collection of all exchange rates.
The Exchange Rates resource has the following attributes:
- base -- Currency used as base for the rates
- rates -- Exchange rates
+ Model (application/json)
```js
{
"base": "EUR",
"rates": {
"AUD": 1.4684,
"BGN": 1.9558,
"BRL": 3.0485,
"CAD": 1.4976,
"CHF": 1.2211
}
}
### List all Exchange Rates [GET]
+ Response 200 (application/json)
[Exchange Rates Collection][]