0.3.0 • Published 10 years ago

sc2ranks v0.3.0

Weekly downloads
6
License
-
Repository
github
Last release
10 years ago

SC2 Ranks for Javascript

A NodeJS Javascript library for accessing the API from SC2 Ranks.

Why?

I suck at Starcraft but I'm awesome at Javascript.

Installing

npm install sc2ranks

Usage

All examples require you to setup a data context to the API with your key. You can get your SC2 Ranks key from here.

var sc2 = require('sc2ranks');
var api = new sc2.Context('your-api-key');

Get a Player

Create a Player model by passing in a Battle.NET ID and a region to the API factory function:

var player = api.factory(Player, 2840641, sc2.REGIONS.US);

To fetch the player's info, call the fetch() method, which returns a Q promise;

var promise = player.fetch();

promise.done(function() { console.log(player); });

As a query:

new sc2.Query(api)
  .from(sc2.Players)
  .where(sc2.Region, sc2.REGIONS.US)
  .where(sc2.BattleNetId, 2840641)
  .first()
  .then(function(player) {
    console.log(player);
  })
  .fail(function(err) {
    console.log('error', err);
  });

Get a Player's Teams

var player = api.factory(Player, 2840641, sc2.REGIONS.US);

player.getTeams()
  .done(function() {
    console.log(player.teams);
  });

As a query:

new sc2.Query(api)
  .from(sc2.Teams)
  .where(sc2.Region, sc2.REGIONS.US)
  .where(sc2.BattleNetId, 2840641)
  .where(sc2.Race, sc2.RACES.TERRAN)
  .where(sc2.League, sc2.GRANDMASTER)
  .select()
  .done(function(teams) {
    console.log(teams);
  });
0.3.0

10 years ago

0.2.0

10 years ago

0.1.1

10 years ago