Contributing - Wobow/pubg_api GitHub Wiki

Contributing

This page describes guidelines and informations needed to contribute to the wrapper

Setting up the dev environment

Start by cloning the repo

git clone https://github.com/Wobow/pubg_api

Install the dependencies

cd pubg_api

npm install

You need npm and node (> v7.6) installed on your device

You can now start working on the wrapper.

Testing & building

To test : npm test

To run the lint : npm run lint

To build: npm run build

You have to annotate every function you write

Writing code

Simple API call

In the index.js file, write your function with the following prototype:

/**
*  This text describes my function to the user.
*
*  Preferably, I then put a link to the official documentation of the API
*  
*  @param {type} param1 - Describes the first param
*  @param {type} param2 - Describe the second param
*  ...
*  @param {string} shard - The shard id. If not specifed, calls the default shard.
*  @returns A Promise or Observable with the result or an error
*/
this.myFunction = (param1, param2, ..., shard = this.defaultShard) => {
  // Write any code you want
  return this.wrapAsync(this.requestAPI(shard, route, params));
}

You can chain the api request if you want to, but your function must always return an instance of this.wrapAsync. This function wraps any promise into the proper async type the user specified in the config (either Promise or Observable). This is to ensure the consistency of the calls thoughout the api.

The this.requestAPI calls the pubg api given a shard with the proper headers and the Bearer token for the authentication.

** If your function does more than 1 call to the api, you have to put a warning in the description** : this is to warn any user who may have an API key with a restricted number of calls per minute.

API call w/ filters

If you have to call an endpoint that takes filters (e.g. /players?filter[playerNames]=HerrExion,ign2 ), there is a simple way to write them :

  • write the function's prototype as follows in index.js:

const mapParams = require('./mapParams.js');

/**
*  This text describes my function to the user.
*
*  Preferably, I then put a link to the official documentation of the API
*  
*  @param {{filterName1: string, filterName2: number}} params -  An object with one or many of the following params:
*    - filterName1 : an example for a string filter
*    - filterName2 : an example for a number filter
*  @param {string} shard - The shard id. If not specifed, calls the default shard.
*  @returns A Promise or Observable with the result or an error
*/
this.myFunction = (filters, shard = this.defaultShard) => {
  // Write any code you want
  return this.wrapAsync(this.requestAPI(
        shard,
        this.routesURI.players,
        mapParams.map(params, mapParams.maps['myMapId']),
      ));
}

There are two main things to do that you can see in the above code:

  1. In the function's description, the first param must be described as an object, with typed and names keys
*  @param {{filterName1: string, filterName2: number}} params -  An object with one or many of the following params:
  1. The third variable passed to this.requestAPI() should be a call to mapParams.map()
        mapParams.map(params, mapParams.maps['myMapId']),

myMapId is the id of the map in the mapParams.js file. See below

  • Add this to the map filters in mapParams.js so that your param name correspond to the proper filter of the api :
const mapParams = {
  maps: {
    ...,
    myMapId: {
      filterName1: 'filter[customFilter1]',
      filterName2: 'filter[customFilter2]',
    },
  } 
  ...
}

wrapAsync