twitter-openapi-typescript
Advanced tools
Comparing version 0.0.9 to 0.0.10
@@ -206,3 +206,3 @@ "use strict"; | ||
_a = TwitterOpenApi; | ||
TwitterOpenApi.hash = 'd5ccc25869b68cbb39c68fa81a1fa77967a667da'; | ||
TwitterOpenApi.hash = '29e05d162f600933fdbf633e992d2d0a249c9413'; | ||
TwitterOpenApi.url = "https://raw.githubusercontent.com/fa0311/twitter-openapi/".concat(_a.hash, "/src/config/placeholder.json"); | ||
@@ -209,0 +209,0 @@ TwitterOpenApi.twitter = 'https://twitter.com/home'; |
@@ -59,3 +59,4 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var apiFn, response, data, _a, _b; | ||
var apiFn, fieldTogglesFn, response, data, _a, _b; | ||
var _this = this; | ||
return __generator(this, function (_c) { | ||
@@ -65,8 +66,8 @@ switch (_c.label) { | ||
apiFn = param.apiFn.bind(this.api); | ||
return [4 /*yield*/, apiFn({ | ||
pathQueryId: this.flag[param.key]['queryId'], | ||
queryId: this.flag[param.key]['queryId'], | ||
variables: JSON.stringify(__assign(__assign({}, this.flag[param.key]['variables']), param.param)), | ||
features: JSON.stringify(this.flag[param.key]['features']), | ||
})]; | ||
fieldTogglesFn = function () { | ||
if (_this.flag[param.key]['fieldToggles'] == null) | ||
return { fieldToggles: '' }; | ||
return { fieldToggles: JSON.stringify(_this.flag[param.key]['fieldToggles']) }; | ||
}; | ||
return [4 /*yield*/, apiFn(__assign({ pathQueryId: this.flag[param.key]['queryId'], queryId: this.flag[param.key]['queryId'], variables: JSON.stringify(__assign(__assign({}, this.flag[param.key]['variables']), param.param)), features: JSON.stringify(this.flag[param.key]['features']) }, fieldTogglesFn()))]; | ||
case 1: | ||
@@ -73,0 +74,0 @@ response = _c.sent(); |
@@ -11,2 +11,11 @@ import * as i from 'twitter-openapi-typescript-generated'; | ||
}; | ||
type GetSearchTimelineParam = { | ||
rawQuery: string; | ||
product?: string; | ||
cursor?: string; | ||
count?: number; | ||
extraParam?: { | ||
[key: string]: any; | ||
}; | ||
}; | ||
type GetHomeTimelineParam = { | ||
@@ -79,2 +88,3 @@ couser?: string; | ||
getTweetDetail(param: GetTweetDetailParam): Promise<TweetListApiUtilsResponse>; | ||
getSearchTimeline(param: GetSearchTimelineParam): Promise<TweetListApiUtilsResponse>; | ||
getHomeTimeline(param?: GetHomeTimelineParam): Promise<TweetListApiUtilsResponse>; | ||
@@ -81,0 +91,0 @@ getHomeLatestTimeline(param?: GetHomeLatestTimelineParam): Promise<TweetListApiUtilsResponse>; |
@@ -59,3 +59,4 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var apiFn, response, instruction, _a, _b, entry, data, raw; | ||
var apiFn, fieldTogglesFn, response, instruction, _a, _b, entry, data, raw; | ||
var _this = this; | ||
return __generator(this, function (_c) { | ||
@@ -65,8 +66,8 @@ switch (_c.label) { | ||
apiFn = param.apiFn.bind(this.api); | ||
return [4 /*yield*/, apiFn({ | ||
pathQueryId: this.flag[param.key]['queryId'], | ||
queryId: this.flag[param.key]['queryId'], | ||
variables: JSON.stringify(__assign(__assign({}, this.flag[param.key]['variables']), param.param)), | ||
features: JSON.stringify(this.flag[param.key]['features']), | ||
})]; | ||
fieldTogglesFn = function () { | ||
if (_this.flag[param.key]['fieldToggles'] == null) | ||
return { fieldToggles: '' }; | ||
return { fieldToggles: JSON.stringify(_this.flag[param.key]['fieldToggles']) }; | ||
}; | ||
return [4 /*yield*/, apiFn(__assign({ pathQueryId: this.flag[param.key]['queryId'], queryId: this.flag[param.key]['queryId'], variables: JSON.stringify(__assign(__assign({}, this.flag[param.key]['variables']), param.param)), features: JSON.stringify(this.flag[param.key]['features']) }, fieldTogglesFn()))]; | ||
case 1: | ||
@@ -115,2 +116,22 @@ response = _c.sent(); | ||
}; | ||
TweetApiUtils.prototype.getSearchTimeline = function (param) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var args, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
args = __assign(__assign(__assign(__assign({ rawQuery: param.rawQuery }, (param.product == null ? {} : { product: param.product })), (param.cursor == null ? {} : { cursor: param.cursor })), (param.count == null ? {} : { count: param.count })), param.extraParam); | ||
return [4 /*yield*/, this.request({ | ||
apiFn: this.api.getSearchTimelineRaw, | ||
convertFn: function (e) { return e.data.searchByRawQuery.searchTimeline.timeline.instructions; }, | ||
key: 'SearchTimeline', | ||
param: args, | ||
})]; | ||
case 1: | ||
response = _a.sent(); | ||
return [2 /*return*/, response]; | ||
} | ||
}); | ||
}); | ||
}; | ||
TweetApiUtils.prototype.getHomeTimeline = function (param) { | ||
@@ -117,0 +138,0 @@ if (param === void 0) { param = {}; } |
import * as i from 'twitter-openapi-typescript-generated'; | ||
import { RequestParam, DefaultFlag, UserApiUtilsResponse } from '../models'; | ||
import { RequestParam, DefaultFlag, UserApiUtilsResponse, UsersApiUtilsResponse } from '../models'; | ||
type getUserByScreenNameParam = { | ||
@@ -9,2 +9,14 @@ screenName: string; | ||
}; | ||
type getUserByRestIdParam = { | ||
userId: string; | ||
extraParam?: { | ||
[key: string]: any; | ||
}; | ||
}; | ||
type getUsersByRestIdsParam = { | ||
userIds: string[]; | ||
extraParam?: { | ||
[key: string]: any; | ||
}; | ||
}; | ||
export declare class UserApiUtils { | ||
@@ -15,5 +27,8 @@ api: i.UserApi; | ||
request<T>(param: RequestParam<i.UserResults, T>): Promise<UserApiUtilsResponse>; | ||
requests<T>(param: RequestParam<i.UserResults[], T>): Promise<UsersApiUtilsResponse>; | ||
getUserByScreenName(param: getUserByScreenNameParam): Promise<UserApiUtilsResponse>; | ||
getUserByRestId(param: getUserByRestIdParam): Promise<UserApiUtilsResponse>; | ||
getUsersByRestIds(param: getUsersByRestIdsParam): Promise<UsersApiUtilsResponse>; | ||
} | ||
export {}; | ||
//# sourceMappingURL=userApi.d.ts.map |
@@ -59,3 +59,4 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var apiFn, response, user, _a, _b; | ||
var apiFn, fieldTogglesFn, response, user, _a, _b; | ||
var _this = this; | ||
return __generator(this, function (_c) { | ||
@@ -65,8 +66,8 @@ switch (_c.label) { | ||
apiFn = param.apiFn.bind(this.api); | ||
return [4 /*yield*/, apiFn({ | ||
pathQueryId: this.flag[param.key]['queryId'], | ||
queryId: this.flag[param.key]['queryId'], | ||
variables: JSON.stringify(__assign(__assign({}, this.flag[param.key]['variables']), param.param)), | ||
features: JSON.stringify(this.flag[param.key]['features']), | ||
})]; | ||
fieldTogglesFn = function () { | ||
if (_this.flag[param.key]['fieldToggles'] == null) | ||
return { fieldToggles: '' }; | ||
return { fieldToggles: JSON.stringify(_this.flag[param.key]['fieldToggles']) }; | ||
}; | ||
return [4 /*yield*/, apiFn(__assign({ pathQueryId: this.flag[param.key]['queryId'], queryId: this.flag[param.key]['queryId'], variables: JSON.stringify(__assign(__assign({}, this.flag[param.key]['variables']), param.param)), features: JSON.stringify(this.flag[param.key]['features']) }, fieldTogglesFn()))]; | ||
case 1: | ||
@@ -87,2 +88,31 @@ response = _c.sent(); | ||
}; | ||
UserApiUtils.prototype.requests = function (param) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var apiFn, fieldTogglesFn, response, user, _a, _b; | ||
var _this = this; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
apiFn = param.apiFn.bind(this.api); | ||
fieldTogglesFn = function () { | ||
if (_this.flag[param.key]['fieldToggles'] == null) | ||
return { fieldToggles: '' }; | ||
return { fieldToggles: JSON.stringify(_this.flag[param.key]['fieldToggles']) }; | ||
}; | ||
return [4 /*yield*/, apiFn(__assign({ pathQueryId: this.flag[param.key]['queryId'], queryId: this.flag[param.key]['queryId'], variables: JSON.stringify(__assign(__assign({}, this.flag[param.key]['variables']), param.param)), features: JSON.stringify(this.flag[param.key]['features']) }, fieldTogglesFn()))]; | ||
case 1: | ||
response = _c.sent(); | ||
_b = (_a = param).convertFn; | ||
return [4 /*yield*/, response.value()]; | ||
case 2: | ||
user = _b.apply(_a, [_c.sent()]).map(function (e) { return e.result; }); | ||
return [2 /*return*/, { | ||
raw: { response: response.raw }, | ||
header: (0, utils_1.buildHeader)(response.raw.headers), | ||
data: user, | ||
}]; | ||
} | ||
}); | ||
}); | ||
}; | ||
UserApiUtils.prototype.getUserByScreenName = function (param) { | ||
@@ -103,2 +133,32 @@ return __awaiter(this, void 0, void 0, function () { | ||
}; | ||
UserApiUtils.prototype.getUserByRestId = function (param) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var args, response; | ||
return __generator(this, function (_a) { | ||
args = __assign({ userId: param.userId }, param.extraParam); | ||
response = this.request({ | ||
key: 'UserByRestId', | ||
apiFn: this.api.getUserByRestIdRaw, | ||
convertFn: function (e) { return e.data.user; }, | ||
param: args, | ||
}); | ||
return [2 /*return*/, response]; | ||
}); | ||
}); | ||
}; | ||
UserApiUtils.prototype.getUsersByRestIds = function (param) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var args, response; | ||
return __generator(this, function (_a) { | ||
args = __assign({ userIds: param.userIds }, param.extraParam); | ||
response = this.requests({ | ||
key: 'UsersByRestIds', | ||
apiFn: this.api.getUsersByRestIdsRaw, | ||
convertFn: function (e) { return e.data.users; }, | ||
param: args, | ||
}); | ||
return [2 /*return*/, response]; | ||
}); | ||
}); | ||
}; | ||
return UserApiUtils; | ||
@@ -105,0 +165,0 @@ }()); |
import * as i from 'twitter-openapi-typescript-generated'; | ||
import { RequestParam, DefaultFlag, UserListApiUtilsResponse } from '../models'; | ||
type GetFollowers = { | ||
type GetFollowersParam = { | ||
userId: string; | ||
@@ -11,3 +11,3 @@ cursor?: string; | ||
}; | ||
type GetFollowing = { | ||
type GetFollowingParam = { | ||
userId: string; | ||
@@ -20,2 +20,26 @@ cursor?: string; | ||
}; | ||
type GetFollowersYouKnowParam = { | ||
userId: string; | ||
cursor?: string; | ||
count?: number; | ||
extraParam?: { | ||
[key: string]: any; | ||
}; | ||
}; | ||
type GetFavoritersParam = { | ||
tweetId: string; | ||
cursor?: string; | ||
count?: number; | ||
extraParam?: { | ||
[key: string]: any; | ||
}; | ||
}; | ||
type GetRetweetersParam = { | ||
tweetId: string; | ||
cursor?: string; | ||
count?: number; | ||
extraParam?: { | ||
[key: string]: any; | ||
}; | ||
}; | ||
export declare class UserListApiUtils { | ||
@@ -26,6 +50,9 @@ api: i.UserListApi; | ||
request<T>(param: RequestParam<i.InstructionUnion[], T>): Promise<UserListApiUtilsResponse>; | ||
getFollowers(param: GetFollowers): Promise<UserListApiUtilsResponse>; | ||
getFollowing(param: GetFollowing): Promise<UserListApiUtilsResponse>; | ||
getFollowers(param: GetFollowersParam): Promise<UserListApiUtilsResponse>; | ||
getFollowing(param: GetFollowingParam): Promise<UserListApiUtilsResponse>; | ||
getFollowersYouKnow(param: GetFollowersYouKnowParam): Promise<UserListApiUtilsResponse>; | ||
getFavoriters(param: GetFavoritersParam): Promise<UserListApiUtilsResponse>; | ||
getRetweeters(param: GetRetweetersParam): Promise<UserListApiUtilsResponse>; | ||
} | ||
export {}; | ||
//# sourceMappingURL=userListApi.d.ts.map |
@@ -59,3 +59,4 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var apiFn, response, instruction, _a, _b, entry, userList, data, raw; | ||
var apiFn, fieldTogglesFn, response, instruction, _a, _b, entry, userList, data, raw; | ||
var _this = this; | ||
return __generator(this, function (_c) { | ||
@@ -65,8 +66,8 @@ switch (_c.label) { | ||
apiFn = param.apiFn.bind(this.api); | ||
return [4 /*yield*/, apiFn({ | ||
pathQueryId: this.flag[param.key]['queryId'], | ||
queryId: this.flag[param.key]['queryId'], | ||
variables: JSON.stringify(__assign(__assign({}, this.flag[param.key]['variables']), param.param)), | ||
features: JSON.stringify(this.flag[param.key]['features']), | ||
})]; | ||
fieldTogglesFn = function () { | ||
if (_this.flag[param.key]['fieldToggles'] == null) | ||
return { fieldToggles: '' }; | ||
return { fieldToggles: JSON.stringify(_this.flag[param.key]['fieldToggles']) }; | ||
}; | ||
return [4 /*yield*/, apiFn(__assign({ pathQueryId: this.flag[param.key]['queryId'], queryId: this.flag[param.key]['queryId'], variables: JSON.stringify(__assign(__assign({}, this.flag[param.key]['variables']), param.param)), features: JSON.stringify(this.flag[param.key]['features']) }, fieldTogglesFn()))]; | ||
case 1: | ||
@@ -136,2 +137,62 @@ response = _c.sent(); | ||
}; | ||
UserListApiUtils.prototype.getFollowersYouKnow = function (param) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var args, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
args = __assign(__assign(__assign({ userId: param.userId }, (param.cursor == null ? {} : { cursor: param.cursor })), (param.count == null ? {} : { count: param.count })), param.extraParam); | ||
return [4 /*yield*/, this.request({ | ||
apiFn: this.api.getFollowersYouKnowRaw, | ||
convertFn: function (e) { return e.data.user.result.timeline.timeline.instructions; }, | ||
key: 'FollowersYouKnow', | ||
param: args, | ||
})]; | ||
case 1: | ||
response = _a.sent(); | ||
return [2 /*return*/, response]; | ||
} | ||
}); | ||
}); | ||
}; | ||
UserListApiUtils.prototype.getFavoriters = function (param) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var args, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
args = __assign(__assign(__assign({ tweetId: param.tweetId }, (param.cursor == null ? {} : { cursor: param.cursor })), (param.count == null ? {} : { count: param.count })), param.extraParam); | ||
return [4 /*yield*/, this.request({ | ||
apiFn: this.api.getTweetFavoritersRaw, | ||
convertFn: function (e) { return e.data.favoritersTimeline.timeline.instructions; }, | ||
key: 'Favoriters', | ||
param: args, | ||
})]; | ||
case 1: | ||
response = _a.sent(); | ||
return [2 /*return*/, response]; | ||
} | ||
}); | ||
}); | ||
}; | ||
UserListApiUtils.prototype.getRetweeters = function (param) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var args, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
args = __assign(__assign(__assign({ tweetId: param.tweetId }, (param.cursor == null ? {} : { cursor: param.cursor })), (param.count == null ? {} : { count: param.count })), param.extraParam); | ||
return [4 /*yield*/, this.request({ | ||
apiFn: this.api.getTweetRetweetersRaw, | ||
convertFn: function (e) { return e.data.retweetersTimeline.timeline.instructions; }, | ||
key: 'Retweeters', | ||
param: args, | ||
})]; | ||
case 1: | ||
response = _a.sent(); | ||
return [2 /*return*/, response]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return UserListApiUtils; | ||
@@ -138,0 +199,0 @@ }()); |
@@ -8,2 +8,7 @@ import * as i from 'twitter-openapi-typescript-generated'; | ||
}; | ||
export type UsersApiUtilsResponse = { | ||
raw: UserApiUtilsRaw; | ||
header: ApiUtilsHeader; | ||
data: i.User[]; | ||
}; | ||
export type UserApiUtilsRaw = { | ||
@@ -10,0 +15,0 @@ response: Response; |
@@ -7,2 +7,3 @@ import * as i from 'twitter-openapi-typescript-generated'; | ||
features: string; | ||
fieldToggles: string; | ||
}) => Promise<i.ApiResponse<T>>; | ||
@@ -9,0 +10,0 @@ export type RequestParam<T1, T2> = { |
{ | ||
"name": "twitter-openapi-typescript", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "Implementation of Twitter internal API in TypeScript", | ||
@@ -13,3 +13,4 @@ "scripts": { | ||
"api", | ||
"typescript" | ||
"typescript", | ||
"scraper" | ||
], | ||
@@ -25,3 +26,3 @@ "author": "fa0311", | ||
"dependencies": { | ||
"twitter-openapi-typescript-generated": "^0.0.7" | ||
"twitter-openapi-typescript-generated": "^0.0.8" | ||
}, | ||
@@ -28,0 +29,0 @@ "devDependencies": { |
@@ -30,3 +30,3 @@ import * as i from 'twitter-openapi-typescript-generated'; | ||
export class TwitterOpenApi { | ||
static hash = 'd5ccc25869b68cbb39c68fa81a1fa77967a667da'; | ||
static hash = '29e05d162f600933fdbf633e992d2d0a249c9413'; | ||
static url = `https://raw.githubusercontent.com/fa0311/twitter-openapi/${this.hash}/src/config/placeholder.json`; | ||
@@ -33,0 +33,0 @@ static twitter = 'https://twitter.com/home'; |
@@ -21,2 +21,6 @@ import * as i from 'twitter-openapi-typescript-generated'; | ||
const apiFn: typeof param.apiFn = param.apiFn.bind(this.api); | ||
const fieldTogglesFn = () => { | ||
if (this.flag[param.key]['fieldToggles'] == null) return { fieldToggles: '' }; | ||
return { fieldToggles: JSON.stringify(this.flag[param.key]['fieldToggles']) }; | ||
}; | ||
const response = await apiFn({ | ||
@@ -27,2 +31,3 @@ pathQueryId: this.flag[param.key]['queryId'], | ||
features: JSON.stringify(this.flag[param.key]['features']), | ||
...fieldTogglesFn(), | ||
}); | ||
@@ -29,0 +34,0 @@ const data = param.convertFn(await response.value()); |
@@ -12,2 +12,9 @@ import * as i from 'twitter-openapi-typescript-generated'; | ||
type GetSearchTimelineParam = { | ||
rawQuery: string; | ||
product?: string; | ||
cursor?: string; | ||
count?: number; | ||
extraParam?: { [key: string]: any }; | ||
}; | ||
type GetHomeTimelineParam = { | ||
@@ -77,2 +84,6 @@ couser?: string; | ||
const apiFn: typeof param.apiFn = param.apiFn.bind(this.api); | ||
const fieldTogglesFn = () => { | ||
if (this.flag[param.key]['fieldToggles'] == null) return { fieldToggles: '' }; | ||
return { fieldToggles: JSON.stringify(this.flag[param.key]['fieldToggles']) }; | ||
}; | ||
const response = await apiFn({ | ||
@@ -83,2 +94,3 @@ pathQueryId: this.flag[param.key]['queryId'], | ||
features: JSON.stringify(this.flag[param.key]['features']), | ||
...fieldTogglesFn(), | ||
}); | ||
@@ -117,3 +129,20 @@ const instruction = param.convertFn(await response.value()); | ||
} | ||
async getSearchTimeline(param: GetSearchTimelineParam): Promise<TweetListApiUtilsResponse> { | ||
const args = { | ||
rawQuery: param.rawQuery, | ||
...(param.product == null ? {} : { product: param.product }), | ||
...(param.cursor == null ? {} : { cursor: param.cursor }), | ||
...(param.count == null ? {} : { count: param.count }), | ||
...param.extraParam, | ||
}; | ||
const response = await this.request({ | ||
apiFn: this.api.getSearchTimelineRaw, | ||
convertFn: (e) => e.data.searchByRawQuery.searchTimeline.timeline.instructions, | ||
key: 'SearchTimeline', | ||
param: args, | ||
}); | ||
return response; | ||
} | ||
async getHomeTimeline(param: GetHomeTimelineParam = {}): Promise<TweetListApiUtilsResponse> { | ||
@@ -120,0 +149,0 @@ const args = { |
import * as i from 'twitter-openapi-typescript-generated'; | ||
import { RequestParam, DefaultFlag, UserApiUtilsResponse } from '@/models'; | ||
import { RequestParam, DefaultFlag, UserApiUtilsResponse, UsersApiUtilsResponse } from '@/models'; | ||
import { buildHeader } from '@/utils'; | ||
@@ -10,2 +10,12 @@ | ||
type getUserByRestIdParam = { | ||
userId: string; | ||
extraParam?: { [key: string]: any }; | ||
}; | ||
type getUsersByRestIdsParam = { | ||
userIds: string[]; | ||
extraParam?: { [key: string]: any }; | ||
}; | ||
export class UserApiUtils { | ||
@@ -22,2 +32,6 @@ api: i.UserApi; | ||
const apiFn: typeof param.apiFn = param.apiFn.bind(this.api); | ||
const fieldTogglesFn = () => { | ||
if (this.flag[param.key]['fieldToggles'] == null) return { fieldToggles: '' }; | ||
return { fieldToggles: JSON.stringify(this.flag[param.key]['fieldToggles']) }; | ||
}; | ||
const response = await apiFn({ | ||
@@ -28,2 +42,3 @@ pathQueryId: this.flag[param.key]['queryId'], | ||
features: JSON.stringify(this.flag[param.key]['features']), | ||
...fieldTogglesFn(), | ||
}); | ||
@@ -38,2 +53,23 @@ const user = param.convertFn(await response.value()); | ||
async requests<T>(param: RequestParam<i.UserResults[], T>): Promise<UsersApiUtilsResponse> { | ||
const apiFn: typeof param.apiFn = param.apiFn.bind(this.api); | ||
const fieldTogglesFn = () => { | ||
if (this.flag[param.key]['fieldToggles'] == null) return { fieldToggles: '' }; | ||
return { fieldToggles: JSON.stringify(this.flag[param.key]['fieldToggles']) }; | ||
}; | ||
const response = await apiFn({ | ||
pathQueryId: this.flag[param.key]['queryId'], | ||
queryId: this.flag[param.key]['queryId'], | ||
variables: JSON.stringify({ ...this.flag[param.key]['variables'], ...param.param }), | ||
features: JSON.stringify(this.flag[param.key]['features']), | ||
...fieldTogglesFn(), | ||
}); | ||
const user = param.convertFn(await response.value()).map((e) => e.result); | ||
return { | ||
raw: { response: response.raw }, | ||
header: buildHeader(response.raw.headers), | ||
data: user, | ||
}; | ||
} | ||
async getUserByScreenName(param: getUserByScreenNameParam): Promise<UserApiUtilsResponse> { | ||
@@ -52,2 +88,29 @@ const args = { | ||
} | ||
async getUserByRestId(param: getUserByRestIdParam): Promise<UserApiUtilsResponse> { | ||
const args = { | ||
userId: param.userId, | ||
...param.extraParam, | ||
}; | ||
const response = this.request({ | ||
key: 'UserByRestId', | ||
apiFn: this.api.getUserByRestIdRaw, | ||
convertFn: (e) => e.data.user, | ||
param: args, | ||
}); | ||
return response; | ||
} | ||
async getUsersByRestIds(param: getUsersByRestIdsParam): Promise<UsersApiUtilsResponse> { | ||
const args = { | ||
userIds: param.userIds, | ||
...param.extraParam, | ||
}; | ||
const response = this.requests({ | ||
key: 'UsersByRestIds', | ||
apiFn: this.api.getUsersByRestIdsRaw, | ||
convertFn: (e) => e.data.users, | ||
param: args, | ||
}); | ||
return response; | ||
} | ||
} |
@@ -5,3 +5,3 @@ import * as i from 'twitter-openapi-typescript-generated'; | ||
type GetFollowers = { | ||
type GetFollowersParam = { | ||
userId: string; | ||
@@ -13,3 +13,3 @@ cursor?: string; | ||
type GetFollowing = { | ||
type GetFollowingParam = { | ||
userId: string; | ||
@@ -21,2 +21,23 @@ cursor?: string; | ||
type GetFollowersYouKnowParam = { | ||
userId: string; | ||
cursor?: string; | ||
count?: number; | ||
extraParam?: { [key: string]: any }; | ||
}; | ||
type GetFavoritersParam = { | ||
tweetId: string; | ||
cursor?: string; | ||
count?: number; | ||
extraParam?: { [key: string]: any }; | ||
}; | ||
type GetRetweetersParam = { | ||
tweetId: string; | ||
cursor?: string; | ||
count?: number; | ||
extraParam?: { [key: string]: any }; | ||
}; | ||
export class UserListApiUtils { | ||
@@ -33,2 +54,6 @@ api: i.UserListApi; | ||
const apiFn: typeof param.apiFn = param.apiFn.bind(this.api); | ||
const fieldTogglesFn = () => { | ||
if (this.flag[param.key]['fieldToggles'] == null) return { fieldToggles: '' }; | ||
return { fieldToggles: JSON.stringify(this.flag[param.key]['fieldToggles']) }; | ||
}; | ||
const response = await apiFn({ | ||
@@ -39,2 +64,3 @@ pathQueryId: this.flag[param.key]['queryId'], | ||
features: JSON.stringify(this.flag[param.key]['features']), | ||
...fieldTogglesFn(), | ||
}); | ||
@@ -59,3 +85,3 @@ const instruction = param.convertFn(await response.value()); | ||
async getFollowers(param: GetFollowers): Promise<UserListApiUtilsResponse> { | ||
async getFollowers(param: GetFollowersParam): Promise<UserListApiUtilsResponse> { | ||
const args = { | ||
@@ -75,3 +101,3 @@ userId: param.userId, | ||
} | ||
async getFollowing(param: GetFollowing): Promise<UserListApiUtilsResponse> { | ||
async getFollowing(param: GetFollowingParam): Promise<UserListApiUtilsResponse> { | ||
const args = { | ||
@@ -91,2 +117,50 @@ userId: param.userId, | ||
} | ||
async getFollowersYouKnow(param: GetFollowersYouKnowParam): Promise<UserListApiUtilsResponse> { | ||
const args = { | ||
userId: param.userId, | ||
...(param.cursor == null ? {} : { cursor: param.cursor }), | ||
...(param.count == null ? {} : { count: param.count }), | ||
...param.extraParam, | ||
}; | ||
const response = await this.request({ | ||
apiFn: this.api.getFollowersYouKnowRaw, | ||
convertFn: (e) => e.data.user.result.timeline.timeline.instructions, | ||
key: 'FollowersYouKnow', | ||
param: args, | ||
}); | ||
return response; | ||
} | ||
async getFavoriters(param: GetFavoritersParam): Promise<UserListApiUtilsResponse> { | ||
const args = { | ||
tweetId: param.tweetId, | ||
...(param.cursor == null ? {} : { cursor: param.cursor }), | ||
...(param.count == null ? {} : { count: param.count }), | ||
...param.extraParam, | ||
}; | ||
const response = await this.request({ | ||
apiFn: this.api.getTweetFavoritersRaw, | ||
convertFn: (e) => e.data.favoritersTimeline.timeline.instructions, | ||
key: 'Favoriters', | ||
param: args, | ||
}); | ||
return response; | ||
} | ||
async getRetweeters(param: GetRetweetersParam): Promise<UserListApiUtilsResponse> { | ||
const args = { | ||
tweetId: param.tweetId, | ||
...(param.cursor == null ? {} : { cursor: param.cursor }), | ||
...(param.count == null ? {} : { count: param.count }), | ||
...param.extraParam, | ||
}; | ||
const response = await this.request({ | ||
apiFn: this.api.getTweetRetweetersRaw, | ||
convertFn: (e) => e.data.retweetersTimeline.timeline.instructions, | ||
key: 'Retweeters', | ||
param: args, | ||
}); | ||
return response; | ||
} | ||
} |
@@ -9,2 +9,7 @@ import * as i from 'twitter-openapi-typescript-generated'; | ||
}; | ||
export type UsersApiUtilsResponse = { | ||
raw: UserApiUtilsRaw; | ||
header: ApiUtilsHeader; | ||
data: i.User[]; | ||
}; | ||
@@ -11,0 +16,0 @@ export type UserApiUtilsRaw = { |
@@ -8,2 +8,3 @@ import * as i from 'twitter-openapi-typescript-generated'; | ||
features: string; | ||
fieldToggles: string; | ||
}) => Promise<i.ApiResponse<T>>; | ||
@@ -10,0 +11,0 @@ |
@@ -12,2 +12,10 @@ import { getClient, logger } from '@test/init'; | ||
test('getSearchTimeline', async () => { | ||
logger.log('getSearchTimeline'); | ||
const client = await getClient(); | ||
const response = await client.getTweetApi().getSearchTimeline({ rawQuery: 'elonmusk' }); | ||
response.data.filter((e) => !e.promotedMetadata).forEach((e) => printTweet(e)); | ||
expect(response.raw.response.ok).toBe(true); | ||
}); | ||
test('getHomeTimeline', async () => { | ||
@@ -14,0 +22,0 @@ logger.log('getHomeTimeline'); |
@@ -19,1 +19,25 @@ import { getClient, logger } from '@test/init'; | ||
}); | ||
test('getFollowersYouKnow', async () => { | ||
logger.log('getFollowersYouKnow'); | ||
const client = await getClient(); | ||
const response = await client.getUserListApi().getFollowersYouKnow({ userId: '44196397' }); | ||
response.data.forEach((e) => printUser(e)); | ||
expect(response.raw.response.ok).toBe(true); | ||
}); | ||
test('getFavoriters', async () => { | ||
logger.log('getFavoriters'); | ||
const client = await getClient(); | ||
const response = await client.getUserListApi().getFavoriters({ tweetId: '1349129669258448897' }); | ||
response.data.forEach((e) => printUser(e)); | ||
expect(response.raw.response.ok).toBe(true); | ||
}); | ||
test('getRetweeters', async () => { | ||
logger.log('getRetweeters'); | ||
const client = await getClient(); | ||
const response = await client.getUserListApi().getRetweeters({ tweetId: '1349129669258448897' }); | ||
response.data.forEach((e) => printUser(e)); | ||
expect(response.raw.response.ok).toBe(true); | ||
}); |
@@ -7,3 +7,2 @@ import { getClient, logger } from '@test/init'; | ||
pathQueryId: client.flag.HomeTimeline.queryId, | ||
queryId: client.flag.HomeTimeline.queryId, | ||
variables: JSON.stringify(client.flag.HomeTimeline.variables), | ||
@@ -10,0 +9,0 @@ features: JSON.stringify(client.flag.HomeTimeline.features), |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
252096
3592
+ Addedtwitter-openapi-typescript-generated@0.0.8(transitive)
- Removedtwitter-openapi-typescript-generated@0.0.7(transitive)