forked from martincarrera/clash-royale-api-data-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·39 lines (37 loc) · 1.12 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
require('dotenv').load();
const request = require('request');
const arenas = require('./data/arenas.json');
const cards = require('./data/cards.json');
const players = require('./data/players.json');
const chests = require('./data/chests.json');
const leagues = require('./data/leagues.json');
const user = { username: process.env.ADMIN_USERNAME || 'admin', password: process.env.ADMIN_PASSWORD || 'admin' };
const uri = 'http://localhost:8085/';
request.post({
url: uri + 'api/authenticate',
headers: {
'Accept': 'application/json'
},
form: user
}, (err, httpResponse, body) => {
const token = body;
// save(token, 'api/cards', cards);
// save(token, 'api/chests', chests);
// save(token, 'api/players', players);
// save(token, 'api/leagues', leagues);
save(token, 'api/arenas', arenas);
});
const save = (token, endpoint, objects) => {
objects.forEach((o) => {
request.post({
url: uri + endpoint,
headers: {
'Authorization': token,
'Accept': 'application/json'
},
form: o
}, (err, httpResponse, body) => {
console.log(o);
});
});
}