khulja-sim-sim 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +24 -0
- package/package.json +7 -0
package/index.js
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
// module.exports exports the function getContests as a promise and exposes it as a module.
|
2
|
+
// we can import an exported module by using require().
|
3
|
+
module.exports = async function getContests() {
|
4
|
+
const axios = require("axios"); // Importing the Axios module to make API requests
|
5
|
+
var result;
|
6
|
+
|
7
|
+
const username = "rajadwaita"; // Insert Your Username here
|
8
|
+
const api_key = "0571f18e68668af8bc8021e0af12f6ffb6281431"; //Insert API key here
|
9
|
+
|
10
|
+
await axios // Making a GET request using axios and requesting information from the API
|
11
|
+
.get(
|
12
|
+
"https://clist.by/api/v1/json/contest/?username=" + username + "&api_key=" + api_key + "&limit=20&end__gt=2020-09-19T00%3A00%3A00"
|
13
|
+
)
|
14
|
+
.then((response) => { // If the GET request is successful, this block is executed
|
15
|
+
return response; // The response of the API call is passed on to the next block
|
16
|
+
})
|
17
|
+
.then((contests) => { // In this block, we store the response data into a variable 'result'
|
18
|
+
result = contests.data.objects;
|
19
|
+
})
|
20
|
+
.catch((err) => {
|
21
|
+
console.log(err); // Error handler
|
22
|
+
});
|
23
|
+
return result; // The contest data is returned
|
24
|
+
};
|