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

wrap-royale-core

v1.3.0

Published

A promise based, minimalist wrapper for the official Clash Royale API written in TypeScript.

Downloads

53

Readme

Wrap Royale Core

Discord Server npm version Travis GitHub license

Wrap royale core is a promise based, minimalist wrapper for the official Clash Royale REST API. It covers all endpoints and parameters, but it barely offers any utility methods. If you are looking for a more feature rich library to interact with the Clash Royale API, take a look at wrap-royale which utilizes this library.

Official Clash Royale API documentation: https://developer.clashroyale.com

Features

  • [x] Lightweight, promise based wrapper functions for API requests.
  • [x] Types for all returned JSON data, which makes working with it very handy due to intellisense (see: https://i.imgur.com/xzP1AHC.png).
  • [x] Normalizes player tags, no matter if you pass #2OPP, 20pp or #20pp the request will succeed.
  • [x] Failed requests (wrong https status code in response or timeout exceeded) throw an exception
  • [x] All API endpoints and parameters are covered.

Getting started

Prerequisites

  • Node.js 8.0+
  • Token for the official Clash Royale API (register here and create a token for your IP address https://developer.clashroyale.com)

Installation

$ npm install --save wrap-royale-core

Note: Typescript definitions are included, there is no need for installing types from the Definetely Typed Repo.

Basic usage

Typescript (2.0+):

import { CRApi, IApiCards } from 'wrap-royale-core';

const baseUri: string = 'https://api.clashroyale.com/v1';
const apiToken: string = 'my-long-jwt';
const api: CRApi = new CRApi(baseUri, apiToken);

async function getAllCards(): Promise<void> {
  try {
    const cards: IApiCards = await api.cards();
    console.log(cards);
  } catch (e) {
    console.log(e);
  }
}

getAllCards();

Javascript (ES6+):

const CRApi = require('wrap-royale-core').CRApi;

const baseUri = 'https://api.clashroyale.com/v1';
const apiToken = 'my-long-jwt';
const api = new CRApi(baseUri, apiToken);

api.cards()
  .then((cards) => {
    console.log(cards);
  })
  .catch((err) => {
    console.log(err);
  })

Class CRApi

The class CRApi offers all available endpoints as promise based functions. Each function returns a Promise which resolves to the json response from the API. If the HTTPS response code is not 2xx (for instance 503 which is being used for API maintenance) an exception will be thrown.

Instantion

When creating a CRApi instance you can pass the following options:

/**
 * Initialize all settings.
 * @param uri Base url to Clash Royale API e.g. 'https://api.clashroyale.com/v1/'.
 * @param token Your API token (JWT as string).
 * @param options Additional options for this wrapper.
 */
constructor(uri: string, token: string, options?: IApiOptions);

interface IApiOptions {
    /**
     * Timeout for awaiting a response until it fails. Defaults to 6000 milliseconds.
     */
    timeoutMS?: number;
}

Available endpoints

Below you'll find a summary of all available methods. For more details about the parameters or method, take a look at the code which comes along with function documentation.

| Route | Returns | |------------------------------------------------------------------------------------------|-----------------------------------| | cards() | Promise<IApiCards> | | locations(limit?: number, after?: string, before?: string) | Promise<IApiLocations> | | locationById(locationId: number) | Promise<IApiLocation> | | clanWarLeaderboard(locationId: string, limit?: number, after?: string, before?: string)| Promise<IApiClanWarLeaderboard> | | playerLeaderboard(locationId: string, limit?: number, after?: string, before?: string) | Promise<IApiPlayerLeaderboard> | | clanLeaderboard(locationId: string, limit?: number, after?: string, before?: string) | Promise<IApiClanLeaderboard> | | playerProfile(playerTag: string) | Promise<IApiPlayerProfile> | | playersUpcomingChests(playerTag: string) | Promise<IApiUpcomingChests> | | playersBattleLogs(playerTag: string) | Promise<IApiPlayersBattleLogs[]> | | clanProfile(clanTag: string) | Promise<IApiClanProfile> | | currentClanWarInfo(clanTag: string) | Promise<ICurrentClanWar> | | clanWarLog(clanTag: string, locationId: string, limit?: number, after?: string, before?: string)| Promise<IClanWarLog> |