@retroachievements/api 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -5
- package/dist/achievement/models/achievement-unlock-entity.model.d.ts +1 -0
- package/dist/achievement/models/get-achievement-unlocks-response.model.d.ts +1 -0
- package/dist/api.cjs +1 -1
- package/dist/api.cjs.map +1 -1
- package/dist/api.modern.js +1 -1
- package/dist/api.modern.js.map +1 -1
- package/dist/api.module.js +1 -1
- package/dist/api.module.js.map +1 -1
- package/dist/api.umd.js +1 -1
- package/dist/api.umd.js.map +1 -1
- package/dist/feed/getAchievementOfTheWeek.d.ts +2 -1
- package/dist/feed/getRecentGameAwards.d.ts +50 -0
- package/dist/feed/getRecentGameAwards.test.d.ts +1 -0
- package/dist/feed/index.d.ts +1 -0
- package/dist/feed/models/achievement-of-the-week.model.d.ts +1 -0
- package/dist/feed/models/get-achievement-of-the-week-response.model.d.ts +1 -0
- package/dist/feed/models/get-recent-game-awards-response.model.d.ts +14 -0
- package/dist/feed/models/index.d.ts +2 -0
- package/dist/feed/models/recent-game-awards.model.d.ts +14 -0
- package/dist/game/getGameHashes.d.ts +45 -0
- package/dist/game/getGameHashes.test.d.ts +1 -0
- package/dist/game/index.d.ts +1 -0
- package/dist/game/models/game-hashes.model.d.ts +10 -0
- package/dist/game/models/get-game-hashes-response.model.d.ts +10 -0
- package/dist/game/models/index.d.ts +2 -0
- package/dist/user/models/game-info-and-user-progress.model.d.ts +2 -1
- package/dist/user/models/get-game-info-and-user-progress-response.model.d.ts +2 -1
- package/dist/user/models/get-user-completion-progress-response.model.d.ts +2 -1
- package/dist/user/models/user-completion-progress-entity.model.d.ts +2 -1
- package/dist/utils/public/models/award-kind.model.d.ts +1 -0
- package/dist/utils/public/models/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/achievement/getAchievementUnlocks.test.ts +2 -0
- package/src/achievement/getAchievementUnlocks.ts +7 -1
- package/src/achievement/models/achievement-unlock-entity.model.ts +1 -0
- package/src/achievement/models/get-achievement-unlocks-response.model.ts +1 -0
- package/src/console/getConsoleIds.test.ts +4 -1
- package/src/feed/getAchievementOfTheWeek.test.ts +4 -0
- package/src/feed/getAchievementOfTheWeek.ts +3 -1
- package/src/feed/getRecentGameAwards.test.ts +78 -0
- package/src/feed/getRecentGameAwards.ts +85 -0
- package/src/feed/index.ts +1 -0
- package/src/feed/models/achievement-of-the-week.model.ts +1 -0
- package/src/feed/models/get-achievement-of-the-week-response.model.ts +1 -0
- package/src/feed/models/get-recent-game-awards-response.model.ts +15 -0
- package/src/feed/models/index.ts +2 -0
- package/src/feed/models/recent-game-awards.model.ts +15 -0
- package/src/game/getGameHashes.test.ts +77 -0
- package/src/game/getGameHashes.ts +66 -0
- package/src/game/index.ts +1 -0
- package/src/game/models/game-hashes.model.ts +10 -0
- package/src/game/models/get-game-hashes-response.model.ts +10 -0
- package/src/game/models/index.ts +2 -0
- package/src/user/models/game-info-and-user-progress.model.ts +2 -6
- package/src/user/models/get-game-info-and-user-progress-response.model.ts +2 -6
- package/src/user/models/get-user-completion-progress-response.model.ts +3 -6
- package/src/user/models/user-completion-progress-entity.model.ts +3 -6
- package/src/utils/public/models/award-kind.model.ts +5 -0
- package/src/utils/public/models/index.ts +1 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { AuthObject, AwardKind } from "../utils/public";
|
|
2
|
+
import type { RecentGameAwards } from "./models";
|
|
3
|
+
/**
|
|
4
|
+
* A call to this function will retrieve all recently granted game
|
|
5
|
+
* awards across the site's userbase.
|
|
6
|
+
*
|
|
7
|
+
* @param authorization An object containing your username and webApiKey.
|
|
8
|
+
* This can be constructed with `buildAuthorization()`.
|
|
9
|
+
*
|
|
10
|
+
* @param payload.startDate The date to fetch awards from.
|
|
11
|
+
*
|
|
12
|
+
* @param payload.offset Optional. Defaults to 0.
|
|
13
|
+
*
|
|
14
|
+
* @param payload.count Optional. Defaults to 25.
|
|
15
|
+
*
|
|
16
|
+
* @param payload.desiredAwardKinds Optional. Defaults to all. Accepts "beaten-softcore", "beaten-hardcore", "completed", and/or "mastered".
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```
|
|
20
|
+
* const recentGameAwards = await getRecentGameAwards(
|
|
21
|
+
* authorization,
|
|
22
|
+
* );
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @returns An object containing metadata about all recently granted game
|
|
26
|
+
* awards across the site's userbase
|
|
27
|
+
* ```
|
|
28
|
+
* {
|
|
29
|
+
* count: 1,
|
|
30
|
+
* total: 1,
|
|
31
|
+
* results: [
|
|
32
|
+
* {
|
|
33
|
+
* user: "renanbrj",
|
|
34
|
+
* awardKind: "mastered",
|
|
35
|
+
* awardDate: "2022-01-01T23:48:04+00:00",
|
|
36
|
+
* gameId: 14_284,
|
|
37
|
+
* gameTitle: "Batman Returns",
|
|
38
|
+
* consoleId: 15,
|
|
39
|
+
* consoleName: "Game Gear",
|
|
40
|
+
* },
|
|
41
|
+
* ],
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const getRecentGameAwards: (authorization: AuthObject, payload?: Partial<{
|
|
46
|
+
startDate: string;
|
|
47
|
+
offset: number;
|
|
48
|
+
count: number;
|
|
49
|
+
desiredAwardKinds: AwardKind[];
|
|
50
|
+
}>) => Promise<RecentGameAwards>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/feed/index.d.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AwardKind } from "../../utils/public";
|
|
2
|
+
export interface GetRecentGameAwardsResponse {
|
|
3
|
+
Count: number;
|
|
4
|
+
Total: number;
|
|
5
|
+
Results: Array<{
|
|
6
|
+
User: string;
|
|
7
|
+
AwardKind: AwardKind;
|
|
8
|
+
AwardDate: string;
|
|
9
|
+
GameID: number;
|
|
10
|
+
GameTitle: string;
|
|
11
|
+
ConsoleID: number;
|
|
12
|
+
ConsoleName: string;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
@@ -3,8 +3,10 @@ export * from "./claim-set-type.enum";
|
|
|
3
3
|
export * from "./claim-status.enum";
|
|
4
4
|
export * from "./claim-type.enum";
|
|
5
5
|
export * from "./get-achievement-of-the-week-response.model";
|
|
6
|
+
export * from "./get-recent-game-awards-response.model";
|
|
6
7
|
export * from "./get-set-claims-response.model";
|
|
7
8
|
export * from "./get-top-ten-users-response.model";
|
|
9
|
+
export * from "./recent-game-awards.model";
|
|
8
10
|
export * from "./set-claim.model";
|
|
9
11
|
export * from "./top-ten-users.model";
|
|
10
12
|
export * from "./top-ten-users-entity.model";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { AwardKind } from "../../utils/public";
|
|
2
|
+
export interface RecentGameAwards {
|
|
3
|
+
count: number;
|
|
4
|
+
total: number;
|
|
5
|
+
results: Array<{
|
|
6
|
+
user: string;
|
|
7
|
+
awardKind: AwardKind;
|
|
8
|
+
awardDate: string;
|
|
9
|
+
gameId: number;
|
|
10
|
+
gameTitle: string;
|
|
11
|
+
consoleId: number;
|
|
12
|
+
consoleName: string;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ID } from "../utils/internal";
|
|
2
|
+
import type { AuthObject } from "../utils/public";
|
|
3
|
+
import type { GameHashes } from "./models";
|
|
4
|
+
/**
|
|
5
|
+
* A call to this function will retrieve a list of hashes linked to a game.
|
|
6
|
+
*
|
|
7
|
+
* @param authorization An object containing your username and webApiKey.
|
|
8
|
+
* This can be constructed with `buildAuthorization()`.
|
|
9
|
+
*
|
|
10
|
+
* @param payload.gameId The unique game ID. If you are unsure, open the
|
|
11
|
+
* game's page on the RetroAchievements.org website. For example, Dragster's
|
|
12
|
+
* URL is https://retroachievements.org/game/14402. We can see from the
|
|
13
|
+
* URL that the game ID is "14402".
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```
|
|
17
|
+
* const game = await getGameHashes(
|
|
18
|
+
* authorization,
|
|
19
|
+
* { gameId: 14402 }
|
|
20
|
+
* );
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @returns An object containing a list of game hashes.
|
|
24
|
+
* ```json
|
|
25
|
+
* {
|
|
26
|
+
* "Results": [
|
|
27
|
+
* {
|
|
28
|
+
* "MD5": "1b1d9ac862c387367e904036114c4825",
|
|
29
|
+
* "Name": "Sonic The Hedgehog (USA, Europe) (Ru) (NewGame).md",
|
|
30
|
+
* "Labels": ["nointro", "rapatches"],
|
|
31
|
+
* "PatchUrl": "https://github.com/RetroAchievements/RAPatches/raw/main/MD/Translation/Russian/1-Sonic1-Russian.zip"
|
|
32
|
+
* },
|
|
33
|
+
* {
|
|
34
|
+
* "MD5": "1bc674be034e43c96b86487ac69d9293",
|
|
35
|
+
* "Name": "Sonic The Hedgehog (USA, Europe).md",
|
|
36
|
+
* "Labels": ["nointro"],
|
|
37
|
+
* "PatchUrl": null
|
|
38
|
+
* }
|
|
39
|
+
* ]
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare const getGameHashes: (authorization: AuthObject, payload: {
|
|
44
|
+
gameId: ID;
|
|
45
|
+
}) => Promise<GameHashes>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/game/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./getAchievementCount";
|
|
|
2
2
|
export * from "./getAchievementDistribution";
|
|
3
3
|
export * from "./getGame";
|
|
4
4
|
export * from "./getGameExtended";
|
|
5
|
+
export * from "./getGameHashes";
|
|
5
6
|
export * from "./getGameRankAndScore";
|
|
6
7
|
export * from "./getGameRating";
|
|
7
8
|
export * from "./models";
|
|
@@ -4,11 +4,13 @@ export * from "./game.model";
|
|
|
4
4
|
export * from "./game-extended.model";
|
|
5
5
|
export * from "./game-extended-achievement-entity.model";
|
|
6
6
|
export * from "./game-extended-claim-entity.model";
|
|
7
|
+
export * from "./game-hashes.model";
|
|
7
8
|
export * from "./game-rank-and-score-entity.model";
|
|
8
9
|
export * from "./game-rating.model";
|
|
9
10
|
export * from "./get-achievement-count-response.model";
|
|
10
11
|
export * from "./get-achievement-distribution-response.model";
|
|
11
12
|
export * from "./get-game-extended-response.model";
|
|
13
|
+
export * from "./get-game-hashes-response.model";
|
|
12
14
|
export * from "./get-game-rank-and-score-response.model";
|
|
13
15
|
export * from "./get-game-rating-response.model";
|
|
14
16
|
export * from "./get-game-response.model";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { GameExtended, GameExtendedAchievementEntity } from "../../game/models";
|
|
2
|
+
import type { AwardKind } from "../../utils/public";
|
|
2
3
|
export type GameExtendedAchievementEntityWithUserProgress = GameExtendedAchievementEntity & {
|
|
3
4
|
dateEarned: string;
|
|
4
5
|
dateEarnedHardcore: string;
|
|
@@ -9,6 +10,6 @@ export interface GameInfoAndUserProgress extends GameExtended {
|
|
|
9
10
|
numAwardedToUserHardcore: number;
|
|
10
11
|
userCompletion: string;
|
|
11
12
|
userCompletionHardcore: string;
|
|
12
|
-
highestAwardKind?:
|
|
13
|
+
highestAwardKind?: AwardKind | null;
|
|
13
14
|
highestAwardDate?: string;
|
|
14
15
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { GameExtendedRawAchievementEntity, GetGameExtendedResponse } from "../../game/models";
|
|
2
|
+
import type { AwardKind } from "../../utils/public";
|
|
2
3
|
type GetGameExtendedResponseWithoutClaims = Omit<GetGameExtendedResponse, "Claims">;
|
|
3
4
|
type GameExtendedRawAchievementEntityWithUserProgress = GameExtendedRawAchievementEntity & {
|
|
4
5
|
DateEarned: string;
|
|
@@ -10,7 +11,7 @@ export interface GetGameInfoAndUserProgressResponse extends GetGameExtendedRespo
|
|
|
10
11
|
NumAwardedToUserHardcore: number;
|
|
11
12
|
UserCompletion: string;
|
|
12
13
|
UserCompletionHardcore: string;
|
|
13
|
-
HighestAwardKind?:
|
|
14
|
+
HighestAwardKind?: AwardKind | null;
|
|
14
15
|
HighestAwardDate?: string;
|
|
15
16
|
}
|
|
16
17
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AwardKind } from "../../utils/public";
|
|
1
2
|
interface RawUserCompletionProgressEntity {
|
|
2
3
|
GameID: number;
|
|
3
4
|
Title: string;
|
|
@@ -8,7 +9,7 @@ interface RawUserCompletionProgressEntity {
|
|
|
8
9
|
NumAwarded: number;
|
|
9
10
|
NumAwardedHardcore: number;
|
|
10
11
|
MostRecentAwardedDate?: string;
|
|
11
|
-
HighestAwardKind?:
|
|
12
|
+
HighestAwardKind?: AwardKind | null;
|
|
12
13
|
HighestAwardDate?: string | null;
|
|
13
14
|
}
|
|
14
15
|
export interface GetUserCompletionProgressResponse {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AwardKind } from "../../utils/public";
|
|
1
2
|
export interface UserCompletionProgressEntity {
|
|
2
3
|
gameId: number;
|
|
3
4
|
title: string;
|
|
@@ -8,6 +9,6 @@ export interface UserCompletionProgressEntity {
|
|
|
8
9
|
numAwarded: number;
|
|
9
10
|
numAwardedHardcore: number;
|
|
10
11
|
mostRecentAwardedDate?: string;
|
|
11
|
-
highestAwardKind?:
|
|
12
|
+
highestAwardKind?: AwardKind | null;
|
|
12
13
|
highestAwardDate?: string;
|
|
13
14
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type AwardKind = "beaten-softcore" | "beaten-hardcore" | "completed" | "mastered";
|
package/package.json
CHANGED
|
@@ -45,6 +45,7 @@ describe("Function: getAchievementUnlocks", () => {
|
|
|
45
45
|
{
|
|
46
46
|
User: "Tiotroll2022",
|
|
47
47
|
RAPoints: "348",
|
|
48
|
+
RASoftcorePoints: "363",
|
|
48
49
|
DateAwarded: "2023-01-29 21:45:41",
|
|
49
50
|
HardcoreMode: "0",
|
|
50
51
|
},
|
|
@@ -91,6 +92,7 @@ describe("Function: getAchievementUnlocks", () => {
|
|
|
91
92
|
{
|
|
92
93
|
user: "Tiotroll2022",
|
|
93
94
|
raPoints: 348,
|
|
95
|
+
raSoftcorePoints: 363,
|
|
94
96
|
dateAwarded: "2023-01-29 21:45:41",
|
|
95
97
|
hardcoreMode: false,
|
|
96
98
|
},
|
|
@@ -75,7 +75,13 @@ export const getAchievementUnlocks = async (
|
|
|
75
75
|
const rawResponse = await call<GetAchievementUnlocksResponse>({ url });
|
|
76
76
|
|
|
77
77
|
return serializeProperties(rawResponse, {
|
|
78
|
-
shouldCastToNumbers: [
|
|
78
|
+
shouldCastToNumbers: [
|
|
79
|
+
"ID",
|
|
80
|
+
"Points",
|
|
81
|
+
"TrueRatio",
|
|
82
|
+
"RAPoints",
|
|
83
|
+
"RASoftcorePoints",
|
|
84
|
+
],
|
|
79
85
|
shouldMapToBooleans: ["HardcoreMode"],
|
|
80
86
|
});
|
|
81
87
|
};
|
|
@@ -62,7 +62,10 @@ describe("Function: getConsoleIds", () => {
|
|
|
62
62
|
);
|
|
63
63
|
|
|
64
64
|
// ACT
|
|
65
|
-
const response = await getConsoleIds(authorization
|
|
65
|
+
const response = await getConsoleIds(authorization, {
|
|
66
|
+
shouldOnlyRetrieveActiveSystems: true,
|
|
67
|
+
shouldOnlyRetrieveGameSystems: true,
|
|
68
|
+
});
|
|
66
69
|
|
|
67
70
|
// ASSERT
|
|
68
71
|
const expectedResponse: FetchedSystem[] = [
|
|
@@ -53,6 +53,7 @@ describe("Function: getAchievementOfTheWeek", () => {
|
|
|
53
53
|
{
|
|
54
54
|
User: "Tirbaba2",
|
|
55
55
|
RAPoints: "72",
|
|
56
|
+
RASoftcorePoints: "72",
|
|
56
57
|
DateAwarded: "2022-10-10 01:42:19",
|
|
57
58
|
HardcoreMode: "1",
|
|
58
59
|
},
|
|
@@ -91,6 +92,7 @@ describe("Function: getAchievementOfTheWeek", () => {
|
|
|
91
92
|
{
|
|
92
93
|
user: "Tirbaba2",
|
|
93
94
|
raPoints: 72,
|
|
95
|
+
raSoftcorePoints: 72,
|
|
94
96
|
dateAwarded: "2022-10-10 01:42:19",
|
|
95
97
|
hardcoreMode: true,
|
|
96
98
|
},
|
|
@@ -131,6 +133,7 @@ describe("Function: getAchievementOfTheWeek", () => {
|
|
|
131
133
|
{
|
|
132
134
|
User: "Tirbaba2",
|
|
133
135
|
RAPoints: "72",
|
|
136
|
+
RASoftcorePoints: "72",
|
|
134
137
|
DateAwarded: "2022-10-10 01:42:19",
|
|
135
138
|
HardcoreMode: "0",
|
|
136
139
|
},
|
|
@@ -169,6 +172,7 @@ describe("Function: getAchievementOfTheWeek", () => {
|
|
|
169
172
|
{
|
|
170
173
|
user: "Tirbaba2",
|
|
171
174
|
raPoints: 72,
|
|
175
|
+
raSoftcorePoints: 72,
|
|
172
176
|
dateAwarded: "2022-10-10 01:42:19",
|
|
173
177
|
hardcoreMode: false,
|
|
174
178
|
},
|
|
@@ -48,7 +48,8 @@ import type {
|
|
|
48
48
|
* unlocks: [
|
|
49
49
|
* {
|
|
50
50
|
* user: "Tirbaba2",
|
|
51
|
-
*
|
|
51
|
+
* raPoints: "72",
|
|
52
|
+
* raSoftcorePoints: "72",
|
|
52
53
|
* dateAwarded: "2022-10-10 01:42:19",
|
|
53
54
|
* hardcoreMode: "1"
|
|
54
55
|
* }
|
|
@@ -75,6 +76,7 @@ export const getAchievementOfTheWeek = async (
|
|
|
75
76
|
"TrueRatio",
|
|
76
77
|
"TotalPlayers",
|
|
77
78
|
"RAPoints",
|
|
79
|
+
"RASoftcorePoints",
|
|
78
80
|
"UnlocksCount",
|
|
79
81
|
],
|
|
80
82
|
shouldMapToBooleans: ["HardcoreMode"],
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { http, HttpResponse } from "msw";
|
|
2
|
+
import { setupServer } from "msw/node";
|
|
3
|
+
|
|
4
|
+
import { apiBaseUrl } from "../utils/internal";
|
|
5
|
+
import { buildAuthorization } from "../utils/public";
|
|
6
|
+
import { getRecentGameAwards } from "./getRecentGameAwards";
|
|
7
|
+
import type { GetRecentGameAwardsResponse, RecentGameAwards } from "./models";
|
|
8
|
+
|
|
9
|
+
const server = setupServer();
|
|
10
|
+
|
|
11
|
+
describe("Function: getRecentGameAwards", () => {
|
|
12
|
+
// MSW Setup
|
|
13
|
+
beforeAll(() => server.listen());
|
|
14
|
+
afterEach(() => server.resetHandlers());
|
|
15
|
+
afterAll(() => server.close());
|
|
16
|
+
|
|
17
|
+
it("is defined #sanity", () => {
|
|
18
|
+
// ASSERT
|
|
19
|
+
expect(getRecentGameAwards).toBeDefined();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("retrieves metadata about all recently-earned game awards on the site", async () => {
|
|
23
|
+
// ARRANGE
|
|
24
|
+
const authorization = buildAuthorization({
|
|
25
|
+
username: "mockUserName",
|
|
26
|
+
webApiKey: "mockWebApiKey",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const mockResponse: GetRecentGameAwardsResponse = {
|
|
30
|
+
Count: 1,
|
|
31
|
+
Total: 1,
|
|
32
|
+
Results: [
|
|
33
|
+
{
|
|
34
|
+
User: "renanbrj",
|
|
35
|
+
AwardKind: "mastered",
|
|
36
|
+
AwardDate: "2022-01-01T23:48:04+00:00",
|
|
37
|
+
GameID: 14_284,
|
|
38
|
+
GameTitle: "Batman Returns",
|
|
39
|
+
ConsoleID: 15,
|
|
40
|
+
ConsoleName: "Game Gear",
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
server.use(
|
|
46
|
+
http.get(`${apiBaseUrl}/API_GetRecentGameAwards.php`, () =>
|
|
47
|
+
HttpResponse.json(mockResponse)
|
|
48
|
+
)
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
// ACT
|
|
52
|
+
const response = await getRecentGameAwards(authorization, {
|
|
53
|
+
startDate: "2025-01-05",
|
|
54
|
+
offset: 10,
|
|
55
|
+
count: 10,
|
|
56
|
+
desiredAwardKinds: ["completed"],
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const expectedResponse: RecentGameAwards = {
|
|
60
|
+
count: 1,
|
|
61
|
+
total: 1,
|
|
62
|
+
results: [
|
|
63
|
+
{
|
|
64
|
+
user: "renanbrj",
|
|
65
|
+
awardKind: "mastered",
|
|
66
|
+
awardDate: "2022-01-01T23:48:04+00:00",
|
|
67
|
+
gameId: 14_284,
|
|
68
|
+
gameTitle: "Batman Returns",
|
|
69
|
+
consoleId: 15,
|
|
70
|
+
consoleName: "Game Gear",
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// ASSERT
|
|
76
|
+
expect(response).toEqual(expectedResponse);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
apiBaseUrl,
|
|
3
|
+
buildRequestUrl,
|
|
4
|
+
call,
|
|
5
|
+
serializeProperties,
|
|
6
|
+
} from "../utils/internal";
|
|
7
|
+
import type { AuthObject, AwardKind } from "../utils/public";
|
|
8
|
+
import type { GetRecentGameAwardsResponse, RecentGameAwards } from "./models";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A call to this function will retrieve all recently granted game
|
|
12
|
+
* awards across the site's userbase.
|
|
13
|
+
*
|
|
14
|
+
* @param authorization An object containing your username and webApiKey.
|
|
15
|
+
* This can be constructed with `buildAuthorization()`.
|
|
16
|
+
*
|
|
17
|
+
* @param payload.startDate The date to fetch awards from.
|
|
18
|
+
*
|
|
19
|
+
* @param payload.offset Optional. Defaults to 0.
|
|
20
|
+
*
|
|
21
|
+
* @param payload.count Optional. Defaults to 25.
|
|
22
|
+
*
|
|
23
|
+
* @param payload.desiredAwardKinds Optional. Defaults to all. Accepts "beaten-softcore", "beaten-hardcore", "completed", and/or "mastered".
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```
|
|
27
|
+
* const recentGameAwards = await getRecentGameAwards(
|
|
28
|
+
* authorization,
|
|
29
|
+
* );
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @returns An object containing metadata about all recently granted game
|
|
33
|
+
* awards across the site's userbase
|
|
34
|
+
* ```
|
|
35
|
+
* {
|
|
36
|
+
* count: 1,
|
|
37
|
+
* total: 1,
|
|
38
|
+
* results: [
|
|
39
|
+
* {
|
|
40
|
+
* user: "renanbrj",
|
|
41
|
+
* awardKind: "mastered",
|
|
42
|
+
* awardDate: "2022-01-01T23:48:04+00:00",
|
|
43
|
+
* gameId: 14_284,
|
|
44
|
+
* gameTitle: "Batman Returns",
|
|
45
|
+
* consoleId: 15,
|
|
46
|
+
* consoleName: "Game Gear",
|
|
47
|
+
* },
|
|
48
|
+
* ],
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export const getRecentGameAwards = async (
|
|
53
|
+
authorization: AuthObject,
|
|
54
|
+
payload?: Partial<{
|
|
55
|
+
startDate: string;
|
|
56
|
+
offset: number;
|
|
57
|
+
count: number;
|
|
58
|
+
desiredAwardKinds: AwardKind[];
|
|
59
|
+
}>
|
|
60
|
+
): Promise<RecentGameAwards> => {
|
|
61
|
+
const queryParams: Record<string, any> = {};
|
|
62
|
+
if (payload?.startDate) {
|
|
63
|
+
queryParams.d = payload.startDate;
|
|
64
|
+
}
|
|
65
|
+
if (payload?.offset) {
|
|
66
|
+
queryParams.o = payload.offset;
|
|
67
|
+
}
|
|
68
|
+
if (payload?.count) {
|
|
69
|
+
queryParams.c = payload.count;
|
|
70
|
+
}
|
|
71
|
+
if (payload?.desiredAwardKinds) {
|
|
72
|
+
queryParams.k = payload.desiredAwardKinds.join(",");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const url = buildRequestUrl(
|
|
76
|
+
apiBaseUrl,
|
|
77
|
+
"/API_GetRecentGameAwards.php",
|
|
78
|
+
authorization,
|
|
79
|
+
queryParams
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const rawResponse = await call<GetRecentGameAwardsResponse>({ url });
|
|
83
|
+
|
|
84
|
+
return serializeProperties(rawResponse);
|
|
85
|
+
};
|
package/src/feed/index.ts
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AwardKind } from "../../utils/public";
|
|
2
|
+
|
|
3
|
+
export interface GetRecentGameAwardsResponse {
|
|
4
|
+
Count: number;
|
|
5
|
+
Total: number;
|
|
6
|
+
Results: Array<{
|
|
7
|
+
User: string;
|
|
8
|
+
AwardKind: AwardKind;
|
|
9
|
+
AwardDate: string;
|
|
10
|
+
GameID: number;
|
|
11
|
+
GameTitle: string;
|
|
12
|
+
ConsoleID: number;
|
|
13
|
+
ConsoleName: string;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
package/src/feed/models/index.ts
CHANGED
|
@@ -3,8 +3,10 @@ export * from "./claim-set-type.enum";
|
|
|
3
3
|
export * from "./claim-status.enum";
|
|
4
4
|
export * from "./claim-type.enum";
|
|
5
5
|
export * from "./get-achievement-of-the-week-response.model";
|
|
6
|
+
export * from "./get-recent-game-awards-response.model";
|
|
6
7
|
export * from "./get-set-claims-response.model";
|
|
7
8
|
export * from "./get-top-ten-users-response.model";
|
|
9
|
+
export * from "./recent-game-awards.model";
|
|
8
10
|
export * from "./set-claim.model";
|
|
9
11
|
export * from "./top-ten-users.model";
|
|
10
12
|
export * from "./top-ten-users-entity.model";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AwardKind } from "../../utils/public";
|
|
2
|
+
|
|
3
|
+
export interface RecentGameAwards {
|
|
4
|
+
count: number;
|
|
5
|
+
total: number;
|
|
6
|
+
results: Array<{
|
|
7
|
+
user: string;
|
|
8
|
+
awardKind: AwardKind;
|
|
9
|
+
awardDate: string;
|
|
10
|
+
gameId: number;
|
|
11
|
+
gameTitle: string;
|
|
12
|
+
consoleId: number;
|
|
13
|
+
consoleName: string;
|
|
14
|
+
}>;
|
|
15
|
+
}
|