@retroachievements/api 2.9.1 → 2.10.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 +2 -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/user/getUserSetRequests.d.ts +54 -0
- package/dist/user/getUserSetRequests.test.d.ts +1 -0
- package/dist/user/getUsersFollowingMe.d.ts +46 -0
- package/dist/user/getUsersFollowingMe.test.d.ts +1 -0
- package/dist/user/index.d.ts +2 -0
- package/dist/user/models/get-user-set-requests-response.model.d.ts +11 -0
- package/dist/user/models/get-users-following-me-response.model.d.ts +11 -0
- package/dist/user/models/index.d.ts +5 -0
- package/dist/user/models/request-list-type.enum.d.ts +4 -0
- package/dist/user/models/user-set-requests.model.d.ts +11 -0
- package/dist/user/models/users-following-me.model.d.ts +11 -0
- package/package.json +1 -1
- package/src/user/getUserSetRequests.test.ts +149 -0
- package/src/user/getUserSetRequests.ts +92 -0
- package/src/user/getUsersFollowingMe.test.ts +124 -0
- package/src/user/getUsersFollowingMe.ts +75 -0
- package/src/user/index.ts +2 -0
- package/src/user/models/get-user-set-requests-response.model.ts +11 -0
- package/src/user/models/get-users-following-me-response.model.ts +11 -0
- package/src/user/models/index.ts +5 -0
- package/src/user/models/request-list-type.enum.ts +4 -0
- package/src/user/models/user-set-requests.model.ts +11 -0
- package/src/user/models/users-following-me.model.ts +11 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { AuthObject } from "../utils/public";
|
|
2
|
+
import type { RequestListType, UserSetRequests } from "./models";
|
|
3
|
+
/**
|
|
4
|
+
* A call to this function will retrieve a given user's set requests.
|
|
5
|
+
*
|
|
6
|
+
* @param authorization An object containing your username and webApiKey.
|
|
7
|
+
* This can be constructed with `buildAuthorization()`.
|
|
8
|
+
*
|
|
9
|
+
* @param payload.username The user for which to retrieve the set requests
|
|
10
|
+
* for.
|
|
11
|
+
*
|
|
12
|
+
* @param payload.requestListType An optional parameter to filter set requests
|
|
13
|
+
* by their current status. If omitted, the API will return only active
|
|
14
|
+
* requests.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```
|
|
18
|
+
* const userSetRequests = await getUserSetRequests(authorization, {
|
|
19
|
+
* username: "ExampleUser"
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @returns An object containing a list of requested sets that the
|
|
24
|
+
* given user made.
|
|
25
|
+
* ```json
|
|
26
|
+
* {
|
|
27
|
+
* "requestedSets": [
|
|
28
|
+
* {
|
|
29
|
+
* "gameId": 8149,
|
|
30
|
+
* "title": "Example Set 1",
|
|
31
|
+
* "consoleId": 0,
|
|
32
|
+
* "consoleName": "Example Console",
|
|
33
|
+
* "imageIcon": "/Images/000001.png"
|
|
34
|
+
* },
|
|
35
|
+
* {
|
|
36
|
+
* "gameId": 9001,
|
|
37
|
+
* "title": "Example Set 2",
|
|
38
|
+
* "consoleId": 2,
|
|
39
|
+
* "consoleName": "Example Console 2",
|
|
40
|
+
* "imageIcon": "/Images/000002.png"
|
|
41
|
+
* }
|
|
42
|
+
* ],
|
|
43
|
+
* "totalRequests": 5,
|
|
44
|
+
* "pointsForNext": 5000
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @throws If the API was given invalid parameters (422) or if the
|
|
49
|
+
* API is currently down (503).
|
|
50
|
+
*/
|
|
51
|
+
export declare const getUserSetRequests: (authorization: AuthObject, payload: {
|
|
52
|
+
username: string;
|
|
53
|
+
requestListType?: RequestListType;
|
|
54
|
+
}) => Promise<UserSetRequests>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { AuthObject } from "../utils/public";
|
|
2
|
+
import type { UsersFollowingMe } from "./models";
|
|
3
|
+
/**
|
|
4
|
+
* A call to this function will retrieve the list of users that are
|
|
5
|
+
* following the caller.
|
|
6
|
+
*
|
|
7
|
+
* @param authorization An object containing your username and webApiKey.
|
|
8
|
+
* This can be constructed with `buildAuthorization()`.
|
|
9
|
+
*
|
|
10
|
+
* @param payload.offset The number of entries to skip. The API will default
|
|
11
|
+
* to 0 if the parameter is not specified.
|
|
12
|
+
*
|
|
13
|
+
* @param payload.count The number of entries to return. The API will
|
|
14
|
+
* default to 100 if the parameter is not specified. The max number
|
|
15
|
+
* of entries that can be returned is 500.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```
|
|
19
|
+
* const usersFollowingMe = await getUsersFollowingMe(authorization);
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @returns An object containing a list of users that are following
|
|
23
|
+
* the caller.
|
|
24
|
+
* ```json
|
|
25
|
+
* {
|
|
26
|
+
* "count": 1,
|
|
27
|
+
* "total": 1,
|
|
28
|
+
* "results": [
|
|
29
|
+
* {
|
|
30
|
+
* "user": "Example",
|
|
31
|
+
* "ulid": "0123456789ABCDEFGHIJKLMNO",
|
|
32
|
+
* "points": 9001,
|
|
33
|
+
* "pointsSoftcore": 101,
|
|
34
|
+
* "amIFollowing": true
|
|
35
|
+
* }
|
|
36
|
+
* ]
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @throws If the API was given invalid parameters (422) or if the
|
|
41
|
+
* API is currently down (503).
|
|
42
|
+
*/
|
|
43
|
+
export declare const getUsersFollowingMe: (authorization: AuthObject, payload?: {
|
|
44
|
+
offset?: number;
|
|
45
|
+
count?: number;
|
|
46
|
+
}) => Promise<UsersFollowingMe>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/user/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export * from "./getUserProfile";
|
|
|
11
11
|
export * from "./getUserProgress";
|
|
12
12
|
export * from "./getUserRecentAchievements";
|
|
13
13
|
export * from "./getUserRecentlyPlayedGames";
|
|
14
|
+
export * from "./getUserSetRequests";
|
|
15
|
+
export * from "./getUsersFollowingMe";
|
|
14
16
|
export * from "./getUsersIFollow";
|
|
15
17
|
export * from "./getUserSummary";
|
|
16
18
|
export * from "./getUserWantToPlayList";
|
|
@@ -12,9 +12,12 @@ export * from "./get-user-profile-response.model";
|
|
|
12
12
|
export * from "./get-user-progress-response.model";
|
|
13
13
|
export * from "./get-user-recent-achievements-response.model";
|
|
14
14
|
export * from "./get-user-recently-played-games-response.model";
|
|
15
|
+
export * from "./get-user-set-requests-response.model";
|
|
15
16
|
export * from "./get-user-summary-response.model";
|
|
16
17
|
export * from "./get-user-want-to-play-list-response.model";
|
|
18
|
+
export * from "./get-users-following-me-response.model";
|
|
17
19
|
export * from "./get-users-i-follow-response.model";
|
|
20
|
+
export * from "./request-list-type.enum";
|
|
18
21
|
export * from "./user-awards.model";
|
|
19
22
|
export * from "./user-claims.model";
|
|
20
23
|
export * from "./user-claims-response.model";
|
|
@@ -27,6 +30,8 @@ export * from "./user-profile.model";
|
|
|
27
30
|
export * from "./user-progress.model";
|
|
28
31
|
export * from "./user-recent-achievement.model";
|
|
29
32
|
export * from "./user-recently-played-games.model";
|
|
33
|
+
export * from "./user-set-requests.model";
|
|
30
34
|
export * from "./user-summary.model";
|
|
31
35
|
export * from "./user-want-to-play-list.model";
|
|
36
|
+
export * from "./users-following-me.model";
|
|
32
37
|
export * from "./users-i-follow.model";
|
package/package.json
CHANGED
|
@@ -0,0 +1,149 @@
|
|
|
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 { getUserSetRequests } from "./getUserSetRequests";
|
|
7
|
+
import type { GetUserSetRequestsResponse, UserSetRequests } from "./models";
|
|
8
|
+
import { RequestListType } from "./models";
|
|
9
|
+
|
|
10
|
+
const server = setupServer();
|
|
11
|
+
|
|
12
|
+
describe("Function: getUserSetRequests", () => {
|
|
13
|
+
// MSW Setup
|
|
14
|
+
beforeAll(() => server.listen());
|
|
15
|
+
afterEach(() => server.resetHandlers());
|
|
16
|
+
afterAll(() => server.close());
|
|
17
|
+
|
|
18
|
+
it("is defined #sanity", () => {
|
|
19
|
+
// ASSERT
|
|
20
|
+
expect(getUserSetRequests).toBeDefined();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("using defaults, retrieves the list of set requests of the given user", async () => {
|
|
24
|
+
// ARRANGE
|
|
25
|
+
const authorization = buildAuthorization({
|
|
26
|
+
username: "mockUserName",
|
|
27
|
+
webApiKey: "mockWebApiKey",
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const mockResponse = mockGetUserSetRequestsResponse;
|
|
31
|
+
|
|
32
|
+
server.use(
|
|
33
|
+
http.get(`${apiBaseUrl}/API_GetUserSetRequests.php`, (info) => {
|
|
34
|
+
const url = new URL(info.request.url);
|
|
35
|
+
expect(url.searchParams.get("u")).toEqual(mockOtherUsername);
|
|
36
|
+
expect(url.searchParams.has("t")).toBeFalsy();
|
|
37
|
+
return HttpResponse.json(mockResponse);
|
|
38
|
+
})
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
// ACT
|
|
42
|
+
const response = await getUserSetRequests(authorization, {
|
|
43
|
+
username: mockOtherUsername,
|
|
44
|
+
});
|
|
45
|
+
expect(response).toEqual(mockUserSetRequestsValue);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it.each([
|
|
49
|
+
{ requestListType: RequestListType.ActiveRequests },
|
|
50
|
+
{ requestListType: RequestListType.AllRequests },
|
|
51
|
+
])(
|
|
52
|
+
"calls the 'User Set Requests' endpoint with a given request list type ($requestListType)",
|
|
53
|
+
async ({ requestListType: expectedRequestListType }) => {
|
|
54
|
+
// ARRANGE
|
|
55
|
+
const authorization = buildAuthorization({
|
|
56
|
+
username: "mockUserName",
|
|
57
|
+
webApiKey: "mockWebApiKey",
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
server.use(
|
|
61
|
+
http.get(`${apiBaseUrl}/API_GetUserSetRequests.php`, (info) => {
|
|
62
|
+
const url = new URL(info.request.url);
|
|
63
|
+
expect(url.searchParams.get("u")).toEqual(mockOtherUsername);
|
|
64
|
+
expect(url.searchParams.get("t")).toEqual(
|
|
65
|
+
String(expectedRequestListType)
|
|
66
|
+
);
|
|
67
|
+
return HttpResponse.json(mockGetUserSetRequestsResponse);
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// ACT
|
|
72
|
+
await getUserSetRequests(authorization, {
|
|
73
|
+
username: mockOtherUsername,
|
|
74
|
+
requestListType: expectedRequestListType,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
it.each([
|
|
80
|
+
{ status: 503, statusText: "The API is currently down" },
|
|
81
|
+
{ status: 422, statusText: "HTTP Error: Status 422 Unprocessable Entity" },
|
|
82
|
+
])(
|
|
83
|
+
"given the API returns a $status, throws an error",
|
|
84
|
+
async ({ status, statusText }) => {
|
|
85
|
+
// ARRANGE
|
|
86
|
+
const authorization = buildAuthorization({
|
|
87
|
+
username: "mockUserName",
|
|
88
|
+
webApiKey: "mockWebApiKey",
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const mockResponse = `<html><body>${statusText}</body></html>`;
|
|
92
|
+
|
|
93
|
+
server.use(
|
|
94
|
+
http.get(`${apiBaseUrl}/API_GetUserSetRequests.php`, () =>
|
|
95
|
+
HttpResponse.json(mockResponse, { status, statusText })
|
|
96
|
+
)
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// ASSERT
|
|
100
|
+
await expect(
|
|
101
|
+
getUserSetRequests(authorization, { username: mockOtherUsername })
|
|
102
|
+
).rejects.toThrow();
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const mockOtherUsername = "otherMockUser";
|
|
108
|
+
|
|
109
|
+
const mockGetUserSetRequestsResponse: GetUserSetRequestsResponse = {
|
|
110
|
+
RequestedSets: [
|
|
111
|
+
{
|
|
112
|
+
GameID: 8149,
|
|
113
|
+
Title: "Example Set 1",
|
|
114
|
+
ConsoleID: 0,
|
|
115
|
+
ConsoleName: "Example Console",
|
|
116
|
+
ImageIcon: "/Images/000001.png",
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
GameID: 9001,
|
|
120
|
+
Title: "Example Set 2",
|
|
121
|
+
ConsoleID: 2,
|
|
122
|
+
ConsoleName: "Example Console 2",
|
|
123
|
+
ImageIcon: "/Images/000002.png",
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
TotalRequests: 5,
|
|
127
|
+
PointsForNext: 5000,
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const mockUserSetRequestsValue: UserSetRequests = {
|
|
131
|
+
requestedSets: [
|
|
132
|
+
{
|
|
133
|
+
gameId: 8149,
|
|
134
|
+
title: "Example Set 1",
|
|
135
|
+
consoleId: 0,
|
|
136
|
+
consoleName: "Example Console",
|
|
137
|
+
imageIcon: "/Images/000001.png",
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
gameId: 9001,
|
|
141
|
+
title: "Example Set 2",
|
|
142
|
+
consoleId: 2,
|
|
143
|
+
consoleName: "Example Console 2",
|
|
144
|
+
imageIcon: "/Images/000002.png",
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
totalRequests: 5,
|
|
148
|
+
pointsForNext: 5000,
|
|
149
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
apiBaseUrl,
|
|
3
|
+
buildRequestUrl,
|
|
4
|
+
call,
|
|
5
|
+
serializeProperties,
|
|
6
|
+
} from "../utils/internal";
|
|
7
|
+
import type { AuthObject } from "../utils/public";
|
|
8
|
+
import type {
|
|
9
|
+
GetUserSetRequestsResponse,
|
|
10
|
+
RequestListType,
|
|
11
|
+
UserSetRequests,
|
|
12
|
+
} from "./models";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A call to this function will retrieve a given user's set requests.
|
|
16
|
+
*
|
|
17
|
+
* @param authorization An object containing your username and webApiKey.
|
|
18
|
+
* This can be constructed with `buildAuthorization()`.
|
|
19
|
+
*
|
|
20
|
+
* @param payload.username The user for which to retrieve the set requests
|
|
21
|
+
* for.
|
|
22
|
+
*
|
|
23
|
+
* @param payload.requestListType An optional parameter to filter set requests
|
|
24
|
+
* by their current status. If omitted, the API will return only active
|
|
25
|
+
* requests.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```
|
|
29
|
+
* const userSetRequests = await getUserSetRequests(authorization, {
|
|
30
|
+
* username: "ExampleUser"
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @returns An object containing a list of requested sets that the
|
|
35
|
+
* given user made.
|
|
36
|
+
* ```json
|
|
37
|
+
* {
|
|
38
|
+
* "requestedSets": [
|
|
39
|
+
* {
|
|
40
|
+
* "gameId": 8149,
|
|
41
|
+
* "title": "Example Set 1",
|
|
42
|
+
* "consoleId": 0,
|
|
43
|
+
* "consoleName": "Example Console",
|
|
44
|
+
* "imageIcon": "/Images/000001.png"
|
|
45
|
+
* },
|
|
46
|
+
* {
|
|
47
|
+
* "gameId": 9001,
|
|
48
|
+
* "title": "Example Set 2",
|
|
49
|
+
* "consoleId": 2,
|
|
50
|
+
* "consoleName": "Example Console 2",
|
|
51
|
+
* "imageIcon": "/Images/000002.png"
|
|
52
|
+
* }
|
|
53
|
+
* ],
|
|
54
|
+
* "totalRequests": 5,
|
|
55
|
+
* "pointsForNext": 5000
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @throws If the API was given invalid parameters (422) or if the
|
|
60
|
+
* API is currently down (503).
|
|
61
|
+
*/
|
|
62
|
+
export const getUserSetRequests = async (
|
|
63
|
+
authorization: AuthObject,
|
|
64
|
+
payload: { username: string; requestListType?: RequestListType }
|
|
65
|
+
): Promise<UserSetRequests> => {
|
|
66
|
+
const queryParams: Record<string, number | string> = {};
|
|
67
|
+
queryParams.u = payload.username;
|
|
68
|
+
if (
|
|
69
|
+
payload.requestListType !== null &&
|
|
70
|
+
payload.requestListType !== undefined
|
|
71
|
+
) {
|
|
72
|
+
queryParams.t = payload.requestListType;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const url = buildRequestUrl(
|
|
76
|
+
apiBaseUrl,
|
|
77
|
+
"/API_GetUserSetRequests.php",
|
|
78
|
+
authorization,
|
|
79
|
+
queryParams
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const rawResponse = await call<GetUserSetRequestsResponse>({ url });
|
|
83
|
+
|
|
84
|
+
return serializeProperties(rawResponse, {
|
|
85
|
+
shouldCastToNumbers: [
|
|
86
|
+
"GameID",
|
|
87
|
+
"ConsoleID",
|
|
88
|
+
"TotalRequests",
|
|
89
|
+
"PointsForNext",
|
|
90
|
+
],
|
|
91
|
+
});
|
|
92
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
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 { getUsersFollowingMe } from "./getUsersFollowingMe";
|
|
7
|
+
import type { GetUsersFollowingMeResponse, UsersFollowingMe } from "./models";
|
|
8
|
+
|
|
9
|
+
const server = setupServer();
|
|
10
|
+
|
|
11
|
+
describe("Function: getUsersFollowingMe", () => {
|
|
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(getUsersFollowingMe).toBeDefined();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("using defaults, retrieves the list of users that are following the caller", async () => {
|
|
23
|
+
// ARRANGE
|
|
24
|
+
const authorization = buildAuthorization({
|
|
25
|
+
username: "mockUserName",
|
|
26
|
+
webApiKey: "mockWebApiKey",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const mockResponse = mockGetUsersFollowingMeResponse;
|
|
30
|
+
|
|
31
|
+
server.use(
|
|
32
|
+
http.get(`${apiBaseUrl}/API_GetUsersFollowingMe.php`, (info) => {
|
|
33
|
+
const url = new URL(info.request.url);
|
|
34
|
+
expect(url.searchParams.has("c")).toBeFalsy();
|
|
35
|
+
expect(url.searchParams.has("o")).toBeFalsy();
|
|
36
|
+
return HttpResponse.json(mockResponse);
|
|
37
|
+
})
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
// ACT
|
|
41
|
+
const response = await getUsersFollowingMe(authorization);
|
|
42
|
+
expect(response).toEqual(mockUsersFollowingMeValue);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it.each([{ offset: 1, count: 1 }, { offset: 5 }, { count: 20 }])(
|
|
46
|
+
"calls the 'Users Following Me' endpoint with a given offset ($offset) and/or count ($count)",
|
|
47
|
+
async (mockPayload) => {
|
|
48
|
+
// ARRANGE
|
|
49
|
+
const authorization = buildAuthorization({
|
|
50
|
+
username: "mockUserName",
|
|
51
|
+
webApiKey: "mockWebApiKey",
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
server.use(
|
|
55
|
+
http.get(`${apiBaseUrl}/API_GetUsersFollowingMe.php`, (info) => {
|
|
56
|
+
const url = new URL(info.request.url);
|
|
57
|
+
const c = url.searchParams.get("c");
|
|
58
|
+
const o = url.searchParams.get("o");
|
|
59
|
+
expect(String(c)).toEqual(String(mockPayload.count ?? null));
|
|
60
|
+
expect(String(o)).toEqual(String(mockPayload.offset ?? null));
|
|
61
|
+
return HttpResponse.json(mockGetUsersFollowingMeResponse);
|
|
62
|
+
})
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
// ACT
|
|
66
|
+
await getUsersFollowingMe(authorization, mockPayload);
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
it.each([
|
|
71
|
+
{ status: 503, statusText: "The API is currently down" },
|
|
72
|
+
{ status: 422, statusText: "HTTP Error: Status 422 Unprocessable Entity" },
|
|
73
|
+
])(
|
|
74
|
+
"given the API returns a $status, throws an error",
|
|
75
|
+
async ({ status, statusText }) => {
|
|
76
|
+
// ARRANGE
|
|
77
|
+
const authorization = buildAuthorization({
|
|
78
|
+
username: "mockUserName",
|
|
79
|
+
webApiKey: "mockWebApiKey",
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const mockResponse = `<html><body>${statusText}</body></html>`;
|
|
83
|
+
|
|
84
|
+
server.use(
|
|
85
|
+
http.get(`${apiBaseUrl}/API_GetUsersFollowingMe.php`, () =>
|
|
86
|
+
HttpResponse.json(mockResponse, { status, statusText })
|
|
87
|
+
)
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
// ASSERT
|
|
91
|
+
await expect(
|
|
92
|
+
getUsersFollowingMe(authorization, { count: 0 })
|
|
93
|
+
).rejects.toThrow();
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const mockGetUsersFollowingMeResponse: GetUsersFollowingMeResponse = {
|
|
99
|
+
Count: 1,
|
|
100
|
+
Total: 1,
|
|
101
|
+
Results: [
|
|
102
|
+
{
|
|
103
|
+
User: "Example",
|
|
104
|
+
ULID: "0123456789ABCDEFGHIJKLMNO",
|
|
105
|
+
Points: 9001,
|
|
106
|
+
PointsSoftcore: 101,
|
|
107
|
+
AmIFollowing: true,
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const mockUsersFollowingMeValue: UsersFollowingMe = {
|
|
113
|
+
count: 1,
|
|
114
|
+
total: 1,
|
|
115
|
+
results: [
|
|
116
|
+
{
|
|
117
|
+
user: "Example",
|
|
118
|
+
ulid: "0123456789ABCDEFGHIJKLMNO",
|
|
119
|
+
points: 9001,
|
|
120
|
+
pointsSoftcore: 101,
|
|
121
|
+
amIFollowing: true,
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
apiBaseUrl,
|
|
3
|
+
buildRequestUrl,
|
|
4
|
+
call,
|
|
5
|
+
serializeProperties,
|
|
6
|
+
} from "../utils/internal";
|
|
7
|
+
import type { AuthObject } from "../utils/public";
|
|
8
|
+
import type { GetUsersFollowingMeResponse, UsersFollowingMe } from "./models";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A call to this function will retrieve the list of users that are
|
|
12
|
+
* following the caller.
|
|
13
|
+
*
|
|
14
|
+
* @param authorization An object containing your username and webApiKey.
|
|
15
|
+
* This can be constructed with `buildAuthorization()`.
|
|
16
|
+
*
|
|
17
|
+
* @param payload.offset The number of entries to skip. The API will default
|
|
18
|
+
* to 0 if the parameter is not specified.
|
|
19
|
+
*
|
|
20
|
+
* @param payload.count The number of entries to return. The API will
|
|
21
|
+
* default to 100 if the parameter is not specified. The max number
|
|
22
|
+
* of entries that can be returned is 500.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```
|
|
26
|
+
* const usersFollowingMe = await getUsersFollowingMe(authorization);
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @returns An object containing a list of users that are following
|
|
30
|
+
* the caller.
|
|
31
|
+
* ```json
|
|
32
|
+
* {
|
|
33
|
+
* "count": 1,
|
|
34
|
+
* "total": 1,
|
|
35
|
+
* "results": [
|
|
36
|
+
* {
|
|
37
|
+
* "user": "Example",
|
|
38
|
+
* "ulid": "0123456789ABCDEFGHIJKLMNO",
|
|
39
|
+
* "points": 9001,
|
|
40
|
+
* "pointsSoftcore": 101,
|
|
41
|
+
* "amIFollowing": true
|
|
42
|
+
* }
|
|
43
|
+
* ]
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @throws If the API was given invalid parameters (422) or if the
|
|
48
|
+
* API is currently down (503).
|
|
49
|
+
*/
|
|
50
|
+
export const getUsersFollowingMe = async (
|
|
51
|
+
authorization: AuthObject,
|
|
52
|
+
payload?: { offset?: number; count?: number }
|
|
53
|
+
): Promise<UsersFollowingMe> => {
|
|
54
|
+
const queryParams: Record<string, number> = {};
|
|
55
|
+
if (payload?.offset !== null && payload?.offset !== undefined) {
|
|
56
|
+
queryParams.o = payload.offset;
|
|
57
|
+
}
|
|
58
|
+
if (payload?.count !== null && payload?.count !== undefined) {
|
|
59
|
+
queryParams.c = payload.count;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const url = buildRequestUrl(
|
|
63
|
+
apiBaseUrl,
|
|
64
|
+
"/API_GetUsersFollowingMe.php",
|
|
65
|
+
authorization,
|
|
66
|
+
queryParams
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const rawResponse = await call<GetUsersFollowingMeResponse>({ url });
|
|
70
|
+
|
|
71
|
+
return serializeProperties(rawResponse, {
|
|
72
|
+
shouldCastToNumbers: ["Points", "PointsSoftcore"],
|
|
73
|
+
shouldMapToBooleans: ["AmIFollowing"],
|
|
74
|
+
});
|
|
75
|
+
};
|
package/src/user/index.ts
CHANGED
|
@@ -11,6 +11,8 @@ export * from "./getUserProfile";
|
|
|
11
11
|
export * from "./getUserProgress";
|
|
12
12
|
export * from "./getUserRecentAchievements";
|
|
13
13
|
export * from "./getUserRecentlyPlayedGames";
|
|
14
|
+
export * from "./getUserSetRequests";
|
|
15
|
+
export * from "./getUsersFollowingMe";
|
|
14
16
|
export * from "./getUsersIFollow";
|
|
15
17
|
export * from "./getUserSummary";
|
|
16
18
|
export * from "./getUserWantToPlayList";
|