Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit 65e8bb0

Browse files
committed
Merge branch 'release/v2.1.0'
2 parents 52d96e9 + 3a02ca3 commit 65e8bb0

File tree

8 files changed

+232
-113
lines changed

8 files changed

+232
-113
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ api.getDataUsage()
3939
```
4040

4141
## Documentation / Methods
42-
You can view all the available methods and documentation on the [PaladinsDev website](https://paladins.dev/docs/paladins.js/v/2.0.0/).
42+
You can view all the available methods and documentation on the [PaladinsDev website](https://paladins.dev/docs/paladins.js/v/2.1.0/).

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "paladins.js",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"description": "A JavaScript package to help make communication with the Paladins API from Hi-Rez/Evil Mojo easier.",
55
"keywords": [
66
"paladins",
@@ -15,7 +15,7 @@
1515
"scripts": {
1616
"test": "jest",
1717
"compile": "./node_modules/.bin/tsc",
18-
"docs": "node_modules/.bin/typedoc --theme node_modules/typedoc-clarity-theme/bin --out ./docs ./src",
18+
"docs": "node_modules/.bin/typedoc --options ./typedoc.json",
1919
"prepublish": "npm run compile"
2020
},
2121
"repository": {
@@ -50,10 +50,10 @@
5050
"@types/request": "^2.48.4",
5151
"@types/request-promise": "^4.1.46",
5252
"cross-env": "^7.0.2",
53+
"eledoc": "^0.2.1",
5354
"jest": "^25.2.7",
5455
"ts-jest": "^25.3.1",
55-
"typedoc": "^0.14.2",
56-
"typedoc-clarity-theme": "^1.1.0",
56+
"typedoc": "^0.17.4",
5757
"typescript": "^3.2.4"
5858
}
5959
}

src/api.ts

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ import md5 from 'md5';
77
import rp from 'request-promise';
88
import sr from 'sync-request';
99
import { NotFoundError, PrivateProfileError, UnauthorizedDeveloper } from './errors';
10+
import { Portals } from './util/enumerations';
1011

1112
export default class API {
13+
/** @ignore */
1214
private serviceUrl: string = 'http://api.paladins.com/paladinsapi.svc';
15+
/** @ignore */
1316
private sessionCache: { [key: string]: any} = {};
1417

15-
constructor(private options: { [key: string]: any} = { }) {
18+
constructor(/** @ignore */private options: { [key: string]: any} = { }) {
1619
this.options = Util.mergeDefaults(DefaultOptions, options);
1720

1821
this.setupModule();
@@ -138,7 +141,10 @@ export default class API {
138141

139142
/**
140143
* Get an array of players with the requested name.
144+
*
145+
* Will be removed in future releases. Please use {@link API.searchPlayers} for searching.
141146
*
147+
* @deprecated
142148
* @param {string} name
143149
* @returns {Promise<any>}
144150
* @memberof API
@@ -237,6 +243,18 @@ export default class API {
237243
return this.endpoint('getmatchhistory', [playerId]);
238244
}
239245

246+
/**
247+
* Get the queue stats of a player.
248+
*
249+
* @param {number} playerId
250+
* @param {number} queueId
251+
* @returns {Promise<any>}
252+
* @memberof API
253+
*/
254+
public getPlayerQueueStats(playerId: number, queueId: number): Promise<any> {
255+
return this.endpoint('getqueuestats', [playerId, null, null, null, queueId]);
256+
}
257+
240258
/**
241259
* Get the information for an ended match.
242260
*
@@ -248,6 +266,41 @@ export default class API {
248266
return this.endpoint('getmodedetails', [matchId]);
249267
}
250268

269+
/**
270+
* Get details on multiple matches
271+
*
272+
* @param {number[]} matchIds
273+
* @param {boolean} [returnSorted=true] Makes each match sorted in the object. If you set this to false, it may improve performance when requesting many matches but it will return everything in a single array.
274+
* @returns {Promise<any>}
275+
* @memberof API
276+
*/
277+
public getMatchModeDetailsBatch(matchIds: number[], returnSorted: boolean = true): Promise<any> {
278+
if (returnSorted) {
279+
return new Promise((resolve, reject) => {
280+
this.endpoint('getmatchdetailsbatch', [matchIds.join(',')])
281+
.then((data) => {
282+
let sorted: { [key: string]: any[] } = {}
283+
284+
data.forEach((matchPlayer: any) => {
285+
if (sorted[matchPlayer['Match']]) {
286+
sorted[matchPlayer['Match']].push(matchPlayer);
287+
} else {
288+
sorted[matchPlayer['Match']] = [];
289+
sorted[matchPlayer['Match']].push(matchPlayer);
290+
}
291+
});
292+
293+
return resolve(sorted);
294+
})
295+
.catch((err) => {
296+
return reject(err);
297+
})
298+
})
299+
} else {
300+
return this.endpoint('getmatchdetailsbatch', [matchIds.join(',')]);
301+
}
302+
}
303+
251304
/**
252305
* Get match details from an ended match.
253306
*
@@ -280,6 +333,35 @@ export default class API {
280333
return this.endpoint('getdataused', [], true);
281334
}
282335

336+
/**
337+
* Do a general player search that returns more detail information on the players.
338+
*
339+
* @param {string} name
340+
* @param {boolean} [mapPortals=false] Map the portals to their general name. WARNING: This can severely affect performance if you are doing generic names because of Switch results.
341+
* @returns {Promise<any>}
342+
* @memberof API
343+
*/
344+
public searchPlayers(name: string, mapPortals: boolean = false): Promise<any> {
345+
if (mapPortals) {
346+
return new Promise((resolve, reject) => {
347+
this.endpoint('searchplayers', [name])
348+
.then((data) => {
349+
data.forEach((player: any) => {
350+
player['portal_name'] = Portals[player['portal_id']];
351+
});
352+
353+
return resolve(data);
354+
})
355+
.catch((err) => {
356+
return reject(err);
357+
})
358+
})
359+
} else {
360+
return this.endpoint('searchplayers', [name]);
361+
}
362+
}
363+
364+
/** @ignore */
283365
private endpoint(endpoint: string, args: Array<any>, returnFirstElement: boolean = false): Promise<any> {
284366
let fArgs = <any>[endpoint].concat(args);
285367
let url = this.buildUrl.apply(this, fArgs);
@@ -305,14 +387,17 @@ export default class API {
305387
})
306388
}
307389

390+
/** @ignore */
308391
private getTimestamp() {
309392
return moment().utc().format('YYYYMMDDHHmmss');
310393
}
311394

395+
/** @ignore */
312396
private getSignature(method: string) {
313397
return md5(`${this.options['devId']}${method}${this.options['authKey']}${this.getTimestamp()}`)
314398
}
315399

400+
/** @ignore */
316401
private setSession(): string {
317402
let response = sr('GET', `${this.getServiceUrl()}/createsessionJson/${this.options['devId']}/${this.getSignature('createsession')}/${this.getTimestamp()}`);
318403
let body = JSON.parse(response.body.toString());
@@ -332,10 +417,12 @@ export default class API {
332417
return this.sessionCache['sessionId'];
333418
}
334419

420+
/** @ignore */
335421
private saveSessionCache() {
336422
fs.writeFileSync(path.resolve(__dirname, 'cache', 'session.json'), JSON.stringify(this.sessionCache));
337423
}
338424

425+
/** @ignore */
339426
private getSession(): string {
340427
if (this.sessionCache['sessionId'] == undefined || this.sessionCache['sessionId'] == null || this.sessionCache['sessionId'].length < 1) {
341428
return this.setSession();
@@ -344,6 +431,7 @@ export default class API {
344431
return this.sessionCache['sessionId'];
345432
}
346433

434+
/** @ignore */
347435
private buildUrl(method: string, player?: any, lang?: number, matchId?: number, champId?: number, queue?: number, tier?: number, season?: number, platform?: number) {
348436
let session = this.getSession();
349437
let baseUrl = `${this.getServiceUrl()}/${method}Json/${this.options['devId']}/${this.getSignature(method)}/${session}/${this.getTimestamp()}`;
@@ -383,12 +471,14 @@ export default class API {
383471
return baseUrl;
384472
}
385473

474+
/** @ignore */
386475
private makeRequest(url: string) {
387476
return rp(url).then((r: any) => {
388477
return r;
389478
});
390479
}
391480

481+
/** @ignore */
392482
private setupModule() {
393483
try {
394484
let data = fs.readFileSync(path.resolve(__dirname, 'cache', 'session.json'));

src/paladins.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** @ignore *//** */
12
import API from './api';
23

34
export default API;

src/util/enumerations.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
export enum Portals {
2+
Unknown = 0,
3+
HiRez = 1,
4+
Steam = 5,
5+
Epic = 28,
6+
PSN = 9,
7+
XboxLive = 10,
8+
Nintendo = 22,
9+
Discord = 25,
10+
Mixer = 14,
11+
Facebook = 12,
12+
Google = 13
13+
}
14+
15+
export enum Languages {
16+
English = 1,
17+
German = 2,
18+
French = 3,
19+
Chinese = 5,
20+
Spanish = 9,
21+
Portuguese = 10,
22+
Russian = 11,
23+
Polish = 12,
24+
Turkish = 13
25+
}
26+
27+
export enum Ranks {
28+
Qualifying = 0,
29+
Bronze_V = 1,
30+
Bronze_IV = 2,
31+
Bronze_III = 3,
32+
Bronze_II = 4,
33+
Bronze_I = 5,
34+
Silver_V = 6,
35+
Silver_IV = 7,
36+
Silver_III = 8,
37+
Silver_II = 9,
38+
Silver_I = 10,
39+
Gold_V = 11,
40+
Gold_IV = 12,
41+
Gold_III = 13,
42+
Gold_II = 14,
43+
Gold_I = 15,
44+
Platinum_V = 16,
45+
Platinum_IV = 17,
46+
Platinum_III = 18,
47+
Platinum_II = 19,
48+
Platinum_I = 20,
49+
Diamond_V = 21,
50+
Diamond_IV = 22,
51+
Diamond_III = 23,
52+
Diamond_II = 24,
53+
Diamond_I = 25,
54+
Master = 26,
55+
Grandmaster = 27
56+
}
57+
58+
export enum ProfileStates {
59+
Offline = 0,
60+
In_Lobby = 1,
61+
Champion_Selection = 2,
62+
In_Match = 3,
63+
Online = 4,
64+
Unknown = 5
65+
}
66+
67+
export enum Queue {
68+
Unknown = 0,
69+
Casual_Siege = 424,
70+
Team_Deathmatch = 469,
71+
Onslaught = 452,
72+
Ranked_Keyboard = 486,
73+
Ranked_Controller = 428,
74+
Shooting_Range = 434,
75+
Training_Siege = 425,
76+
Training_Team_Deathmatch = 470,
77+
Training_Onslaught = 453,
78+
Test_Maps = 445
79+
}

src/util/util.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** @ignore *//** */
12
const has = (o: any, k: any) => Object.prototype.hasOwnProperty.call(o, k);
23

34
export default class Util {

typedoc.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "PaladinsJS",
3+
"inputFiles": ["./src"],
4+
"exclude": ["**/*+(index|.spec|.e2e).ts"],
5+
"mode": "modules",
6+
"out": "docs",
7+
"theme": "default",
8+
"includeVersion": true
9+
}

0 commit comments

Comments
 (0)