1.4.0 • Published 2 years ago

retroachievements-js v1.4.0

Weekly downloads
8
License
MIT
Repository
github
Last release
2 years ago

Features

Contents

Getting started

Install

npm install --save retroachievements-js

OR

yarn add retroachievements-js

Usage with Node

Node 10 and above are officially supported. The package can be imported via:

const RetroAchievementsClient = require('retroachievements-js');

Usage with TypeScript

You can use import syntax to utilize the package in your app. This library provides its own type definitions. "It just works", no need to install anything from @types.

import { RetroAchievementsClient } from 'retroachievements-js';

Understanding the Promise-based API

All methods in the API are async and return a native Promise.

These methods can be used with the native Promise API or the more modern async/await syntax.

// Native Promise API.
client.getTopTen().then(topTen => {
  console.log({ topTen });
});

// async/await syntax.
const logTopTenUsers = async () => {
  const topTen = await client.getTopTen();
  console.log({ topTen });
};

Examples

Initializing the Client

To initialize the client, you will need your username and your RetroAchievements Web API key. To get your Web API key, visit your control panel on the RetroAchievements website.

You can initialize the client like so:

import { RetroAchievementsClient } from 'retroachievements-js';

const client = new RetroAchievementsClient({
  userName: 'MyUserName', // this is your actual account name on the site
  apiKey: 'MyApiKey'
});

Please note if you are using this library in the browser then your API key will be exposed. This is not destructive, as the API is read-only, but that could change at any time. For this reason, I recommend only using the library on the server where your API key can be kept a secret.

Top ten users by points

const printTopTenUsers = async () => {
  const topTen = await client.getTopTenUsers();
  console.log({ topTen });
};

Get all console IDs

const printAllConsoleIds = async () => {
  const allConsoleIds = await client.getConsoleIds();
  console.log({ allConsoleIds });
};

Get list of all registered Gameboy games

const printAllGameboyGames = async () => {
  const allGameboyGames = await client.getGameListByConsoleId(4);
  console.log({ allGameboyGames });
};

Basic game information for Super Mario Land (GB)

const printGameInfo = async () => {
  const superMarioLandInfo = await client.getGameInfoByGameId(504);
  console.log({ superMarioLandInfo });
};

Full game information for Super Mario Land (GB)

const printExtendedGameInfo = async () => {
  const superMarioLandExtendedInfo = await client.getExtendedGameInfoByGameId(
    504
  );

  console.log({ superMarioLandExtendedInfo });
};

Complete summary of Scott's progress for game ID 3

const printUserGameProgress = async () => {
  const userGameProgress = await client.getUserProgressForGameId('Scott', 3);
  console.log({ userGameProgress });
};

Scott's global rank and score

const printUserGlobalRankAndScore = async () => {
  const userRankAndScore = await client.getUserRankAndScore('Scott');
  console.log({ userRankAndScore });
};

Scott's 10 most recently played games

const printUserRecentGames = async () => {
  const userRecentGames = await client.getUserRecentlyPlayedGames('Scott', 10);
  console.log({ userRecentGames });
};

Scott's progress on games with IDs 2, 3, and 75

const printUserMultipleGameProgress = async () => {
  const userProgress = await client.getUserProgressForGames('Scott', [
    2,
    3,
    75
  ]);

  console.log({ userProgress });
};

Scott's user summary

const printUserSummary = async () => {
  const userSummary = await client.getUserSummary('Scott');
  console.log({ userSummary });
};

Achievements earned by Scott on January 4th, 2014

const printUserAchievementsOnDate = async () => {
  const achievementsOnDate = await client.getUserAchievementsEarnedOnDate(
    'Scott',
    new Date('01-04-2014')
  );

  console.log({ achievementsOnDate });
};

Scott's game completion progress

const printUserCompletionProgress = async () => {
  const completionProgress = await client.getUserGameCompletionStats('Scott');
  console.log({ completionProgress });
};
1.3.6

2 years ago

1.3.5

2 years ago

1.3.4

2 years ago

1.4.0

2 years ago

1.3.3

2 years ago

1.2.0

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.0.2

3 years ago

1.1.0

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago