twitter-openapi-typescript 0.0.43 → 0.0.45
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/dist/src/apis/defaultApi.d.ts.map +1 -1
- package/dist/src/apis/defaultApi.js +8 -9
- package/dist/src/apis/defaultApi.js.map +1 -1
- package/dist/src/apis/postApi.d.ts +2 -2
- package/dist/src/apis/postApi.d.ts.map +1 -1
- package/dist/src/apis/postApi.js +48 -56
- package/dist/src/apis/postApi.js.map +1 -1
- package/dist/src/apis/tweetApi.d.ts.map +1 -1
- package/dist/src/apis/tweetApi.js +16 -17
- package/dist/src/apis/tweetApi.js.map +1 -1
- package/dist/src/apis/userApi.d.ts.map +1 -1
- package/dist/src/apis/userApi.js +8 -9
- package/dist/src/apis/userApi.js.map +1 -1
- package/dist/src/apis/userListApi.d.ts.map +1 -1
- package/dist/src/apis/userListApi.js +11 -12
- package/dist/src/apis/userListApi.js.map +1 -1
- package/dist/src/apis/usersApi.d.ts.map +1 -1
- package/dist/src/apis/usersApi.js +7 -8
- package/dist/src/apis/usersApi.js.map +1 -1
- package/dist/src/models/utils.d.ts +1 -1
- package/dist/src/models/utils.d.ts.map +1 -1
- package/dist/src/utils/api.d.ts +1 -2
- package/dist/src/utils/api.d.ts.map +1 -1
- package/dist/src/utils/api.js +9 -16
- package/dist/src/utils/api.js.map +1 -1
- package/package.json +2 -2
- package/.prettierrc +0 -8
- package/.vscode/extensions.json +0 -8
- package/.vscode/settings.json +0 -21
- package/cookies.json +0 -170
- package/jest.config.js +0 -11
- package/src/api.ts +0 -222
- package/src/apis/defaultApi.ts +0 -72
- package/src/apis/index.ts +0 -10
- package/src/apis/initialStateApi.ts +0 -3
- package/src/apis/postApi.ts +0 -208
- package/src/apis/tweetApi.ts +0 -289
- package/src/apis/userApi.ts +0 -72
- package/src/apis/userListApi.ts +0 -173
- package/src/apis/usersApi.ts +0 -50
- package/src/apis/v11GetApi.ts +0 -14
- package/src/apis/v11PostApi.ts +0 -75
- package/src/apis/v20GetApi.ts +0 -14
- package/src/index.ts +0 -4
- package/src/models/flag.ts +0 -5
- package/src/models/header.ts +0 -14
- package/src/models/index.ts +0 -5
- package/src/models/response.ts +0 -11
- package/src/models/timeline.ts +0 -32
- package/src/models/utils.ts +0 -10
- package/src/utils/api.ts +0 -230
- package/src/utils/index.ts +0 -1
- package/test/api/auth.test.ts +0 -15
- package/test/api/defaultApi.test.ts +0 -21
- package/test/api/guest.test.ts +0 -10
- package/test/api/postApi.test.ts +0 -61
- package/test/api/tweetApi.test.ts +0 -82
- package/test/api/userApi.test.ts +0 -33
- package/test/api/userListApi.test.ts +0 -42
- package/test/api/usersApi.test.ts +0 -12
- package/test/api/v11PostApi.test.ts +0 -13
- package/test/init.ts +0 -50
- package/test/raw/tweet_api.test.ts +0 -12
- package/test/util.ts +0 -29
- package/tsconfig.build.json +0 -26
- package/tsconfig.json +0 -26
package/src/apis/tweetApi.ts
DELETED
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DefaultFlag,
|
|
3
|
-
RequestParam,
|
|
4
|
-
TimelineApiUtilsResponse,
|
|
5
|
-
TweetApiUtilsData,
|
|
6
|
-
TwitterApiUtilsResponse,
|
|
7
|
-
initOverrides,
|
|
8
|
-
} from '@/models';
|
|
9
|
-
import {
|
|
10
|
-
buildHeader,
|
|
11
|
-
entriesCursor,
|
|
12
|
-
errorCheck,
|
|
13
|
-
getKwargs,
|
|
14
|
-
instructionConverter,
|
|
15
|
-
instructionToEntry,
|
|
16
|
-
nonNullable,
|
|
17
|
-
tweetEntriesConverter,
|
|
18
|
-
} from '@/utils';
|
|
19
|
-
import * as i from 'twitter-openapi-typescript-generated';
|
|
20
|
-
|
|
21
|
-
type GetTweetDetailParam = {
|
|
22
|
-
focalTweetId: string;
|
|
23
|
-
cursor?: string;
|
|
24
|
-
controllerData?: string;
|
|
25
|
-
extraParam?: { [key: string]: any };
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
type GetSearchTimelineParam = {
|
|
29
|
-
rawQuery: string;
|
|
30
|
-
product?: string;
|
|
31
|
-
cursor?: string;
|
|
32
|
-
count?: number;
|
|
33
|
-
extraParam?: { [key: string]: any };
|
|
34
|
-
};
|
|
35
|
-
type GetHomeTimelineParam = {
|
|
36
|
-
cursor?: string;
|
|
37
|
-
count?: number;
|
|
38
|
-
extraParam?: { [key: string]: any };
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
type GetHomeLatestTimelineParam = {
|
|
42
|
-
cursor?: string;
|
|
43
|
-
count?: number;
|
|
44
|
-
extraParam?: { [key: string]: any };
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
type GetListLatestTweetsTimelineParam = {
|
|
48
|
-
listId: string;
|
|
49
|
-
cursor?: string;
|
|
50
|
-
count?: number;
|
|
51
|
-
extraParam?: { [key: string]: any };
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
type GetUserTweetsParam = {
|
|
55
|
-
userId: string;
|
|
56
|
-
cursor?: string;
|
|
57
|
-
count?: number;
|
|
58
|
-
extraParam?: { [key: string]: any };
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
type GetUserTweetsAndRepliesParam = {
|
|
62
|
-
userId: string;
|
|
63
|
-
cursor?: string;
|
|
64
|
-
count?: number;
|
|
65
|
-
extraParam?: { [key: string]: any };
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
type GetUserMediaParam = {
|
|
69
|
-
userId: string;
|
|
70
|
-
cursor?: string;
|
|
71
|
-
count?: number;
|
|
72
|
-
extraParam?: { [key: string]: any };
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
type GetLikesParam = {
|
|
76
|
-
userId: string;
|
|
77
|
-
cursor?: string;
|
|
78
|
-
count?: number;
|
|
79
|
-
extraParam?: { [key: string]: any };
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
type GetBookmarksParam = {
|
|
83
|
-
cursor?: string;
|
|
84
|
-
count?: number;
|
|
85
|
-
extraParam?: { [key: string]: any };
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
type ResponseType = TwitterApiUtilsResponse<TimelineApiUtilsResponse<TweetApiUtilsData>>;
|
|
89
|
-
|
|
90
|
-
export class TweetApiUtils {
|
|
91
|
-
api: i.TweetApi;
|
|
92
|
-
flag: DefaultFlag;
|
|
93
|
-
initOverrides: initOverrides;
|
|
94
|
-
|
|
95
|
-
constructor(api: i.TweetApi, flag: DefaultFlag, initOverrides: initOverrides) {
|
|
96
|
-
this.api = api;
|
|
97
|
-
this.flag = flag;
|
|
98
|
-
this.initOverrides = initOverrides;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async request<T>(param: RequestParam<i.InstructionUnion[], T>): Promise<ResponseType> {
|
|
102
|
-
const apiFn: typeof param.apiFn = param.apiFn.bind(this.api);
|
|
103
|
-
const args = getKwargs(this.flag[param.key], param.param);
|
|
104
|
-
const response = await apiFn(args, this.initOverrides);
|
|
105
|
-
const checked = errorCheck(await response.value());
|
|
106
|
-
const instruction = param.convertFn(checked);
|
|
107
|
-
const entry = instructionToEntry(instruction);
|
|
108
|
-
const data = [...tweetEntriesConverter(entry), ...instructionConverter(instruction)];
|
|
109
|
-
return {
|
|
110
|
-
raw: {
|
|
111
|
-
response: response.raw,
|
|
112
|
-
},
|
|
113
|
-
header: buildHeader(response.raw.headers),
|
|
114
|
-
data: {
|
|
115
|
-
raw: {
|
|
116
|
-
instruction,
|
|
117
|
-
entry,
|
|
118
|
-
},
|
|
119
|
-
cursor: entriesCursor(entry),
|
|
120
|
-
data: data,
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async getTweetDetail(param: GetTweetDetailParam): Promise<ResponseType> {
|
|
126
|
-
const args = {
|
|
127
|
-
focalTweetId: param.focalTweetId,
|
|
128
|
-
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
129
|
-
...(param.controllerData == undefined ? {} : { controller_data: param.controllerData }),
|
|
130
|
-
...param.extraParam,
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
const response = await this.request({
|
|
134
|
-
apiFn: this.api.getTweetDetailRaw,
|
|
135
|
-
convertFn: (e) => e.data.threadedConversationWithInjectionsV2.instructions,
|
|
136
|
-
key: 'TweetDetail',
|
|
137
|
-
param: args,
|
|
138
|
-
});
|
|
139
|
-
return response;
|
|
140
|
-
}
|
|
141
|
-
async getSearchTimeline(param: GetSearchTimelineParam): Promise<ResponseType> {
|
|
142
|
-
const args = {
|
|
143
|
-
rawQuery: param.rawQuery,
|
|
144
|
-
...(param.product == undefined ? {} : { product: param.product }),
|
|
145
|
-
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
146
|
-
...(param.count == undefined ? {} : { count: param.count }),
|
|
147
|
-
...param.extraParam,
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
const response = await this.request({
|
|
151
|
-
apiFn: this.api.getSearchTimelineRaw,
|
|
152
|
-
convertFn: (e) => e.data.searchByRawQuery.searchTimeline.timeline.instructions,
|
|
153
|
-
key: 'SearchTimeline',
|
|
154
|
-
param: args,
|
|
155
|
-
});
|
|
156
|
-
return response;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
async getHomeTimeline(param: GetHomeTimelineParam = {}): Promise<ResponseType> {
|
|
160
|
-
const args = {
|
|
161
|
-
...(param.count == undefined ? {} : { count: param.count }),
|
|
162
|
-
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
163
|
-
...param.extraParam,
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
const response = await this.request({
|
|
167
|
-
apiFn: this.api.getHomeTimelineRaw,
|
|
168
|
-
convertFn: (e) => e.data.home.homeTimelineUrt.instructions,
|
|
169
|
-
key: 'HomeTimeline',
|
|
170
|
-
param: args,
|
|
171
|
-
});
|
|
172
|
-
return response;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
async getHomeLatestTimeline(param: GetHomeLatestTimelineParam = {}): Promise<ResponseType> {
|
|
176
|
-
const args = {
|
|
177
|
-
...(param.count == undefined ? {} : { count: param.count }),
|
|
178
|
-
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
179
|
-
...param.extraParam,
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
const response = await this.request({
|
|
183
|
-
apiFn: this.api.getHomeLatestTimelineRaw,
|
|
184
|
-
convertFn: (e) => e.data.home.homeTimelineUrt.instructions,
|
|
185
|
-
key: 'HomeLatestTimeline',
|
|
186
|
-
param: args,
|
|
187
|
-
});
|
|
188
|
-
return response;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
async getListLatestTweetsTimeline(param: GetListLatestTweetsTimelineParam): Promise<ResponseType> {
|
|
192
|
-
const args = {
|
|
193
|
-
listId: param.listId,
|
|
194
|
-
...(param.count == undefined ? {} : { count: param.count }),
|
|
195
|
-
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
196
|
-
...param.extraParam,
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
const response = await this.request({
|
|
200
|
-
apiFn: this.api.getListLatestTweetsTimelineRaw,
|
|
201
|
-
convertFn: (e) => e.data.list.tweetsTimeline.timeline?.instructions ?? [],
|
|
202
|
-
key: 'ListLatestTweetsTimeline',
|
|
203
|
-
param: args,
|
|
204
|
-
});
|
|
205
|
-
return response;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
async getUserTweets(param: GetUserTweetsParam): Promise<ResponseType> {
|
|
209
|
-
const args = {
|
|
210
|
-
userId: param.userId,
|
|
211
|
-
...(param.count == undefined ? {} : { count: param.count }),
|
|
212
|
-
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
213
|
-
...param.extraParam,
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
const response = await this.request({
|
|
217
|
-
apiFn: this.api.getUserTweetsRaw,
|
|
218
|
-
convertFn: (e) => nonNullable(e.data.user.result.timelineV2.timeline).instructions,
|
|
219
|
-
key: 'UserTweets',
|
|
220
|
-
param: args,
|
|
221
|
-
});
|
|
222
|
-
return response;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
async getUserTweetsAndReplies(param: GetUserTweetsAndRepliesParam): Promise<ResponseType> {
|
|
226
|
-
const args = {
|
|
227
|
-
userId: param.userId,
|
|
228
|
-
...(param.count == undefined ? {} : { count: param.count }),
|
|
229
|
-
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
230
|
-
...param.extraParam,
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
const response = await this.request({
|
|
234
|
-
apiFn: this.api.getUserTweetsAndRepliesRaw,
|
|
235
|
-
convertFn: (e) => nonNullable(e.data.user.result.timelineV2.timeline).instructions,
|
|
236
|
-
key: 'UserTweetsAndReplies',
|
|
237
|
-
param: args,
|
|
238
|
-
});
|
|
239
|
-
return response;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
async getUserMedia(param: GetUserMediaParam): Promise<ResponseType> {
|
|
243
|
-
const args = {
|
|
244
|
-
userId: param.userId,
|
|
245
|
-
...(param.count == undefined ? {} : { count: param.count }),
|
|
246
|
-
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
247
|
-
...param.extraParam,
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
const response = await this.request({
|
|
251
|
-
apiFn: this.api.getUserMediaRaw,
|
|
252
|
-
convertFn: (e) => nonNullable(e.data.user.result.timelineV2.timeline).instructions,
|
|
253
|
-
key: 'UserMedia',
|
|
254
|
-
param: args,
|
|
255
|
-
});
|
|
256
|
-
return response;
|
|
257
|
-
}
|
|
258
|
-
async getLikes(param: GetLikesParam): Promise<ResponseType> {
|
|
259
|
-
const args = {
|
|
260
|
-
userId: param.userId,
|
|
261
|
-
...(param.count == undefined ? {} : { count: param.count }),
|
|
262
|
-
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
263
|
-
...param.extraParam,
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
const response = await this.request({
|
|
267
|
-
apiFn: this.api.getLikesRaw,
|
|
268
|
-
convertFn: (e) => nonNullable(e.data.user.result.timelineV2.timeline).instructions,
|
|
269
|
-
key: 'Likes',
|
|
270
|
-
param: args,
|
|
271
|
-
});
|
|
272
|
-
return response;
|
|
273
|
-
}
|
|
274
|
-
async getBookmarks(param: GetBookmarksParam = {}): Promise<ResponseType> {
|
|
275
|
-
const args = {
|
|
276
|
-
...(param.count == undefined ? {} : { count: param.count }),
|
|
277
|
-
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
278
|
-
...param.extraParam,
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
const response = await this.request({
|
|
282
|
-
apiFn: this.api.getBookmarksRaw,
|
|
283
|
-
convertFn: (e) => e.data.bookmarkTimelineV2.timeline.instructions,
|
|
284
|
-
key: 'Bookmarks',
|
|
285
|
-
param: args,
|
|
286
|
-
});
|
|
287
|
-
return response;
|
|
288
|
-
}
|
|
289
|
-
}
|
package/src/apis/userApi.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { DefaultFlag, RequestParam, TwitterApiUtilsResponse, UserApiUtilsData, initOverrides } from '@/models';
|
|
2
|
-
import { buildHeader, errorCheck, getKwargs, nonNullable, userOrNullConverter } from '@/utils';
|
|
3
|
-
import * as i from 'twitter-openapi-typescript-generated';
|
|
4
|
-
|
|
5
|
-
type getUserByScreenNameParam = {
|
|
6
|
-
screenName: string;
|
|
7
|
-
extraParam?: { [key: string]: any };
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
type getUserByRestIdParam = {
|
|
11
|
-
userId: string;
|
|
12
|
-
extraParam?: { [key: string]: any };
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
type ResponseType = TwitterApiUtilsResponse<UserApiUtilsData>;
|
|
16
|
-
|
|
17
|
-
export class UserApiUtils {
|
|
18
|
-
api: i.UserApi;
|
|
19
|
-
flag: DefaultFlag;
|
|
20
|
-
initOverrides: initOverrides;
|
|
21
|
-
|
|
22
|
-
constructor(api: i.UserApi, flag: DefaultFlag, initOverrides: initOverrides) {
|
|
23
|
-
this.api = api;
|
|
24
|
-
this.flag = flag;
|
|
25
|
-
this.initOverrides = initOverrides;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async request<T>(param: RequestParam<i.UserResults, T>): Promise<ResponseType> {
|
|
29
|
-
const apiFn: typeof param.apiFn = param.apiFn.bind(this.api);
|
|
30
|
-
const args = getKwargs(this.flag[param.key], param.param);
|
|
31
|
-
const response = await apiFn(args, this.initOverrides);
|
|
32
|
-
const checked = errorCheck(await response.value());
|
|
33
|
-
const result = param.convertFn(checked);
|
|
34
|
-
const user = result.result && userOrNullConverter(result.result);
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
raw: { response: response.raw },
|
|
38
|
-
header: buildHeader(response.raw.headers),
|
|
39
|
-
data: {
|
|
40
|
-
raw: result,
|
|
41
|
-
user: user,
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async getUserByScreenName(param: getUserByScreenNameParam): Promise<ResponseType> {
|
|
47
|
-
const args = {
|
|
48
|
-
screen_name: param.screenName,
|
|
49
|
-
...param.extraParam,
|
|
50
|
-
};
|
|
51
|
-
const response = this.request({
|
|
52
|
-
key: 'UserByScreenName',
|
|
53
|
-
apiFn: this.api.getUserByScreenNameRaw,
|
|
54
|
-
convertFn: (e) => nonNullable(e.data.user),
|
|
55
|
-
param: args,
|
|
56
|
-
});
|
|
57
|
-
return response;
|
|
58
|
-
}
|
|
59
|
-
async getUserByRestId(param: getUserByRestIdParam): Promise<ResponseType> {
|
|
60
|
-
const args = {
|
|
61
|
-
userId: param.userId,
|
|
62
|
-
...param.extraParam,
|
|
63
|
-
};
|
|
64
|
-
const response = this.request({
|
|
65
|
-
key: 'UserByRestId',
|
|
66
|
-
apiFn: this.api.getUserByRestIdRaw,
|
|
67
|
-
convertFn: (e) => nonNullable(e.data.user),
|
|
68
|
-
param: args,
|
|
69
|
-
});
|
|
70
|
-
return response;
|
|
71
|
-
}
|
|
72
|
-
}
|
package/src/apis/userListApi.ts
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DefaultFlag,
|
|
3
|
-
RequestParam,
|
|
4
|
-
TimelineApiUtilsResponse,
|
|
5
|
-
TwitterApiUtilsResponse,
|
|
6
|
-
UserApiUtilsData,
|
|
7
|
-
initOverrides,
|
|
8
|
-
} from '@/models';
|
|
9
|
-
import {
|
|
10
|
-
buildHeader,
|
|
11
|
-
entriesCursor,
|
|
12
|
-
errorCheck,
|
|
13
|
-
getKwargs,
|
|
14
|
-
instructionToEntry,
|
|
15
|
-
nonNullable,
|
|
16
|
-
userEntriesConverter,
|
|
17
|
-
userResultConverter,
|
|
18
|
-
} from '@/utils';
|
|
19
|
-
import * as i from 'twitter-openapi-typescript-generated';
|
|
20
|
-
|
|
21
|
-
type GetFollowersParam = {
|
|
22
|
-
userId: string;
|
|
23
|
-
cursor?: string;
|
|
24
|
-
count?: number;
|
|
25
|
-
extraParam?: { [key: string]: any };
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
type GetFollowingParam = {
|
|
29
|
-
userId: string;
|
|
30
|
-
cursor?: string;
|
|
31
|
-
count?: number;
|
|
32
|
-
extraParam?: { [key: string]: any };
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
type GetFollowersYouKnowParam = {
|
|
36
|
-
userId: string;
|
|
37
|
-
cursor?: string;
|
|
38
|
-
count?: number;
|
|
39
|
-
extraParam?: { [key: string]: any };
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
type GetFavoritersParam = {
|
|
43
|
-
tweetId: string;
|
|
44
|
-
cursor?: string;
|
|
45
|
-
count?: number;
|
|
46
|
-
extraParam?: { [key: string]: any };
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
type GetRetweetersParam = {
|
|
50
|
-
tweetId: string;
|
|
51
|
-
cursor?: string;
|
|
52
|
-
count?: number;
|
|
53
|
-
extraParam?: { [key: string]: any };
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
type ResponseType = TwitterApiUtilsResponse<TimelineApiUtilsResponse<UserApiUtilsData>>;
|
|
57
|
-
|
|
58
|
-
export class UserListApiUtils {
|
|
59
|
-
api: i.UserListApi;
|
|
60
|
-
flag: DefaultFlag;
|
|
61
|
-
initOverrides: initOverrides;
|
|
62
|
-
|
|
63
|
-
constructor(api: i.UserListApi, flag: DefaultFlag, initOverrides: initOverrides) {
|
|
64
|
-
this.api = api;
|
|
65
|
-
this.flag = flag;
|
|
66
|
-
this.initOverrides = initOverrides;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async request<T>(param: RequestParam<i.InstructionUnion[], T>): Promise<ResponseType> {
|
|
70
|
-
const apiFn: typeof param.apiFn = param.apiFn.bind(this.api);
|
|
71
|
-
const args = getKwargs(this.flag[param.key], param.param);
|
|
72
|
-
const response = await apiFn(args, this.initOverrides);
|
|
73
|
-
const checked = errorCheck(await response.value());
|
|
74
|
-
const instruction = param.convertFn(checked);
|
|
75
|
-
const entry = instructionToEntry(instruction);
|
|
76
|
-
const userList = userEntriesConverter(entry);
|
|
77
|
-
const data = userResultConverter(userList);
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
raw: {
|
|
81
|
-
response: response.raw,
|
|
82
|
-
},
|
|
83
|
-
header: buildHeader(response.raw.headers),
|
|
84
|
-
data: {
|
|
85
|
-
raw: {
|
|
86
|
-
instruction: instruction,
|
|
87
|
-
entry: entry,
|
|
88
|
-
},
|
|
89
|
-
data: data,
|
|
90
|
-
cursor: entriesCursor(entry),
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
async getFollowers(param: GetFollowersParam): Promise<ResponseType> {
|
|
96
|
-
const args = {
|
|
97
|
-
userId: param.userId,
|
|
98
|
-
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
99
|
-
...(param.count == undefined ? {} : { count: param.count }),
|
|
100
|
-
...param.extraParam,
|
|
101
|
-
};
|
|
102
|
-
const response = await this.request({
|
|
103
|
-
apiFn: this.api.getFollowersRaw,
|
|
104
|
-
convertFn: (e) => e.data.user.result.timeline.timeline.instructions,
|
|
105
|
-
key: 'Followers',
|
|
106
|
-
param: args,
|
|
107
|
-
});
|
|
108
|
-
return response;
|
|
109
|
-
}
|
|
110
|
-
async getFollowing(param: GetFollowingParam): Promise<ResponseType> {
|
|
111
|
-
const args = {
|
|
112
|
-
userId: param.userId,
|
|
113
|
-
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
114
|
-
...(param.count == undefined ? {} : { count: param.count }),
|
|
115
|
-
...param.extraParam,
|
|
116
|
-
};
|
|
117
|
-
const response = await this.request({
|
|
118
|
-
apiFn: this.api.getFollowingRaw,
|
|
119
|
-
convertFn: (e) => e.data.user.result.timeline.timeline.instructions,
|
|
120
|
-
key: 'Following',
|
|
121
|
-
param: args,
|
|
122
|
-
});
|
|
123
|
-
return response;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
async getFollowersYouKnow(param: GetFollowersYouKnowParam): Promise<ResponseType> {
|
|
127
|
-
const args = {
|
|
128
|
-
userId: param.userId,
|
|
129
|
-
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
130
|
-
...(param.count == undefined ? {} : { count: param.count }),
|
|
131
|
-
...param.extraParam,
|
|
132
|
-
};
|
|
133
|
-
const response = await this.request({
|
|
134
|
-
apiFn: this.api.getFollowersYouKnowRaw,
|
|
135
|
-
convertFn: (e) => e.data.user.result.timeline.timeline.instructions,
|
|
136
|
-
key: 'FollowersYouKnow',
|
|
137
|
-
param: args,
|
|
138
|
-
});
|
|
139
|
-
return response;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
async getFavoriters(param: GetFavoritersParam): Promise<ResponseType> {
|
|
143
|
-
const args = {
|
|
144
|
-
tweetId: param.tweetId,
|
|
145
|
-
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
146
|
-
...(param.count == undefined ? {} : { count: param.count }),
|
|
147
|
-
...param.extraParam,
|
|
148
|
-
};
|
|
149
|
-
const response = await this.request({
|
|
150
|
-
apiFn: this.api.getFavoritersRaw,
|
|
151
|
-
convertFn: (e) => nonNullable(e.data.favoritersTimeline.timeline).instructions,
|
|
152
|
-
key: 'Favoriters',
|
|
153
|
-
param: args,
|
|
154
|
-
});
|
|
155
|
-
return response;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
async getRetweeters(param: GetRetweetersParam): Promise<ResponseType> {
|
|
159
|
-
const args = {
|
|
160
|
-
tweetId: param.tweetId,
|
|
161
|
-
...(param.cursor == undefined ? {} : { cursor: param.cursor }),
|
|
162
|
-
...(param.count == undefined ? {} : { count: param.count }),
|
|
163
|
-
...param.extraParam,
|
|
164
|
-
};
|
|
165
|
-
const response = await this.request({
|
|
166
|
-
apiFn: this.api.getRetweetersRaw,
|
|
167
|
-
convertFn: (e) => nonNullable(e.data.retweetersTimeline.timeline).instructions,
|
|
168
|
-
key: 'Retweeters',
|
|
169
|
-
param: args,
|
|
170
|
-
});
|
|
171
|
-
return response;
|
|
172
|
-
}
|
|
173
|
-
}
|
package/src/apis/usersApi.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { DefaultFlag, RequestParam, TwitterApiUtilsResponse, UserApiUtilsData, initOverrides } from '@/models';
|
|
2
|
-
import { buildHeader, errorCheck, getKwargs, userResultConverter } from '@/utils';
|
|
3
|
-
import * as i from 'twitter-openapi-typescript-generated';
|
|
4
|
-
|
|
5
|
-
type getUsersByRestIdsParam = {
|
|
6
|
-
userIds: string[];
|
|
7
|
-
extraParam?: { [key: string]: any };
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
type ResponseType = TwitterApiUtilsResponse<UserApiUtilsData[]>;
|
|
11
|
-
|
|
12
|
-
export class UsersApiUtils {
|
|
13
|
-
api: i.UsersApi;
|
|
14
|
-
flag: DefaultFlag;
|
|
15
|
-
initOverrides: initOverrides;
|
|
16
|
-
|
|
17
|
-
constructor(api: i.UsersApi, flag: DefaultFlag, initOverrides: initOverrides) {
|
|
18
|
-
this.api = api;
|
|
19
|
-
this.flag = flag;
|
|
20
|
-
this.initOverrides = initOverrides;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async request<T>(param: RequestParam<i.UserResults[], T>): Promise<ResponseType> {
|
|
24
|
-
const apiFn: typeof param.apiFn = param.apiFn.bind(this.api);
|
|
25
|
-
const args = getKwargs(this.flag[param.key], param.param);
|
|
26
|
-
const response = await apiFn(args, this.initOverrides);
|
|
27
|
-
const checked = errorCheck(await response.value());
|
|
28
|
-
const result = param.convertFn(checked);
|
|
29
|
-
const user = userResultConverter(result);
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
raw: { response: response.raw },
|
|
33
|
-
header: buildHeader(response.raw.headers),
|
|
34
|
-
data: user,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
async getUsersByRestIds(param: getUsersByRestIdsParam): Promise<ResponseType> {
|
|
38
|
-
const args = {
|
|
39
|
-
userIds: param.userIds,
|
|
40
|
-
...param.extraParam,
|
|
41
|
-
};
|
|
42
|
-
const response = this.request({
|
|
43
|
-
key: 'UsersByRestIds',
|
|
44
|
-
apiFn: this.api.getUsersByRestIdsRaw,
|
|
45
|
-
convertFn: (e) => e.data.users,
|
|
46
|
-
param: args,
|
|
47
|
-
});
|
|
48
|
-
return response;
|
|
49
|
-
}
|
|
50
|
-
}
|
package/src/apis/v11GetApi.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { DefaultFlag, initOverrides } from '@/models';
|
|
2
|
-
import * as i from 'twitter-openapi-typescript-generated';
|
|
3
|
-
|
|
4
|
-
export class V11GetApiUtils {
|
|
5
|
-
api: i.V11GetApi;
|
|
6
|
-
flag: DefaultFlag;
|
|
7
|
-
initOverrides: initOverrides;
|
|
8
|
-
|
|
9
|
-
constructor(api: i.V11GetApi, flag: DefaultFlag, initOverrides: initOverrides) {
|
|
10
|
-
this.api = api;
|
|
11
|
-
this.flag = flag;
|
|
12
|
-
this.initOverrides = initOverrides;
|
|
13
|
-
}
|
|
14
|
-
}
|
package/src/apis/v11PostApi.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { DefaultFlag, TwitterApiUtilsResponse, initOverrides } from '@/models';
|
|
2
|
-
import { buildHeader } from '@/utils';
|
|
3
|
-
import * as i from 'twitter-openapi-typescript-generated';
|
|
4
|
-
|
|
5
|
-
type PostCreateFriendshipsParam = {
|
|
6
|
-
userId: string;
|
|
7
|
-
extraParam?: { [key: string]: any };
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
type PostDestroyFriendshipsParam = {
|
|
11
|
-
userId: string;
|
|
12
|
-
extraParam?: { [key: string]: any };
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export class V11PostApiUtils {
|
|
16
|
-
api: i.V11PostApi;
|
|
17
|
-
flag: DefaultFlag;
|
|
18
|
-
initOverrides: initOverrides;
|
|
19
|
-
|
|
20
|
-
constructor(api: i.V11PostApi, flag: DefaultFlag, initOverrides: initOverrides) {
|
|
21
|
-
this.api = api;
|
|
22
|
-
this.flag = flag;
|
|
23
|
-
this.initOverrides = initOverrides;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async postCreateFriendships(param: PostCreateFriendshipsParam): Promise<TwitterApiUtilsResponse<undefined>> {
|
|
27
|
-
const response = await this.api.postCreateFriendshipsRaw({
|
|
28
|
-
includeBlockedBy: 1,
|
|
29
|
-
includeBlocking: 1,
|
|
30
|
-
includeCanDm: 1,
|
|
31
|
-
includeCanMediaTag: 1,
|
|
32
|
-
includeExtHasNftAvatar: 1,
|
|
33
|
-
includeExtIsBlueVerified: 1,
|
|
34
|
-
includeExtProfileImageShape: 1,
|
|
35
|
-
includeExtVerifiedType: 1,
|
|
36
|
-
includeFollowedBy: 1,
|
|
37
|
-
includeMuteEdge: 1,
|
|
38
|
-
includeProfileInterstitialType: 1,
|
|
39
|
-
includeWantRetweets: 1,
|
|
40
|
-
skipStatus: 1,
|
|
41
|
-
userId: param.userId,
|
|
42
|
-
...param.extraParam,
|
|
43
|
-
});
|
|
44
|
-
return {
|
|
45
|
-
raw: { response: response.raw },
|
|
46
|
-
header: buildHeader(response.raw.headers),
|
|
47
|
-
data: undefined,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async postDestroyFriendships(param: PostDestroyFriendshipsParam): Promise<TwitterApiUtilsResponse<undefined>> {
|
|
52
|
-
const response = await this.api.postDestroyFriendshipsRaw({
|
|
53
|
-
includeBlockedBy: 0,
|
|
54
|
-
includeBlocking: 0,
|
|
55
|
-
includeCanDm: 0,
|
|
56
|
-
includeCanMediaTag: 0,
|
|
57
|
-
includeExtHasNftAvatar: 0,
|
|
58
|
-
includeExtIsBlueVerified: 0,
|
|
59
|
-
includeExtProfileImageShape: 0,
|
|
60
|
-
includeExtVerifiedType: 0,
|
|
61
|
-
includeFollowedBy: 0,
|
|
62
|
-
includeMuteEdge: 0,
|
|
63
|
-
includeProfileInterstitialType: 0,
|
|
64
|
-
includeWantRetweets: 0,
|
|
65
|
-
skipStatus: 0,
|
|
66
|
-
userId: param.userId,
|
|
67
|
-
...param.extraParam,
|
|
68
|
-
});
|
|
69
|
-
return {
|
|
70
|
-
raw: { response: response.raw },
|
|
71
|
-
header: buildHeader(response.raw.headers),
|
|
72
|
-
data: undefined,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
}
|
package/src/apis/v20GetApi.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { DefaultFlag, initOverrides } from '@/models';
|
|
2
|
-
import * as i from 'twitter-openapi-typescript-generated';
|
|
3
|
-
|
|
4
|
-
export class V20GetApiUtils {
|
|
5
|
-
api: i.V20GetApi;
|
|
6
|
-
flag: DefaultFlag;
|
|
7
|
-
initOverrides: initOverrides;
|
|
8
|
-
|
|
9
|
-
constructor(api: i.V20GetApi, flag: DefaultFlag, initOverrides: initOverrides) {
|
|
10
|
-
this.api = api;
|
|
11
|
-
this.flag = flag;
|
|
12
|
-
this.initOverrides = initOverrides;
|
|
13
|
-
}
|
|
14
|
-
}
|
package/src/index.ts
DELETED