Skip to content

Commit

Permalink
Merge pull request #15 from martinsileno/season-state
Browse files Browse the repository at this point in the history
Add typing for seasonState attribute added in PUBG API v6.0.0
  • Loading branch information
martinsileno committed Oct 5, 2018
2 parents 40265bf + e731d35 commit 298ae4a
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pubg-typescript-api",
"version": "1.5.0",
"version": "1.5.1",
"description": "TypeScript wrapper on the official PUBG API",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions src/entities/match.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import 'mocha';

import { DeathType, GameMode, IMatch, MapName, PlatformRegion } from '..';
import { DeathType, GameMode, IMatch, MapName, PlatformRegion, SeasonState } from '..';

import { Asset } from './asset';
import { Match } from './match';
Expand All @@ -20,7 +20,7 @@ const API_RESPONSE: IMatch = {
"gameMode": "duo-fpp",
"isCustomMatch": false,
"mapName": "Desert_Main",
"seasonState": "",
"seasonState": "progress",
"shardId": "pc-eu",
"stats": null,
"tags": null,
Expand Down Expand Up @@ -685,7 +685,7 @@ describe('Match entity', () => {
expect(match.isCustomMatch).to.be.false;
expect(match.map).to.equal(MapName.DESERT_MAIN);
expect(match.patchVersion).to.be.an('undefined');
expect(match.seasonState).to.equal('');
expect(match.seasonState).to.equal(SeasonState.PROGRESS);
expect(match.shardId).to.equal(PlatformRegion.PC_EU);
});

Expand Down
5 changes: 3 additions & 2 deletions src/entities/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
PlatformRegion,
PubgAPI,
Roster,
SeasonState,
Telemetry,
TelemetryPubgAPI,
} from '..';
Expand All @@ -30,7 +31,7 @@ export class Match {
private _isCustomMatch: boolean;
private _map: MapName;
private _patchVersion: string | undefined;
private _seasonState: any;
private _seasonState: SeasonState;
private _shardId: PlatformRegion;

private _participants: Participant[];
Expand All @@ -45,7 +46,7 @@ export class Match {
this._isCustomMatch = matchDetail.data.attributes.isCustomMatch;
this._map = matchDetail.data.attributes.mapName as MapName;
this._patchVersion = matchDetail.data.attributes.patchVersion;
this._seasonState = matchDetail.data.attributes.seasonState;
this._seasonState = matchDetail.data.attributes.seasonState as SeasonState;
this._shardId = matchDetail.data.attributes.shardId as PlatformRegion;

const participantsMap = new Map<string, Participant>(); // maps participant id to Participant
Expand Down
8 changes: 4 additions & 4 deletions src/entities/telemetry/events/matchDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { ILogMatchDefinition } from '../../..';
import { ILogMatchDefinition, SeasonState } from '../../..';

import { TelemetryEvent } from './telemetryEvent';


export class MatchDefinition extends TelemetryEvent {
private _matchId: string;
private _pingQuality: string;
private _seasonState: any;
private _seasonState: SeasonState;

constructor(event: ILogMatchDefinition) {
super(event);
this._matchId = event.MatchId;
this._pingQuality = event.PingQuality;
this._seasonState = event.SeasonState;
this._seasonState = event.SeasonState as SeasonState;
}

get matchId(): string {
Expand All @@ -23,7 +23,7 @@ export class MatchDefinition extends TelemetryEvent {
return this._pingQuality;
}

get seasonState(): any {
get seasonState(): SeasonState {
return this._seasonState;
}
}
6 changes: 3 additions & 3 deletions src/entities/telemetry/telemetry.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import 'mocha';

import { ITelemetry, Telemetry } from '../..';
import { ITelemetry, SeasonState, Telemetry } from '../..';


//#region setup
Expand All @@ -10,7 +10,7 @@ const API_RESPONSE: ITelemetry = [
{
"MatchId": "match.bro.official.2018-04.eu.duo-fpp.2018.04.27.8c1c8a56-4104-46ef-8aec-5e012b041574",
"PingQuality": "low",
"SeasonState": "",
"SeasonState": "progress",
"_D": "2018-04-27T09:14:41.7057369+00:00",
"_T": "LogMatchDefinition"
},
Expand Down Expand Up @@ -1163,7 +1163,7 @@ describe('Telemetry entity', () => {
/* tslint:disable-next-line:max-line-length */
expect(event.matchId).to.equal('match.bro.official.2018-04.eu.duo-fpp.2018.04.27.8c1c8a56-4104-46ef-8aec-5e012b041574');
expect(event.pingQuality).to.equal('low');
expect(event.seasonState).to.equal('');
expect(event.seasonState).to.equal(SeasonState.PROGRESS);
expect(event.dateTime).to.deep.equal(new Date('2018-04-27T09:14:41.7057369+00:00'));
});

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export interface IMatch {
isCustomMatch: boolean;
mapName: string; // XXX: sometimes not returned?
patchVersion?: ''; // XXX: sometimes not returned?
seasonState: any;
seasonState: string;
shardId: string;
stats: null;
tags: null;
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export interface ILogMatchDefinition extends IBaseTelemetryEvent {
_T: 'LogMatchDefinition';
MatchId: string;
PingQuality: string; // PC only
SeasonState: any;
SeasonState: string;
}

export interface ILogMatchStart extends ITelemetryEvent {
Expand Down
6 changes: 6 additions & 0 deletions src/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export enum PlatformRegion {
KAKAO = 'kakao'
}

export enum SeasonState {
CLOSED = 'closed',
PREPARE = 'prepare',
PROGRESS = 'progress'
}

export enum TelemetryEventType {
LOGPLAYERLOGIN = 'LogPlayerLogin',
LOGPLAYERCREATE = 'LogPlayerCreate',
Expand Down
1 change: 1 addition & 0 deletions src/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export {
GameMode,
MapName,
PlatformRegion,
SeasonState,
TelemetryEventType,
} from './constants';

0 comments on commit 298ae4a

Please sign in to comment.