-
Notifications
You must be signed in to change notification settings - Fork 160
/
getCards.js
33 lines (29 loc) · 1.21 KB
/
getCards.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
'use strict';
const fetch = require("node-fetch");
async function getCards() {
return await fetch("https://api2.splinterlands.com/cards/get_details?v=1582322601277", {"credentials":"omit","headers":{"accept":"application/json, text/javascript, */*; q=0.01","accept-language":"en-GB,en-US;q=0.9,en;q=0.8"},"referrer":"https://splinterlands.com/?p=collection&a=a1492dc","referrerPolicy":"no-referrer-when-downgrade","body":null,"method":"GET","mode":"cors"})
.then((response) => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response;
})
.then((cards) => {
return cards.json();
})
.catch((error) => {
console.error('There has been a problem with your fetch operation:', error);
});
}
const cardByIds = (ids = []) => {
return getCards()
.then(inventory => inventory.filter(card => ids.includes(card.id))
).then(x=> x.map((y) => ({
'id': y.id,
'name': y.name,
'color': y.color})
)).then(x=> console.log(x));
}
//example get card id [1,145,167]
//cards([1,145,167]);
exports.cardByIds = cardByIds;