๐ŸŽ‰๋กค ์ „์ ๊ฒ€์ƒ‰ ์‚ฌ์ดํŠธ ๋งŒ๋“ค๊ธฐ(2) - ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ํŽ˜์ด์ง€์— ์ ์šฉ

์ค€์„(์ค€์„์•„)ยท2021๋…„ 10์›” 1์ผ
0
  • โœ” Riot API๋ฅผ ์ธ์ฆ
  • ๐Ÿ“XMLHttpRequest์„ ์ด์šฉํ•ด์„œ Riot API ๋ฐ์ดํ„ฐ ํŒŒ์‹ฑ
  • Express๋ฅผ ์ด์šฉํ•ด์„œ Front์— ๋ฐ์ดํ„ฐ ๋„˜๊ธฐ๊ธฐ
  • ๋‰ด๋ชจํ”ผ์ฆ˜์„ ์ด์šฉํ•˜์—ฌ ์‚ฌ์ดํŠธ ๊พธ๋ฏธ๊ธฐ

์ฑ„ํƒํ•œ ํŒŒ์‹ฑ๋ฐฉ๋ฒ•

์„œ๋ธŒํŒŒํ‹ฐ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์•„์ง ์ˆ™์ง€ํ•œ๊ฒŒ ์—†์–ด์„œ XMLHttpRequest์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ํŒŒ์‹ฑํ•˜๊ธฐ๋กœ ํ•˜์˜€๋‹ค.
๋‚˜์ค‘์— ์‚ฌ์ดํŠธ๋ฅผ ๋‹ค๋“ฌ์„๋•Œ Spring boot๋‚˜ ๋‹ค๋ฅธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ํŒŒ์‹ฑํ•˜๋Š”๊ฑธ ๊ณต๋ถ€ํ•ด๋ณด๋„๋ก ํ•˜์ž.


ํŒŒ์‹ฑํ•  ๋ฐ์ดํ„ฐ ์ •ํ•˜๊ธฐ

Riot Developer์‚ฌ์ดํŠธ์—์„œ ๊ฐ€์ ธ์˜ฌ ๋งŒํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ์ถ”๋ ค๋‚ด ๋ณด์ž.

SUMMONER-V4 ์†Œํ™˜์‚ฌ์ •๋ณด

  • /lol/summoner/v4/summoners/by-name/{summonerName}

LEAGUE-V4 ๋ฆฌ๊ทธ ์ •๋ณด

  • /lol/league/v4/entries/by-summoner/{encryptedSummonerId}

Match-V4 ์†Œํ™˜์‚ฌ ์ „์ ๋ฆฌ์ŠคํŠธ

  • /lol/match/v5/matches/by-puuid/{puuid}/ids
  • /lol/match/v5/matches/{matchId}

CHAMPION-V3 ์ฑ”ํ”ผ์˜จ ์ •๋ณด

  • /lol/platform/v3/champion-rotations

RIOT APIํ‚ค๋ฅผ ๋ฐ›์•˜๋‹ค๋ฉด ๊ฐœ๋ฐœ์ž์‚ฌ์ดํŠธ์—์„œ ๋ฐ์ดํ„ฐ๊ฐ€ ์–ด๋–ป๊ฒŒ ๋‚ ์•„์˜ค๋Š”์ง€ ๋ฏธ๋ฆฌ ํ…Œ์ŠคํŠธํ•ด ๋ณผ ์ˆ˜ ์žˆ๋‹ค

๋ฐ์ดํ„ฐ ํŒŒ์‹ฑ

function httpGet(theUrl)
{
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
    xmlHttp.send( null );
    return JSON.parse(xmlHttp.responseText);
}

์š”์ฒญํ•œ ๋ฐ์ดํ„ฐ๋ฅผ JSON๋ฐ์ดํ„ฐ๋กœ ํŒŒ์‹ฑํ•˜๋Š” ํ•จ์ˆ˜์ด๋‹ค. ๊ฐ„๋‹จํ•˜๊ฒŒ JSON๊ฐ์ฒด ํ˜•ํƒœ๋กœ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์—ˆ๋‹ค.
์•„๋ž˜ ์‚ฌ์ง„์€ ํŒŒ์‹ฑํ•œ JSON๋ฐ์ดํ„ฐ์ด๋‹ค.

