Skip to content

Commit d6db479

Browse files
committed
add getTweetResultByRestId
Signed-off-by: ふぁ <yuki@yuki0311.com>
1 parent 890a885 commit d6db479

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

twitter-openapi-typescript/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

twitter-openapi-typescript/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"main": "./dist/src/index.js",
2323
"typings": "./dist/src/index.d.ts",
2424
"dependencies": {
25-
"twitter-openapi-typescript-generated": "^0.0.9"
25+
"twitter-openapi-typescript-generated": "^0.0.10"
2626
},
2727
"devDependencies": {
2828
"@types/jest": "^28.1.8",
@@ -42,4 +42,4 @@
4242
"ts-jest": "^28.0.0",
4343
"typescript": "^5.1"
4444
}
45-
}
45+
}

twitter-openapi-typescript/src/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export type TwitterOpenApiCookie = {
2828
};
2929

3030
export class TwitterOpenApi {
31-
static hash = '2d477a0fb84d249a30b5af535b467efc25b34923';
31+
static hash = '591bddfa4707b3c01a0b1ca081226e7c6ff230f8';
3232
static url = `https://raw.githubusercontent.com/fa0311/twitter-openapi/${this.hash}/src/config/placeholder.json`;
3333
static twitter = 'https://twitter.com/home';
3434

twitter-openapi-typescript/src/apis/defaultApi.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import * as i from 'twitter-openapi-typescript-generated';
2-
import { buildHeader, errorCheck, getKwargs } from '@/utils';
3-
import { RequestParam, DefaultFlag, TwitterApiUtilsResponse } from '@/models';
2+
import { buildHeader, buildTweetApiUtils, errorCheck, getKwargs } from '@/utils';
3+
import { RequestParam, DefaultFlag, TwitterApiUtilsResponse, TweetApiUtilsData } from '@/models';
44

55
export type ProfileSpotlightsQueryParam = {
66
screenName: string;
77
extraParam?: { [key: string]: any };
88
};
99

10+
export type TweetResultByRestIdParam = {
11+
tweetId: string;
12+
extraParam?: { [key: string]: any };
13+
};
14+
1015
export class DefaultApiUtils {
1116
api: i.DefaultApi;
1217
flag: DefaultFlag;
@@ -45,4 +50,19 @@ export class DefaultApiUtils {
4550

4651
return response;
4752
}
53+
54+
async getTweetResultByRestId(param: TweetResultByRestIdParam): Promise<TwitterApiUtilsResponse<TweetApiUtilsData>> {
55+
const args = {
56+
tweetId: param.tweetId,
57+
...param.extraParam,
58+
};
59+
const response = await this.request({
60+
key: 'TweetResultByRestId',
61+
apiFn: this.api.getTweetResultByRestIdRaw,
62+
convertFn: (value) => buildTweetApiUtils({ result: value.data.tweetResult }),
63+
param: args,
64+
});
65+
66+
return response;
67+
}
4868
}

twitter-openapi-typescript/test/api/defaultApi.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getClient, logger } from '@test/init';
2+
import { printTweet } from '@test/util';
23

34
test('getProfileSpotlightsQuery', async () => {
45
logger.log('getProfileSpotlightsQuery');
@@ -10,3 +11,11 @@ test('getProfileSpotlightsQuery', async () => {
1011
logger.log('┄'.repeat(50));
1112
expect(response.raw.response.ok).toBe(true);
1213
});
14+
15+
test('getTweetResultByRestId', async () => {
16+
logger.log('getTweetResultByRestId');
17+
const client = await getClient();
18+
const response = await client.getDefaultApi().getTweetResultByRestId({ tweetId: '1349129669258448897' });
19+
printTweet(response.data);
20+
expect(response.raw.response.ok).toBe(true);
21+
});

0 commit comments

Comments
 (0)