-
Notifications
You must be signed in to change notification settings - Fork 1
/
abcd.js
123 lines (102 loc) · 3.74 KB
/
abcd.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
var axios = require("axios").default;
const { response } = require("express");
var index=require('./playerIndex');
var searchByPlayerName=function(searchTerm){
return new Promise((resolve,rejects)=>{
playerId=index.filter((player)=>{
return player.playerName.toLowerCase().includes(searchTerm.toLowerCase());
})[0].playerId;
getPlayerData(playerId,false).then((res)=>{
return resolve(res)
})
})
}
var searchByPlayerName_Bat = function (searchTerm) {
return new Promise((resolve, rejects) => {
playerId = index.filter((player) => {
return player.playerName.toLowerCase().includes(searchTerm.toLowerCase());
})[0].playerId;
getPlayerBatData(playerId, false).then((res) => {
return resolve(res)
})
})
}
var searchByPlayerName_Bowl = function (searchTerm) {
return new Promise((resolve, rejects) => {
playerId = index.filter((player) => {
return player.playerName.toLowerCase().includes(searchTerm.toLowerCase());
})[0].playerId;
getPlayerBowlData(playerId, false).then((res) => {
return resolve(res)
})
})
}
var getPlayerData=function(playerId,summary){
return new Promise((resolve,rejects)=>{
var options = {
method: 'GET',
url: 'https://unofficial-cricbuzz.p.rapidapi.com/players/get-info',
params: { playerId: playerId },
headers: {
'x-rapidapi-host': 'unofficial-cricbuzz.p.rapidapi.com',
'x-rapidapi-key': 'c6b2545514mshff7bd320e6e0561p17836ejsnbb4c7d2cd7e4'
}
};
axios.request(options).then(function (response) {
// console.log(response.data);
var playerData=response.data;
return resolve(playerData);
}).catch(function (error) {
console.error(error);
});
})
}
var getPlayerBatData = function (playerId, summary) {
return new Promise((resolve, rejects) => {
var axios = require("axios").default;
var options = {
method: 'GET',
url: 'https://unofficial-cricbuzz.p.rapidapi.com/players/get-batting',
params: { playerId: playerId },
headers: {
'x-rapidapi-host': 'unofficial-cricbuzz.p.rapidapi.com',
'x-rapidapi-key': 'c6b2545514mshff7bd320e6e0561p17836ejsnbb4c7d2cd7e4'
}
};
axios.request(options).then(function (response) {
// console.log(response.data);
var playerData = response.data;
return resolve(playerData);
}).catch(function (error) {
console.error(error);
});
})
}
var getPlayerBowlData = function (playerId, summary) {
return new Promise((resolve, rejects) => {
var axios = require("axios").default;
var axios = require("axios").default;
var options = {
method: 'GET',
url: 'https://unofficial-cricbuzz.p.rapidapi.com/players/get-bowling',
params: { playerId: playerId },
headers: {
'x-rapidapi-host': 'unofficial-cricbuzz.p.rapidapi.com',
'x-rapidapi-key': 'c6b2545514mshff7bd320e6e0561p17836ejsnbb4c7d2cd7e4'
}
};
axios.request(options).then(function (response) {
// console.log(response.data);
var playerData = response.data;
return resolve(playerData);
}).catch(function (error) {
console.error(error);
});
})
}
var abcd = {
getPlayerInfoByName: searchByPlayerName,
getPlayerBatInfoByName: searchByPlayerName_Bat,
getPlayerBowlInfoByName: searchByPlayerName_Bowl,
}
module.exports = abcd;