npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pactify-api

v1.0.2

Published

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

Downloads

3

Readme

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: | statusCode | error | |---|---| | 0 | no error | | 1 | internal error (which surely comes from a connection error from you or the server) | | 2 | unknown player | | 3 | unknown 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);
});