Skip to content

Commit d5c16f6

Browse files
committed
add default api
Signed-off-by: ふぁ <yuki@yuki0311.com>
1 parent f2ccc1a commit d5c16f6

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed
Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import * as i from 'twitter-openapi-typescript-generated';
22
import { DefaultFlag } from '@/types';
3+
import { RequestParamDefault } from '@/models';
34

45
export type ProfileSpotlightsQueryParam = {
56
screenName: string;
6-
extraParam: {
7-
[key: string]: any;
8-
};
7+
extraParam?: { [key: string]: any };
98
};
109

1110
export class DefaultApiUtils {
@@ -16,4 +15,27 @@ export class DefaultApiUtils {
1615
this.api = api;
1716
this.flag = flag;
1817
}
18+
19+
async request<T>(param: RequestParamDefault<T>): Promise<T> {
20+
const apiFn: typeof param.apiFn = param.apiFn.bind(this.api);
21+
const response = await apiFn({
22+
queryId: this.flag[param.key]['queryId'],
23+
variables: JSON.stringify({ ...this.flag[param.key]['variables'], ...param }),
24+
features: JSON.stringify(this.flag[param.key]['features']),
25+
});
26+
return response.value() as T;
27+
}
28+
29+
async gettProfileSpotlightsQuery(param: ProfileSpotlightsQueryParam): Promise<i.UserResultByScreenName> {
30+
const args = {
31+
screenName: param.screenName,
32+
...param.extraParam,
33+
};
34+
const response = this.request({
35+
key: 'ProfileSpotlightsQuery',
36+
apiFn: this.api.getProfileSpotlightsQueryRaw,
37+
param: args,
38+
});
39+
return (await response).data.userResultByScreenName;
40+
}
1941
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { getClient, logger } from '@test/init';
2+
import { printTweet } from '@test/util';
3+
4+
test('gettProfileSpotlightsQuery', async () => {
5+
logger.log('gettProfileSpotlightsQuery');
6+
const client = await getClient();
7+
const response = await client.getDefaultApi().gettProfileSpotlightsQuery({ screenName: 'elonmusk' });
8+
const legacy = response.result.legacy;
9+
logger.log(legacy.screenName);
10+
logger.log(`followedBy: ${legacy.followedBy} following: ${legacy.following}`);
11+
logger.log('┄'.repeat(50));
12+
expect(0).toBe(0);
13+
});

0 commit comments

Comments
 (0)