이재용

api 분리로 가독성 향상, 동기화 사용

1 +var request = require('request');
2 +var search = {};
3 +var apikey="RGAPI-4ccc267c-4dba-46f4-b705-bdb224f15ac2"
4 +//사용자 정보 api
5 +search.getPuuid = function(name){
6 + return new Promise(function(resolve,reject){
7 + request({
8 + url : "https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-name/" + name+"?api_key="+ apikey,
9 + method: 'GET'
10 + },function(err,res,body){
11 +
12 + resolve(JSON.parse(body).puuid);
13 + });
14 + });
15 +};
16 +
17 +//ppuid를 이용한 게임링크 api
18 +search.getGamename = function(puuid){
19 + return new Promise(function(resolve,reject){
20 + request({
21 + uri : "https://asia.api.riotgames.com/tft/match/v1/matches/by-puuid/"+puuid+"/ids?count=20&api_key="+apikey,
22 + method: 'GET'
23 + },function(err,res,body){
24 + // console.log(JSON.parse(body).link);
25 + resolve(JSON.parse(body));
26 + });
27 + });
28 +};
29 +
30 +search.getGametrait = function(game_id){
31 + return new Promise(function(resolve,reject){
32 + request({
33 + url : "https://asia.api.riotgames.com/tft/match/v1/matches/"+game_id+"?api_key="+apikey,
34 + method: 'GET'
35 + },function(err,res,body){
36 + // console.log(JSON.parse(body).link);
37 + resolve(JSON.parse(body).info);
38 + });
39 + });
40 +};
41 +module.exports = search;
...\ No newline at end of file ...\ No newline at end of file