Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyuman committed Jul 6, 2016
1 parent f3366ce commit 5f9c35b
Show file tree
Hide file tree
Showing 10 changed files with 493 additions and 512 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- 6
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
# championgg-api-node
A node module wrapper for the Champion.GG API
# Node.js Client for the Champion.GG API

[![NPM](https://nodei.co/npm/@solomid/node-gg.png?mini=true)](https://www.npmjs.com/package/@solomid/node-gg)

[![Build Status via Travis CI](https://travis-ci.org/solomidnet/championgg-api-node.svg?branch=master)](https://travis-ci.org/solomidnet/championgg-api-node)

The official Champion.GG API Node.js Client.

# installation
```
npm i @solomid/node-gg
```

If you really need an ES5 version:
```
npm i @solomid/[email protected]
```

# usage
First, instantiate the wrapper with your api key
```
var GG = require('node-gg');
var gg = GG.init('YOUR_KEY');
const GG = require('node-gg');
const gg = GG.init('YOUR_KEY');
```

Then you gain access to all current endpoints of the API! All but initialization require a callback function and some also require either `role` or `champion_name`, along with an optional object with ...options. These options are passed as query string params and are `page` and `limit`
Then you gain access to all current endpoints of the API! All but initialization require a callback function and some also require either `role` or `champion_name`, along with an optional object with ...options. These options are passed as query string params and are `page` and `limit`.

The methods are:

Expand Down Expand Up @@ -58,6 +68,3 @@ Method | Parameters |

## contributing
Feel free to contribute, let's just try to keep it readable :)

## Release History
* 1.0.0 Initial release
19 changes: 9 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
var stats = require('./lib/stats');
var champs = require('./lib/champs');
const champions = require('./lib/champions');
const statistics = require('./lib/statistics');

var key = null;
function init(key) {
if (!key) throw new Error('API Key Required');

statistics.init(key);
champions.init(key);

function init(_key) {
if (!_key) throw new Error('API Key required');
key = _key;
stats.init(key);
champs.init(key);
return {
statistics: stats,
champions: champs
statistics: statistics,
champions: champions
};
}

Expand Down
162 changes: 162 additions & 0 deletions lib/champions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
const { request, resolve, error } = require('./utils');

const base = '/champion';

function all (cb) {
request(base, module.key, (err, res) => {
if (err) throw err;
resolve(res, cb);
});
}

function specific(name, cb) {
if (!name || typeof name !== 'string') throw new Error(error.champ);

request(`${base}/${name}`, module.key, (err, res) => {
if (err) throw err;
resolve(res, cb);
});
}

function general(name, cb) {
if (!name || typeof name !== 'string') throw new Error(error.champ);

resolve(`${base}/${name}/general`, module.key, (err, res) => {
if (err) throw err;
resolve(res, cb);
});
}

function generalMatchup (name, cb) {
if (!name || typeof name !== 'string') throw new Error(error.champ);

request(`${base}/${name}/matchup`, module.key, (err, res) => {
if (err) throw err;
resolve(res, cb);
});
}

function specificMatchup (name, enemy, cb) {
if (!name || typeof name !== 'string') throw new Error(error.champ);
if (!enemy || typeof enemy !== 'string') throw new Error(error.enemy);

request(`${base}/${name}/matchup/${enemy}`, module.key, (err, res) => {
if (err) throw err;
resolve(res, cb);
});
}

function mostPopularFinishedItems(name, cb) {
if (!name || typeof name !== 'string') throw new Error(error.champ);

request(`${base}/${name}/items/finished/mostPopular`, module.key, (err, res) => {
if (err) throw err;
resolve(res, cb);
});
}

function mostWinsFinishedItems(name, cb) {
if (!name || typeof name !== 'string') throw new Error(error.champ);

request(`${base}/${name}/items/finished/mostWins`, module.key, (err, res) => {
if (err) throw err;
resolve(res, cb);
});
}

function mostWinsStartingItems(name, cb) {
if (!name || typeof name !== 'string') throw new Error(error.champ);

request(`${base}/${name}/items/starters/mostWins`, module.key, (err, res) => {
if (err) throw err;
resolve(res, cb);
});
}

function mostPopularStartingItems(name, cb) {
if (!name || typeof name !== 'string') throw new Error(error.champ);

request(`${base}/${name}/items/starters/mostPopular`, module.key, (err, res) => {
if (err) throw err;
resolve(res, cb);
});
}

function skillsInfo(name, cb) {
if (!name || typeof name !== 'string') throw new Error(error.champ);

request(`${base}/${name}/skills`, module.key, (err, res) => {
if (err) throw err;
resolve(res, cb);
});
}

function mostWinsSkills(name, cb) {
if (!name || typeof name !== 'string') throw new Error(error.champ);

request(`${base}/${name}/skills/mostWins`, module.key, (err, res) => {
if (err) throw err;
resolve(res, cb);
});
}

function mostPopularSkills(name, cb) {
if (!name || typeof name !== 'string') throw new Error(error.champ);

request(`${base}/${name}/skills/mostPopular`, module.key, (err, res) => {
if (err) throw err;
resolve(res, cb);
});
}

function mostPopularRunes (name, cb) {
if (!name || typeof name !== 'string') throw new Error(error.champ);

request(`${base}/${name}/runes/mostPopular`, module.key, (err, res) => {
if (err) throw err;
resolve(res, cb);
});
}

function mostWinningRunes (name, cb) {
if (!name || typeof name !== 'string') throw new Error(error.champ);

request(`${base}/${name}/runes/mostWins`, module.key, (err, res) => {
if (err) throw err;
resolve(res, cb);
});
}

module.exports = {
init: key => module.key = key,
all: all,
data: {
general: general,
specific: specific
},
skills: {
info: skillsInfo,
order: {
popular: mostPopularSkills,
winning: mostWinsSkills
}
},
items: {
starting: {
popular: mostPopularStartingItems,
winning: mostWinsStartingItems
},
finished: {
popular: mostPopularFinishedItems,
winning: mostWinsFinishedItems
}
},
runes: {
popular: mostPopularRunes,
winning: mostWinningRunes
},
matchups: {
general: generalMatchup,
specific: specificMatchup
}
}
Loading

0 comments on commit 5f9c35b

Please sign in to comment.