Skip to content

Commit

Permalink
Добавлен метод getPlayerSummaries
Browse files Browse the repository at this point in the history
  • Loading branch information
atreslesne committed Dec 14, 2017
1 parent dd008bc commit c88948f
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 1 deletion.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,44 @@ steam.getGlobalAchievementPercentagesForApp(440)
percent: 53.728801727294922
}]
```

### getPlayerSummaries

Метод возвращает информацию о профиле пользователя по указанному идентификатору/идентификаторам.

`getPlayerSummaries([players])`

* `players` - идентификатор или массив идентификаторов пользователей.

```js
const Steam = require('steam-web-api');
const steam = new Steam();

steam.getPlayerSummaries('76561198030288194')
.then(result => {
console.dir(result.players);
})
.catch(err => console.error(err.message))
```

Результат:

```js
[{
'id': '76561198030288194',
'name': 'Atres Lesne',
'realname': 'Vladimir',
'url': 'http://steamcommunity.com/id/atres/',
'avatar': {
'small': 'https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/25/253e5467ec2594e27d758508cbe6f176a4f6d4c7.jpg',
'medium': 'https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/25/253e5467ec2594e27d758508cbe6f176a4f6d4c7_medium.jpg',
'full': 'https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/25/253e5467ec2594e27d758508cbe6f176a4f6d4c7_full.jpg'
},
'created': 1284103613,
'location': {
'country': 'RU',
'state': '20',
'city': 39928
}
}]
```
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ class Steam {
'gameid': gameId
});
}

getPlayerSummaries(players) {
if (!Array.isArray(players)) players = [players];
return this.client.request('getPlayerSummaries', {
'steamids': players
});
}
}

module.exports = Steam;
15 changes: 15 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const SteamError = require('./error');

const EntityNews = require('./entity/entityNews');
const EntityAchievements = require('./entity/entityAchievements');
const EntityPlayers = require('./entity/entityPlayers');

class SteamClient {
static get methods() {
Expand Down Expand Up @@ -39,6 +40,18 @@ class SteamClient {
},
'key': false,
'entity': (data, method, url) => { return new EntityAchievements(data, method, url); }
},
'getPlayerSummaries': {
'name': 'getPlayerSummaries',
'url': {
'protocol': 'http',
'host': 'api.steampowered.com',
'path': '/ISteamUser/GetPlayerSummaries/v0002/'
},
'args': ['steamids'],
'defaults': {},
'key': true,
'entity': (data, method, url) => { return new EntityPlayers(data, method, url); }
}
}
}
Expand Down Expand Up @@ -80,10 +93,12 @@ class SteamClient {

method = SteamClient.methods[method];
if (method.key && !this.key) throw new SteamError('KEY_REQUIRED', { 'method': method.name });
if (method.key) args['key'] = this.key;

for (let arg of method.args) {
if (!(arg in args)) {
if (!(arg in method.defaults)) throw new SteamError('MISSING_ARGUMENT', { 'arg': arg });
if (Array.isArray(arg)) arg = arg.join(',');
args[arg] = method.defaults[arg];
}
}
Expand Down
35 changes: 35 additions & 0 deletions src/entity/entityPlayers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

const Entity = require('./entity');

class EntityPlayers extends Entity {
constructor(rawData, method, url) {
super(rawData, method, url);

let data = [];
for (let index in rawData['response']['players']) {
let item = rawData['response']['players'][index];
data.push({
'id': item['steamid'],
'name': item['personaname'],
'realname': item['realname'],
'url': item['profileurl'],
'avatar': {
'small': item['avatar'],
'medium': item['avatarmedium'],
'full': item['avatarfull']
},
'created': item['timecreated'],
'location': {
'country': item['loccountrycode'],
'state': item['locstatecode'],
'city': item['loccityid']
}
});
}

this.players = data;
}
}

module.exports = EntityPlayers;
33 changes: 32 additions & 1 deletion test/testSteam.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ const Steam = require('../index');

const EntityNews = require('../src/entity/entityNews');
const EntityAchievements = require('../src/entity/entityAchievements');
const EntityPlayers = require('../src/entity/entityPlayers');

const STEAM_KEY = process.env.STEAM_KEY;

describe('Steam', function () {
const steam = new Steam();
const steam = new Steam(STEAM_KEY);

it('getNewsForApp', (done) => {
steam.getNewsForApp(440, 2, 100)
Expand All @@ -32,4 +35,32 @@ describe('Steam', function () {
})
.catch(err => done(err));
});

it('getPlayerSummaries', (done) => {
steam.getPlayerSummaries('76561198030288194')
.then(res => {
assert.instanceOf(res, EntityPlayers);
assert.equal(res.url, 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?steamids=76561198030288194&key=' + STEAM_KEY);
assert.equal(res.method, 'getPlayerSummaries');
assert.deepEqual(res.players[0], {
'id': '76561198030288194',
'name': 'Atres Lesne',
'realname': 'Vladimir',
'url': 'http://steamcommunity.com/id/atres/',
'avatar': {
'small': 'https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/25/253e5467ec2594e27d758508cbe6f176a4f6d4c7.jpg',
'medium': 'https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/25/253e5467ec2594e27d758508cbe6f176a4f6d4c7_medium.jpg',
'full': 'https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/25/253e5467ec2594e27d758508cbe6f176a4f6d4c7_full.jpg'
},
'created': 1284103613,
'location': {
'country': 'RU',
'state': '20',
'city': 39928
}
});
done();
})
.catch(err => done(err));
});
});

0 comments on commit c88948f

Please sign in to comment.