-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (35 loc) · 1.1 KB
/
index.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
import Schematics from 'schematicsjs';
import request from 'request';
let httpMethod = function(settings){
let doRequest = function(resolve, reject){
let method = settings.type || 'get';
request[method]({
url: settings.url,
data: settings.data,
headers: {
'User-Agent': 'schematicsjs'
}
}, function(err, res, body) {
if(err){
reject(err);
} else {
try {
let json = JSON.parse(body);
resolve(json);
} catch(err) {
throw new Error(err);
}
}
});
};
return new Promise(doRequest);
};
new Schematics('http://kvendrik.github.io/schematicsjs/examples/schema.json', httpMethod)
.then(function({ api, body }){
api.users.get({ username: 'kvendrik', limit: 5 })
.then((data) => console.log(data))
.catch((err) => console.log(err));
api.events.post({ name: 'Koen' })
.then((data) => console.log(data))
.catch((err) => console.log(err));
});