Skip to content

Commit

Permalink
Add GamesSummary endpoint (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
lovethebomb committed Aug 18, 2018
1 parent 06507d8 commit c7303a6
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ async function getData() {

- [Player](#player)
- [Match](#match)
- [GamesSummary](#gamessummary)

### Player

Expand Down Expand Up @@ -73,6 +74,22 @@ async function getMatchWithPlayerSummary() {
}
```

### GamesSummary

#### get(playername)

Retrieve a GamesSummary data for a given `playername`.

Returns JSON from the API.

```javascript
const client = new QuakeChampionsClient();

async function getGamesSummary() {
const gamesSummary = await client.gamesSummary.get('my-playername');
}
```

## Testing

```bash
Expand Down
50 changes: 50 additions & 0 deletions __tests__/gamesSummary.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const QuakeChampionsClient = require('../index.js');

describe('Client/GamesSummary', () => {
const client = new QuakeChampionsClient();
const TEST_MATCH_PLAYERNAME = "lovethebomb";
const TEST_GAMESSUMMARY = {
"id": "7258a90b-a28f-11e8-bce6-0003ffb6be63",
"time": "2018-08-18T02:36:01.7236235Z",
"mapName": "fortress_of_the_deep",
"rank": 2,
"score": null,
"gameMode": "FFA",
"won": true,
"xp": 2639,
"kdr": 1.6666666666666667,
"totalDamage": 5680,
"weaponAccuracy": {
"GAUNTLET": 0,
"MACHINEGUN": 23.976608187134502,
"MACHINEGUN_GRADE1": 34.66666666666667,
"SHOTGUN": 0,
"SHOTGUN_GRADE1": 75,
"NAILGUN": 0,
"NAILGUN_GRADE1": 0,
"ROCKET_LAUNCHER": 43.82022471910113,
"LIGHTNING_GUN": 39.726027397260275,
"RAILGUN": 58.333333333333336,
"LAGBOLT": 0
}
};

test('should throw if missing playername', async () => {
expect.assertions(1);
try {
await client.gamesSummary.get();
} catch (e) {
expect(e.message).toBe('gamesSummary/get requires a playername')
}
});

test('should be able to fetch data for playername lovethebomb', async () => {
expect.assertions(1);
const gamesSummary = await client.gamesSummary.get(TEST_MATCH_PLAYERNAME);
expect(gamesSummary).toEqual(expect.objectContaining({
"matches": expect.arrayContaining([
expect.objectContaining(TEST_GAMESSUMMARY)
])
}));
});
})
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fetch = require('isomorphic-unfetch');

const player = require('./lib/player');
const match = require('./lib/match');
const gamesSummary = require('./lib/gamesSummary');

const API_URL = "https://stats.quake.com/api/";
const API_VERSION = "v2";
Expand All @@ -14,6 +15,7 @@ class QuakeChampionsClient {

this.player = player.bind(this)();
this.match = match.bind(this)();
this.gamesSummary = gamesSummary.bind(this)();
}

async request(url) {
Expand Down
17 changes: 17 additions & 0 deletions lib/gamesSummary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function gamesSummary() {
const endpoint = '/Player/GamesSummary';
return {
get: async (playername = false) => {
if (!playername) {
throw new Error('gamesSummary/get requires a playername');
}

const query = `?name=${playername}`;
const url = `${endpoint}${query}`
return this.request(url)
.then(data => this.toJson(data));
},
}
}

module.exports = gamesSummary;

0 comments on commit c7303a6

Please sign in to comment.