-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapiary.apib
730 lines (523 loc) · 22.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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
FORMAT: 1A
HOST: http://dynamisapp.herokuapp.com/
# Dynamis Backend API
This is a Dynamis API description.
## Login [/api/v1/login]
Log in user and get **sessionid** Cookie.
### Login [POST /api/v1/login]
+ Request (application/json)
{
"email": "sample@email.com",
"password": "123456"
}
+ Response 200
+ Headers
Cookies: sessionid
+ Body
{
// current user account ID
"accountid": "123456"
}
## Logout [/api/v1/logout]
Log the user out
### Logout [POST /api/v1/logout]
+ Request
+ Body
{
}
+ Response 200
## Accounts [/api/v1/accounts/{accountid}]
### Create new Account [POST /api/v1/accounts]
Create new account by calling this method. As a side-effect will send user a verification e-mail.
+ Request (application/json)
{
"email": "sample@email.com",
"password1": "123456",
"password2": "123456",
// the field is optional
"linkedin_account": "http://me.linkedin.com",
// the field is optional
"keybase_username": "someusername",
// the field is optional
"eth_address": "0xCf14744B3B4Ac720026569249CA4eb19Fc86A708"
}
+ Response 200
### Get all Accounts [GET /api/v1/accounts]
Get list of all account IDs.
+ Response 200
+ Body
{
"results":
[
"231313231",
"231421843",
"894898989"
]
}
### Update Account [PUT /api/v1/accounts/{accountid}]
Change account parameters (email, keybase_username)
If **admin** - can update any account info.
If **not admin** - can update only my account info.
+ Parameters
+ accountid (number) - ID of an account
+ Response 200 (application/json)
+ Body
{
"email": "xxx@mail.com",
"keybase_username": "something",
"linkedin_account": "http://me.linkedin.com",
// only if admin is asking:
"email_verified": true,
"active": true,
"superuser": true,
"staff": true,
"risk_assessor": true,
// these can't be set
// "date_joined": "",
// "last_login": ""
}
### Get Account [GET /api/v1/accounts/{accountid}]
Get account data.
If **admin** - can get any account info.
If **not admin** - can get only my account info.
+ Parameters
+ accountid (number) - ID of an account
+ Response 200 (application/json)
+ Body
{
"email": "xxx@mail.com",
"keybase_username": "something",
"eth_address": "0xCf14744B3B4Ac720026569249CA4eb19Fc86A708",
"linkedin_account": "http://me.linkedin.com",
"is_keybase_verified": true,
"eth_balance": 10,
"policies": [
1,
3,
5
},
// only if admin is asking:
"email_verified": true,
"keybase_username": "",
"active": true,
"superuser": true,
"staff": true,
"risk_assessor": true,
"date_joined": "",
"last_login": ""
}
### Update Settings [PUT /api/v1/accounts/{accountid}/settings]
The settings is some params that user has set. For example: view color or list sort type.
If **admin** - can update any account settings.
If **not admin** - can update only my account settings.
+ Parameters
+ accountid (number) - ID of an account
+ Request (application/json)
{
"eth_node_host": "http://52.16.72.86:8545",
}
+ Response 200
### Get Settings [GET /api/v1/accounts/{accountid}/settings]
The settings is some params that user has set. For example: view color or list sort type.
If **admin** - can get any account settings.
If **not admin** - can get only my account settings.
+ Parameters
+ accountid (number) - ID of an account
+ Response 200
{
"eth_node_host": "http://52.16.72.86:8545"
}
### Verify Keybase [PUT /api/v1/accounts/{accountid}/keybase]
Validate the user's keybase account. signed_message must be signed by user. We will check that it is signed with account's keybase key.
That is to make sure that valid keybase account is connected with current Dynamis user.
If signature is bad - return 404.
+ Parameters
+ accountid (number) - ID of an account
+ Request (application/json)
{
"signed_message": "123123123123cxxfsq24390dXFasdfj234",
"keybase_username": "tonykent"
}
+ Response 200
+ Response 400
### Get wallet info [GET /api/v1/accounts/{accountid}/wallet]
Each user has his own wallet. We don't have control of the ETH wallet/account, because it is on the frontend side (ETH-Lightwallet).
Please see this [Wiki for more information on tokens](https://github.com/dynamisdao/dynamisapp/wiki/RiskAssessment-tokens-(DYNA))
+ Response 200
+ Body
{
"immature_tokens_balance": 0,
"mature_tokens_balance: 0,
}
### Get ImmatureTokens info [GET /api/v1/accounts/{accountid}/immature_tokens/info]
If user has **Risk Assessor** role set - he can buy some immature tokens.
Please see this [Wiki for more information on tokens](https://github.com/dynamisdao/dynamisapp/wiki/RiskAssessment-tokens-(DYNA))
+ Response 200 (application/json)
+ Body
{
// where to send ETH in order to buy immature tokens
"address_to_send": "0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8",
// 0.5 ETH per 1 immature token
"immature_token_cost": 0.5,
// 0 - initial
// 1 - waiting
// 2 - received
"status": 0
}
### Send ETH to buy Immature Tokens [POST /api/v1/accounts/{accountid}/immature_tokens/buy]
When user clicks on 'Send transaction' or 'Buy' button.
Please see this [Wiki for more information on tokens](https://github.com/dynamisdao/dynamisapp/wiki/RiskAssessment-tokens-(DYNA))
+ Request
+ Body
{
// immature tokens
"count": 5,
"from_address": "0x123"
}
+ Response 200
## Peer Review Tasks [/api/v1/review-tasks]
### Get Items for Peer Review [GET]
Get list of items that need to be reviewed (by me). This is not a **risk assessment tasks** (that is done only by RiskAssessors)!
Before we need to verify user identity and verify employment information. This is done by an ordinary users.
If **admin** - get all tasks for all users.
If **not admin** - get all tasks for current user (me) only.
+ Response 200
+ Body
{
tasks: [
{
// global review task ID
id: 1,
is_finished: true,
// TODO: this field is not implemented yet
// TODO: copy it from method below
"type": "employment-claim"
},
...
]
}
### Get Item for Peer Review [GET /api/v1/review-tasks/{review_task_id}]
Get Peer Review task.
+ Parameters
+ review_task_id (number) - ID of a task
+ Response 200
+ Body
{
"type": "employment-claim",
"files": [],
"startYear": "2012",
"company": "Some Company",
"startMonth": "4",
"currentJob": true,
"endMonth": 7,
"state": "READ_ONLY",
"endYear": 2016,
"notes": "* Job Title:\n* ..."
}
### Submit Peer Review [POST /api/v1/review-tasks/{review_task_id}/verify]
After the Peer has reviewed some parts of an application - i want to be able to set **Verify/Falsify/Can't Tell**.
Please see [screenshot here](https://s4.postimg.org/47engihul/Screen_Shot_2016_08_17_at_19_05_14.png).
Please see [another screenshot here](https://s3.postimg.org/a501ucv83/Screen_Shot_2016_08_17_at_19_07_10.png).
That creates the message ```{"task_hash":"things","result":"no"}``` (for example) that he needs then to sign.
+ Parameters
+ review_task_id (number) - ID of a task
+ Request (application/json)
+ Body
{
"signed_message": "4234234jkfjsdlkfaj"
}
+ Response 200
## Assessment Tasks [/api/v1/assessment_tasks]
### Get List of My Assessment Tasks [GET /api/v1/assessment_tasks]
Assessment Task is a 'task' that is assigned to RiskAssessor. RiskAssessor should review it and make a bet.
RiskAssessor wants to get list of assessments that is assigned to him.
If **admin** - get all tasks for all users.
If **not admin** - get all tasks for current user (me) only.
+ Response 200 (application/json)
{
tasks: [
{
// global assessment ID
id: 1,
// is RiskAssessor finished to review it?
is_finished: true
},
...
]
}
### Get Assessment Tasks Info [GET /api/v1/assessment_tasks/{taskid}]
Get assessment full info.
If **admin** - can get any.
If **not admin** - can get only my assessments.
+ Parameters
+ taskid (number) - Assessment Task ID (global for all users)
+ Response 200 (application/json)
{
// linked with policies (global ID)
policyid: 123,
// is RiskAssessor finished to review it?
is_finished: true
bet1: 1.2,
bet2: 2.2
}
### Update Assessment Task Info [PUT /api/v1/assessment_tasks/{taskid}]
Update assessment task data.
If **admin** - can get any.
If **not admin** - can get only my assessment tasks.
+ Parameters
+ taskid (number) - Assessment Task ID (global for all users)
+ Request (application/json)
{
// is RiskAssessor finished to review it?
is_finished: true
bet1: 1.2,
bet2: 2.2
}
+ Response 200
## Policies [/api/v1/policies/{policyid}]
### Create new Policy [POST /api/v1/policies]
Create empty policy for **userid**.
+ Request
+ Body
{
}
+ Response 200
### Get all Policies list [GET /api/v1/policies]
Get list of all policy IDs.
If **admin** - get all policies for all users.
If **not admin** - get all policies for current user (me) only.
+ Response 200
+ Body
{
"results":
[
"1",
"3",
"4"
]
}
### Get Policy [GET /api/v1/policies/{policyid}]
Get the policy data.
In insurance, the insurance **policy** is a contract (generally a standard form contract) between the insurer and the insured, known as the policyholder, which determines the claims which the insurer is legally required to pay. In exchange for an initial payment, known as the premium, the insurer promises to pay for loss caused by perils covered under the policy language.
Insurance contracts are designed to meet specific needs and thus have many features not found in many other types of contracts. Since insurance policies are standard forms, they feature boilerplate language which is similar across a wide variety of different types of insurance policies.
+ Parameters
+ policyid (number) - ID of a policy (global for all users)
+ Response 200 (application/json)
{
"id": 1,
// TODO: field is still not implemented
"is_signed": true,
// See https://github.com/dynamisdao/dynamisapp/wiki/Policy-State-Diagram
// and https://github.com/dynamisdao/dynamisapp/wiki/Risk-Assessment-(Policy-Review)
//
// POLICY_STATUS_INIT = 1
// POLICY_STATUS_SUBMITTED = 2
// POLICY_STATUS_ON_P2P_REVIEW = 3
// POLICY_STATUS_ON_RISK_ASSESSMENT_REVIEW = 4
// POLICY_STATUS_APPROVED = 5
// POLICY_STATUS_ON_SMART_DEPOSIT_REFUND = 6
// POLICY_STATUS_DELETED = 7
// POLICY_STATUS_ACTIVE = 8
// POLICY_STATUS_WAIT_FOR_PREMIUM = 9
// POLICY_STATUS_ON_COMPLETENESS_CHECK = 10
"state": 1,
"data":
{
"public_key": "-----BEGIN PGP PUBLIC KEY BLOCK-----\nVersion: KEY BLOCK-----",
"signed_message": "-----BEGIN PGP SIGNED MESSAGE-----\nHash: SHA512\n\n{\"identity\":{\"verification_method\":\"keybase\",\"verificati`-----END PGP SIGNATURE-----",
"public_key_identity": {
"username": "tonykent"
},
"public_key_provider": "keybase",
"policy_data": {
"requestedPremiumAmount": "46",
"identity": {
"verification_method": "keybase",
"verification_data": {
"username": "tonykent",
"proofs": [
{
"proof_id": "6bd6da447e3d1b0b4a17c210",
"proof_url": "https://twitter.com/anthonyakentiev/status/763656278963085312",
"presentation_tag": "tweet",
"nametag": "anthonyakentiev",
"human_url": "https://twitter.com/anthonyakentiev/status/763656278963085312",
"state": 1,
"proof_type": "twitter",
"service_url": "https://twitter.com/anthonyakentiev",
"sig_id": "476015a934a9b5878b7572ad49853e77e331c36eec76dd836bb78cd45ff3e8d90f",
"presentation_group": "twitter"
},
{
"proof_id": "e26f23f128e6f92ed7955910",
"proof_url": "https://gist.github.com/49e0adf02231361735edd4937d43dc56",
"presentation_tag": "gist",
"nametag": "anthonyakentiev",
"human_url": "https://gist.github.com/49e0adf02231361735edd4937d43dc56",
"state": 1,
"proof_type": "github",
"service_url": "https://github.com/anthonyakentiev",
"sig_id": "5e82869934b8693128f8f4f3023467a9ba7529fc509ae35b364d297ff9982c0c0f",
"presentation_group": "github"
}
]
}
},
"employmentHistory": {
"jobs": [
{
"files": [],
"startYear": "2012",
"company": "Sample",
"startMonth": "6",
"currentJob": true,
"endMonth": 7,
"state": "READ_ONLY",
"endYear": 2016,
"notes": "* Job Title:\n* Reason for leaving:\nProgrammer."
}
]
},
"questions":{
// "In a perfect world how long do you see yourself staying with your present employer?
// Some things to consider might be going back to school or starting a family."
//
// 0 - Less than 1 year
// 1 - In about 1 year
// 2 - Before the end of next year
// 3 - Maybe before 2 years time
// 4 - More than 2 years
// 5 - I love my job. I will work for my present employer till the day I die. :)
"howLongStay": 1,
// "If and when you finally do need coverage about how long do you suppose you might need
// it for? Some things to consider might be the acquiring of a new skill, moving to a new
// industry, starting a completely new career."
//
// 0 - About 1 to 2 weeks
// 1 - Maybe 3 weeks to 1 month
// 2 - Perhaps 1 to 2 months
// 3 - Possibly 2 to 3 months
// 4 - Potentially 3 to 4 months
// 5 - I will need more than 4 months of coverage.
"unemploymentPeriod": 0
},
"requestedPremiumAmount": 12,
// TODO: still not implemented
"requestedCoverageAmount": 84,
"requestedDuration": 4
}
}
}
### Update Policy [PUT /api/v1/policies/{policyid}]
Update the policy.
+ Request (application/json)
+ Body
{
"data":
{
"identity": {
"verification_method": "keybase",
"verification_data": {}
},
"employmentHistory": {
"jobs": [
{
"startYear": "2015"
"company": "Sample",
"startMonth": "3",
"currentJob": true,
"endMonth": 7,
"endYear": 2016,
"state": "READ_ONLY",
"notes": "* Job Title:\n* ...."
}
]
},
"questions":{
"howLongStay": 1,
"unemploymentPeriod": 0
},
"requestedPremiumAmount": 12,
// TODO: still not implemented
"requestedCoverageAmount": 84,
"requestedDuration": 4
}
}
+ Response 200 (application/json)
+ Body
{
"id": 1,
"data": {
"requestedPremiumAmount": 250,
"identity": {
"verification_method": "keybase",
"verification_data": {}
},
"employmentHistory": {
"jobs": [
{
"files": [],
"startYear": "2015",
"notes": "* Job Title:\n* ....",
"startMonth": "3",
"currentJob": true,
"endMonth": 7,
"state": "READ_ONLY",
"endYear": 2016
}
]
},
"questions":{
"howLongStay": 1,
"unemploymentPeriod": 0
}
}
}
### Sign a Policy [POST /api/v1/policies/{policyid}/signature]
After all data is entered - user can submit a policy application. The peers will then review it.
If signature is bad -> return 404.
+ Request (application/json)
+ Body
{
"keybase_username": "tonykent",
"signed_message": "fjdskajflakjdfkweu2434"
}
+ Response 200
### Upload File to Policy [POST /api/v1/policies/{policyid}/file]
Attach the file to the application. Will uplad it to IPFS.
+ Request (application/json)
+ Body
{
"filename": "file1.png",
"data_url": "data:image/png;base64,iVBORw0KGgoAAAANS...",
"mimetype": "image/png"
}
+ Response 200
### Get SmartDeposit info [GET /api/v1/policies/{policyid}/smart_deposit]
When policy is at least in **POLICY_STATUS_SUBMITTED**, this method will return information about Smart Deposit.
+ Response 200 (application/json)
+ Body
{
"amount_in_dollars": 50,
// converted on the fly
"cost_in_eth": 1.2
"cost_in_dollars": 50,
// see this - http://ether.fund/tool/converter
"cost_in_wei": 1200000000000000000,
// where SmartDeposit should be sent to
"address_to_send": "0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8",
// 0 - initial
// 1 - waiting
// 2 - received
"status": 0
}
### Send SmartDeposit [POST /api/v1/policies/{policyid}/smart_deposit/send]
When user clicks on 'Send transaction' button -> we need to move smart deposit into 'waiting' state and wait for transaction confirmation.
+ Request
+ Body
{
// 1.2 ETH
"amount_in_wei": 1200000000000000000,
"from_address": "0x123"
}
+ Response 200