-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.service.ts
More file actions
82 lines (76 loc) · 2.12 KB
/
Copy pathstats.service.ts
File metadata and controls
82 lines (76 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import type {
GlobalAchievementPercentagesForAppResponse,
NumberOfCurrentPlayersResponse,
PlayerAchievementsResponse,
SchemaForGameResponse,
UserStatsForGameResponse,
} from '../schemas/responses'
import { BaseService } from './_base.service'
export class StatsService extends BaseService {
constructor(apiKey: string) {
super(apiKey, 'api', 'ISteamUserStats')
}
async getNumberOfCurrentPlayers(
appId: number,
): Promise<NumberOfCurrentPlayersResponse> {
const url = this.generateSteamUrl(`/GetNumberOfCurrentPlayers/v1`, {
appid: appId,
})
const response = await this.sendGETRequest<{
response: NumberOfCurrentPlayersResponse
}>(url)
return response.response
}
async getPlayerAchievements(
steamUserId: string,
appId: number,
): Promise<PlayerAchievementsResponse> {
const url = this.generateSteamUrl(`/GetPlayerAchievements/v1`, {
steamid: steamUserId,
appid: appId,
})
return await this.sendGETRequest<PlayerAchievementsResponse>(url)
}
async getGlobalAchievementPercentagesForApp(
appId: number,
): Promise<GlobalAchievementPercentagesForAppResponse> {
const url = this.generateSteamUrl(
`/GetGlobalAchievementPercentagesForApp/v2`,
{
gameid: appId,
},
)
const response = await this.sendGETRequest<{
achievementpercentages: GlobalAchievementPercentagesForAppResponse
}>(url)
return response.achievementpercentages
}
/**
* Gets available game achivements and stats for the given app
*/
async getSchemaForGame(appId: number): Promise<SchemaForGameResponse> {
const url = this.generateSteamUrl(`/GetSchemaForGame/v2`, {
appid: appId,
})
const response = await this.sendGETRequest<{
game: SchemaForGameResponse
}>(url)
return response.game
}
/**
* Gets unlocked achievements for a user for a game
*/
async getUserStatsForGame(
steamUserId: string,
appId: number,
): Promise<UserStatsForGameResponse> {
const url = this.generateSteamUrl(`/GetUserStatsForGame/v2`, {
steamid: steamUserId,
appid: appId,
})
const response = await this.sendGETRequest<{
playerstats: UserStatsForGameResponse
}>(url)
return response.playerstats
}
}