-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
134 lines (96 loc) · 2.78 KB
/
api.js
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
/* @flow */
'use strict';
//import request from 'reqwest';
import {VERIFY_TOKEN_URL} from './constants/constants.js';
import {AsyncStorage} from 'react-native';
import { NativeModules } from 'react-native';
import * as schemas from './dataSchemas';
import {buildAssessment} from './BuildAssessment';
//import request from 'reqwest';
import request from "XMLHttpRequest";
export function postJson (URL, data, token=null) {
console.log("POST URL: " + URL);
//console.log(data);
return request({
headers: {
Authorization: "JWT"+ token,
"Content-Type": 'application/json',
},
url: URL,
method: 'POST',
crossOrigin: true,
type: 'json',
data: JSON.stringify(data),
})
};
export function getJson (URL, data, token=null) {
console.log("GET URL: " + URL);
return request({
headers: {
Authorization: "JWT "+ token,
},
url: URL,
method: 'GET',
crossOrigin: true,
type: 'json'
})
};
export function patchJson (URL, data, token=null) {
console.log("PATCH URL: " + URL);
console.log(data);
return request({
headers: {
Authorization: "JWT "+ token,
"Content-Type": 'application/json',
},
url: URL,
method: 'PATCH',
crossOrigin: true,
type: 'json',
data: JSON.stringify(data),
})
};
export function getDataFromDevice(){
console.log("getDataFromDevice");
var CoreInspector = NativeModules.CallCoreInspector;
//console.log(CoreInspector.getAllData().then((data)=>{return buildAssessment(data)}));
return CoreInspector.getAllData().then((data)=>{return buildAssessment(data)})
}
export function getSerialFromDevice () {
console.log("getSerialFromDevice");
var CoreInspector = NativeModules.CallCoreInspector;
return CoreInspector.getSerial()
}
////////////DUMMY
export function getDummySerialFromDevice(){
console.log("getDummySerialFromDevice");
return (
new Promise(function(resolve, reject) {
let response= dummySerialFunc()
if (response.ok == true) {
// Resolve the promise with the response
resolve(response);
}
else {
// Otherwise reject with the status text
// which will hopefully be a meaningful error
reject(Error("error getting serial"));
}
// Handle network errors
response.onerror = function() {
reject(Error("Module Error"));
};
// Make the request
response.send();
}
)
)
}
export function makeidmakeid(x)
{
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for( var i=0; i < x; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}