-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode-wars-api.js
More file actions
35 lines (29 loc) · 916 Bytes
/
code-wars-api.js
File metadata and controls
35 lines (29 loc) · 916 Bytes
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
require('dotenv').config();
const { argv } = require('yargs')
const fetch = require('node-fetch');
const apiKey = process.env.CODE_WARS_API_KEY;
if (!apiKey || apiKey === '') {
console.error('API KEY required!');
return;
}
if (!argv.id) {
console.error('Code Kata ID required!');
console.info('npm run cw -- --id=<id>');
return;
}
const codeWarsUrl = `https://www.codewars.com/api/v1/code-challenges/${argv.id}?access_key=${apiKey}`;
fetch(codeWarsUrl)
.then(res => res.json())
.then(codeWarsData => {
if (argv.full) {
console.log(codeWarsData);
} else {
console.info('To see full informations provide the --full argument')
console.log({
id: codeWarsData.id,
slug: codeWarsData.slug,
url: codeWarsData.url
});
}
})
.catch(error => console.error(error));