์œ„์™€ ๊ฐ™์ด ๊ธ์–ด์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ๋‚ด๊ฐ€ ๋งŒ๋“  ๋ชจ๋“ˆ์— ํŒŒ๋žŒ์œผ๋กœ ๋„˜๊ฒจ์ฃผ๊ธฐ๋กœ ํ•˜์˜€๋‹ค.

search_summoner.js File

const template = require('./lib/template.js');
...
html = template.HTML(
                        results
                        ,list
                    )
res.send(html);

template.js


module.exports = {
    HTML:function (SummonerObject,list) {
        let queType ="UnRanked";
        let soloInfo ='';
        let soloImg;
        let queTypeTeam ="UnRanked";
        let teamInfo ='UnRanked';
        let teamIMG;
        
        if(SummonerObject[0].tier1==undefined){
            console.log('์‹คํ–‰?');
            soloImg='undefined'
        }else{
            queType ="์†”๋กœ๋žญํฌ";

            soloInfo = SummonerObject[0].tier1 + '&nbsp' + SummonerObject[0].rank1 + '&nbsp' + SummonerObject[0].leaguePoints1 + '<br>' +
            SummonerObject[0].wins1+'์Šน' +SummonerObject[0].losses1+'ํŒจ';

            soloImg = SummonerObject[0].tier1;
        }

        if(SummonerObject[0].tier2==undefined){
            teamIMG='undefined';
        }else{
            queTypeTeam ="ํŒ€ ๋žญํฌ";

            teamInfo = SummonerObject[0].tier2 +'&nbsp '+SummonerObject[0].rank2 +' &nbsp'+SummonerObject[0].leaguePoints2+'<br>'+
            SummonerObject[0].wins2+'์Šน' +SummonerObject[0].losses2+'ํŒจ';

            teamIMG = SummonerObject[0].tier2;
        }
        return`
        <html lang="en">
        <head>
            <meta charset="UTF-8">
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <link href="what.css" rel="stylesheet">
            <title>Document</title>
        </head>
        <script src="../search_summoner.js"></script>
            <body>
           
                <header>
                    <div class="profile">
                        <div id="profile_left">
                            <span class="face">
                                <img src="profileicon/${SummonerObject[0].profileIconId}.png" alt="">
                            </span>
                            <span class="profile_left">
                                <div>
                                    <span class="name">${SummonerObject[0].summonerName}</span>
                                </div>
                                <div>
                                    <form action="http://localhost:3000/search" id="form_style" method="get">
                                        <div class="search_form">
                                            <input type="text" id="search_summoner" placeholder="์†Œํ™˜์‚ฌ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜์„ธ์š”" name="id">
                                            <Button type="submit" id="btn_search">๊ฒ€์ƒ‰</Button>
                                        </div>
                                    </form>
                                </div>
                                <div>
                                    <button id="reload">์ „์ ๊ฐฑ์‹ </button>
                                </div>
                            </span>
                        </div>
                        <div id="logo">
                            <img src="logo.png" alt="">
                        </div>
                    </div>
                    <div class="ranks">
                        <span class="rank">
                            <span class="tier">
                                <div>${queType}</div>
                                <img style='width:10vh' src="ranked-emblems/${soloImg}.png" alt="">
                            </span>
                            <span> 
                                ${soloInfo}
                            </span>              
                        </span>
                        <span class="rank">
                            <span class="tier">
                                <div>${queTypeTeam}</div>
                                <img src="ranked-emblems/${teamIMG}.png" alt="">
                            </span>
                            <span> 
                                ${teamInfo}
                            </span>              
                        </span>                   
                    </div>                                                                                                            
                </header>
                ${list}
            </body>
      
        </html> 
        `;
    }

์ •์ƒ์ ์œผ๋กœ ๋ฐ์ดํ„ฐ๊ฐ€ ์ „๋‹ฌ๋œ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

profile
๋‰ด๋น„๊ฐœ๋ฐœ์ž

0๊ฐœ์˜ ๋Œ“๊ธ€