1
1
const API = "/api" ;
2
- const VIDEO_API = `${ API } /videos` ;
3
2
const CHALLENGE_API = `${ API } /challenges` ;
3
+ const RESPONSE_API = `${ API } /responses` ;
4
4
5
5
class HumanApi {
6
- constructor ( ) {
7
- this . challenges = [
8
- {
9
- challengeId : "45" ,
10
- name : "car_crash" ,
11
- instructions : "How much empathy do you have for bad drivers?" ,
12
- gradingCriteria : "Does the viewer cringe?" ,
13
- link : "https://fat.gfycat.com/PowerlessDiligentAstarte.webm" ,
14
- author : "Brian Basham"
15
- } ,
16
- {
17
- challengeId : "202" ,
18
- name : "big_buck_bunny" ,
19
- instructions : "Smile when you see animals!?" ,
20
- gradingCriteria : "Does the viewer smile when they see animals?" ,
21
- link :
22
- "https://storage.googleapis.com/the-human-factor-videos/19f32a31-5fd8-4ec9-85c4-5dc9216795f6" ,
23
- author : "Leo Urbina"
24
- } ,
25
- {
26
- challengeId : "345" ,
27
- name : "brian_prices" ,
28
- instructions : "Find out what Brian's budget is" ,
29
- gradingCriteria : "How empathetic and curious are you?" ,
30
- link :
31
- "https://storage.googleapis.com/the-human-factor-videos/d8912f88-3726-48e5-b280-fde3bf17d2b4" ,
32
- author : "Brian Basham"
33
- } ,
34
- {
35
- challengeId : "888" ,
36
- name : "alex_cant_trust_tech" ,
37
- instructions : "Find a way forward in the conversation" ,
38
- gradingCriteria : "How empathetic and curious are you?" ,
39
- link :
40
- "https://storage.googleapis.com/the-human-factor-videos/70e70f89-072e-4de1-9357-5214e5d6d6c9" ,
41
- author : "Alex Warren"
42
- }
43
- ] ;
44
-
45
- this . responses = [
46
- {
47
- responseId : "111" ,
48
- challengeId : "345" ,
49
- responder : "Leo Urbina" ,
50
- notes : "I think I did OK." ,
51
- link :
52
- "https://storage.googleapis.com/the-human-factor-videos/cedd88e6-0841-4d2f-8b8e-123bc475f7a7"
53
- } ,
54
- {
55
- responseId : "505" ,
56
- challengeId : "345" ,
57
- responder : "Alex Warren" ,
58
- notes : "That was uncomfortable." ,
59
- link :
60
- "https://storage.googleapis.com/the-human-factor-videos/c1c57ea6-00bd-432f-a71c-09c7685ae70f"
61
- } ,
62
- {
63
- responseId : "999" ,
64
- challengeId : "888" ,
65
- responder : "Brian Basham" ,
66
- notes : "Couldn't stop laughing." ,
67
- link :
68
- "https://storage.googleapis.com/the-human-factor-videos/10ded6f0-5e9f-45a9-88ce-a273cd1bb4ad"
69
- }
70
- ] ;
71
- }
72
-
73
- getResponseIds ( ) {
74
- return this . responses . map ( response => {
75
- return response . responseId ;
76
- } ) ;
77
- }
78
-
79
- getResponse ( responseId ) {
80
- for ( let response of this . responses ) {
81
- if ( response . responseId === responseId ) {
82
- return response ;
83
- }
84
- }
85
- alert ( "no such response" + responseId ) ;
86
- }
87
-
88
- addVideo ( blob , callback ) { }
89
-
90
6
createChallenge ( challenge ) {
91
7
let formData = this . convertToForm ( challenge ) ;
92
8
return fetch ( `${ CHALLENGE_API } /create` , {
@@ -101,6 +17,20 @@ class HumanApi {
101
17
} ) ;
102
18
}
103
19
20
+ createResponse ( response ) {
21
+ let formData = this . convertToForm ( response ) ;
22
+ return fetch ( `${ RESPONSE_API } /create` , {
23
+ method : "POST" ,
24
+ body : formData
25
+ } )
26
+ . then ( res => {
27
+ return res . json ( ) ;
28
+ } )
29
+ . catch ( error => {
30
+ console . error ( "Failed to createResponse:" , error ) ;
31
+ } ) ;
32
+ }
33
+
104
34
convertToForm ( obj ) {
105
35
var formData = new FormData ( ) ;
106
36
for ( const [ key , val ] of Object . entries ( obj ) ) {
@@ -116,6 +46,14 @@ class HumanApi {
116
46
console . error ( "Failed to fetch challenges" ) ;
117
47
} ) ;
118
48
}
49
+
50
+ fetchResponses ( ) {
51
+ return fetch ( `${ RESPONSE_API } ` )
52
+ . then ( res => res . json ( ) )
53
+ . catch ( error => {
54
+ console . error ( "Failed to fetch challenges" ) ;
55
+ } ) ;
56
+ }
119
57
}
120
58
121
59
export default new HumanApi ( ) ;
0 commit comments