javilobo8 / pubg-api-redis

Playerunknown's Battlegrounds API Wrapper with Redis caching
MIT License
65 stars 9 forks source link

How send request getMatchHistory #4

Closed dedarh closed 7 years ago

dedarh commented 7 years ago

const games = profile.getMatchHistory({ region: REGION.ALL, // defaults to profile.content.selectedRegion season: SEASON.EA2017pre3, // defaults to profile.content.defaultSeason match: MATCH.SOLO // defaults to SOLO });

Add a library so that you can give information by type (as in the profile SOLO DUO SQUAD)

dedarh commented 7 years ago

for (i = 0; i < games.matchHistory.length; i++) { if (games.matchHistory[i].matchDisplay == 'Solo') { game[i] = games.matchHistory[i]; } }

javilobo8 commented 7 years ago

You can do:

const api = new PubgAPI({apikey: process.env.PUBG_APIKEY});

api.getProfileByNickname('fak3zito')
  .then((profile) => {
    const matchH = profile.getMatchHistory();

    const filteredMatches = matchH.matchHistory.filter((match) => {
      return season === 3;
      // return region === 2;
      // return match === 3;
    });

  });

You can filter each match by every variable, I don't now how that int values are mapped. Anyway, you can submit a pull request and I will review :)

dedarh commented 7 years ago

Unhandled rejection ReferenceError: season is not defined at matchH.matchHistory.filter (D:\1\pubg\pubg\pubg.js:14:14) at Array.filter (native) at api.getProfileByNickname.then (D:\1\pubg\pubg\pubg.js:13:51) at tryCatcher (D:\1\pubg\pubg\node_modules\bluebird\js\release\util.js:16:23 )

javilobo8 commented 7 years ago

Fixed...

const api = new PubgAPI({apikey: process.env.PUBG_APIKEY});

api.getProfileByNickname('fak3zito')
  .then((profile) => {
    const matchH = profile.getMatchHistory();

    const filteredMatches = matchH.matchHistory.filter((match) => {
      return match.season === 3;
      // return match.region === 2;
      // return match.match === 3;
    });

  });
dedarh commented 7 years ago

Thank you, add in constants.js const SEASON = { .......... EA2017pre4: '2017-pre4', };

javilobo8 commented 7 years ago

Already added in 3.4.1 https://github.com/javilobo8/pubg-api-redis/commit/47c2bb6ee207ea1ee00e16a9a78234095f203e77