LIANG XIAOTONG

api interface all complete

...@@ -9,7 +9,7 @@ module.exports = function (app) { ...@@ -9,7 +9,7 @@ module.exports = function (app) {
9 }); 9 });
10 10
11 app.get('/search/:username/', function (req, res) { 11 app.get('/search/:username/', function (req, res) {
12 - // api url 12 + // tft api url
13 const summonerName = req.params.username; 13 const summonerName = req.params.username;
14 var nameUrl = `https://kr.api.riotgames.com/tft/summoner/v1/summoners/by-name/${summonerName}?api_key=${apikey}` 14 var nameUrl = `https://kr.api.riotgames.com/tft/summoner/v1/summoners/by-name/${summonerName}?api_key=${apikey}`
15 request(nameUrl, function (error, response, body) { 15 request(nameUrl, function (error, response, body) {
...@@ -27,13 +27,42 @@ module.exports = function (app) { ...@@ -27,13 +27,42 @@ module.exports = function (app) {
27 const leagueUrl = `https://kr.api.riotgames.com/tft/league/v1/entries/by-summoner/${summonerId}?api_key=${apikey}`; 27 const leagueUrl = `https://kr.api.riotgames.com/tft/league/v1/entries/by-summoner/${summonerId}?api_key=${apikey}`;
28 request(leagueUrl, function (error, response, body) { 28 request(leagueUrl, function (error, response, body) {
29 const info_league_json = JSON.parse(body); 29 const info_league_json = JSON.parse(body);
30 - console.log('league', body); 30 + const matchIdUrl = `https://asia.api.riotgames.com/tft/match/v1/matches/by-puuid/${info_summoner_json.puuid}/ids?api_key=${apikey}`;
31 - res.render('index', { 31 + request(matchIdUrl, function (error, response, body) {
32 - title: req.params.username, 32 + const matchIdList = JSON.parse(body);
33 - error_message: false, 33 + console.log('matchIds', matchIdList);
34 - c_summoner: summoner, 34 + const promiseList = [];
35 - c_leagueList: info_league_json 35 + if (matchIdList.length > 0) {
36 + matchIdList.forEach(matchId => {
37 + promiseList.push(new Promise((resolve, reject) => {
38 + const matchURL = `https://asia.api.riotgames.com/tft/match/v1/matches/${matchId}?api_key=${apikey}`;
39 + request(matchURL, function (error, response, body) {
40 + const match = JSON.parse(body);
41 + resolve(match);
42 + });
43 + }));
44 + });
45 + Promise.all(promiseList).then(matches => {
46 + console.log('matches', matches);
47 + res.render('index', {
48 + title: req.params.username,
49 + error_message: false,
50 + c_matchList: matches, // 게임 데이터, array
51 + c_summoner: info_summoner_json, // 소환사, object
52 + c_leagueList: info_league_json // leagues 데이터, array
53 + });
54 + })
55 + } else {
56 + res.render('index', {
57 + title: req.params.username,
58 + error_message: false,
59 + c_matchList: [],
60 + c_summoner: info_summoner_json,
61 + c_leagueList: info_league_json
62 + });
63 + }
36 }); 64 });
65 + console.log('league', body);
37 }); 66 });
38 }); 67 });
39 }); 68 });
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
41 <% } else { %> 41 <% } else { %>
42 <font size=10em> 42 <font size=10em>
43 <strong> 43 <strong>
44 - <%= c_summoner + "\n"%> 44 + <%= c_summoner.name + "\n"%> <!-- 소환사 object -->
45 </strong> 45 </strong>
46 </font> 46 </font>
47 <table class="table"> 47 <table class="table">
......