-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
46 lines (34 loc) · 1.01 KB
/
index.js
File metadata and controls
46 lines (34 loc) · 1.01 KB
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
"use strict"
const EventEmitter = require('events');
const parseProperties = require("./parser-properties")
class ApiAdapter {
constructor(config, middleware) {
this.config = config
this.middleware = middleware
this.emitter = new EventEmitter()
}
compile() {
const { host, path, method, request } = this.config
return new Function("data",
`
const newData ={
method: "${method}",
url: "${[ host, path ].join("")}"
};
return newData;
`)
}
parseRequest(data) {
const { host, path, method = "GET", request } = this.config
const newResp = parseProperties(request, data, data, { middleware: this.middleware })
newResp.method = method
newResp.url = [ host, path ].join("")
return newResp
}
parseResponse(data) {
const { host, path, method = "GET", response } = this.config
const newResp = parseProperties(response, data, data, { middleware: this.middleware })
return newResp
}
}
module.exports = ApiAdapter