-
Notifications
You must be signed in to change notification settings - Fork 1
/
apimok-client.js
48 lines (43 loc) · 938 Bytes
/
apimok-client.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
function ApiMok(port) {
var port = port || 3001;
this.mok = function(params){
if(!params.url){
throw "Endpoint Url not supplied";
}
if(!params.returnValue){
throw "Endpoint return value not supplied";
}
if(!params.verb){
throw "Request method not supplied";
}
if(!jQuery){
throw "jQuery not found";
}
this.requestParams = {
url: params.url,
verb: params.verb,
returnValue: params.returnValue
};
//Make request to Mok server
jQuery.ajax({
url: 'http://localhost:' + port + '/_mok/',
type: 'POST',
async: false,
contentType: 'application/json',
data: JSON.stringify(this.requestParams),
error: function(xhr, status, err){
throw status;
}
});
};
this.destroyAll = function(){
jQuery.ajax({
url: 'http://localhost:' + port + '/_removeAllMoks/',
type: 'POST',
async: false,
error: function(xhr, status, err){
throw status;
}
});
};
}