🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

pactify-api

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pactify-api

A simple API wrapper for Pactify - see https://www.pactify.fr/.

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

pactify-api

A simple API wrapper for Pactify - see https://www.pactify.fr/. It returns data from https://www.pactify.fr/api/player, https://www.pactify.fr/api/faction and https://www.pactify.fr/api/ranking.

Usage

Due to the simplicity of the API, I think there is no need to write a long documentation, theses examples clearly show how to use it. If you want more details, methods and properties are also explained using JSDoc.

Imports

const { Player, Faction, Ranking } = require('pactify-api');

Player

The only guaranteed properties are id, name, registrationDate, lastActivityDate, activityTime, online.

  • Get a player by his name:
    Player.fromName('username').then(player => {
        console.log(player);
    }).catch(error => {
        console.log(error.error);
    });
    
  • Get a player by his ID:
    const player = new Player('id');
    player.fetch().then(() => {
        console.log(player);
    }).catch(error => {
        console.log(error.error);
    });
    

Faction

  • Get a faction by its name:
    Faction.fromName('FAC').then(faction => {
        console.log(faction);
    }).catch(error => {
        console.log(error.error);
    });
    
  • Get a faction by its ID:
    const faction = new Faction('id');
    faction.fetch().then(() => {
        console.log(faction);
    }).catch(error => {
        console.log(error.error);
    });
    

Ranking

  • Get factions ranking for a month:
const ranking = new Ranking('latest');
// you can also specify a YYYY-MM formatted month (e.g. 2020-05) instead of 'latest':
// const ranking = new Ranking('2020-05');
ranking.fetch().then(() => {
    console.log(ranking);
}).catch(error => {
    console.log(error.error);
});

Error codes

Errors returned by the API are objects containing a statusCode and an error property:

statusCodeerror
0no error
1internal error (which surely comes from a connection error from you or the server)
2unknown player
3unknown faction

Partial data

Explanations

When parsing an object, you can have properties containing other data type. For instance, when you parse a Player, if he is in a faction, the faction Player property will result in a Faction object. This object is partial, which means you cannot expect it to have any information beside its ID. You can know whether a data is partial by checking its partial property. The only data you can expect to don't be partial are these fetched with fetch or fromName methods.

Example

This example simply requests a player, then retrieves information from its faction. While the first log will only show the faction ID, the second will display all the property of the faction.

Player.fromName('username').then(async  player => {
    if (player.faction) {
        console.log(player.faction);
        await player.faction.fetch();
        console.log(player.faction);
    }
    else
        console.log('This player is not in a faction.');
}).catch(error => {
    console.log(error.error);
});

FAQs

Package last updated on 23 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts