challonge-js

1.1.1 • Public • Published

Usage

Get all tournaments on your account

const challonge = require('./node-challonge');
const client = challonge.createClient({
  apiKey: '<yourApiKey>'
});
 
client.tournaments.index({
  callback: function (error, data) {
    if (error) { console.log(error); return; }
    console.log(data);
  }
});
 

Create a tournament

const challonge = require('./node-challonge');
const client = challonge.createClient({
  apiKey: '<yourApiKey>'
});
 
client.tournaments.create({
  tournament: {
    name: 'new_tournament_name',
    url: 'new_tournament_url',
    tournamentType: 'single elimination'
  },
  callback: function (error, data) {
    if (error) { console.log(error); return; }
    console.log(data);
  }
});

API Client

createClient takes one argument for configuration and returns an instance of the api client. The configuration object can contain the following options:

  • apiKey string (required) - Your challonge API Key

  • subdomain string (optional) - Setting the subdomain automatically passes tournament[subdomain] and prefixes the subdomain to tournament urls. If you don't want to pass a subdomain to the constructor, and want to use an organization (or multiple organizations), you must use client.setSubdomain('subdomain') before making api calls.

  • format string (optional) - The format of the response data. Defaults to 'json'. If set to 'json', will return javascript objects. 'xml' will return the raw text string.

  • massageProperties boolean (optional) - If the response object should be massaged into camelCase properties when using json format. Defaults to true.

The wrapper is organized into resource.method to match the API

For API calls that require nested params (eg: http://api.challonge.com/v1/documents/tournaments/create) properties should be specified as a nested object:

{
    tournament: {
        name: 'new_tournament_name',
        url: 'new_tournament_url',
        tournamentType: 'single elimination'
    },
    callback: function (error, data) {}
}

All properties can be specified camelCase instead of using under_scores Both of the following are valid:

tournament: { tournamentType: 'single elimination' }
tournament: { tournament_type: 'single elimination' }

TODO

  1. validate required params
  2. docs
  3. tests

Bugs in the API / docs

Some minor gatchas:


The structure of this api wrapper is ripped off from https://github.com/nodejitsu/nodejitsu-api
This repository was forked from https://github.com/Tidwell/node-challonge

Package Sidebar

Install

npm i challonge-js

Weekly Downloads

2

Version

1.1.1

License

none

Last publish

Collaborators

  • jonas-vanen
  • tidwell