-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollections.js
55 lines (44 loc) · 1.3 KB
/
collections.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
const fs = require('fs');
const axios = require('axios').default;
const dotenv = require('dotenv');
dotenv.config();
let endpoint = "https://api.thinkific.com/api/public/v1/";
let key = process.env.API_KEY;
let subdomain = process.env.API_DOMAIN;
let headers = {
'X-Auth-API-Key': key,
'X-Auth-Subdomain': subdomain,
'Content-Type': 'application/json'
};
var courses = [];
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
console.log("Getting Collections");
axios({
method: 'get',
url: endpoint+"collections?limit=250",
headers: headers
})
.then(function (c_response) {
var items = c_response.data.items;
items.forEach(item => {
fs.writeFileSync(process.env.DIST+'collections/'+item.id+'.json', JSON.stringify(item));
courses.push(item);
});
})
.catch(function (error) {
// handle error
console.log(error);
})
.then(function () {
fs.writeFileSync(process.env.DIST+'collections.json', JSON.stringify(courses));
console.log("done");
});
// let rawdata = fs.readFileSync('people.json');
// let people = JSON.parse(rawdata);
// people.people.push({
// 'firstname': 'Steve',
// 'lastname': 'Jobs'
// });
// fs.writeFileSync('people.json', JSON.stringify(people));