Add files via upload

This commit is contained in:
shahramdj
2022-10-07 15:45:45 -04:00
committed by GitHub
parent 8ddcc312b7
commit 91c72d107e
78 changed files with 6467 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
import TwitterApiv2ReadWrite from './client.v2.write';
import TwitterApiv2Labs from '../v2-labs/client.v2.labs';
/**
* Twitter v2 client with all rights (read/write/DMs)
*/
export declare class TwitterApiv2 extends TwitterApiv2ReadWrite {
protected _prefix: string;
protected _labs?: TwitterApiv2Labs;
/**
* Get a client with read/write rights.
*/
get readWrite(): TwitterApiv2ReadWrite;
/**
* Get a client for v2 labs endpoints.
*/
get labs(): TwitterApiv2Labs;
}
export default TwitterApiv2;

View File

@@ -0,0 +1,35 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TwitterApiv2 = void 0;
const globals_1 = require("../globals");
const client_v2_write_1 = __importDefault(require("./client.v2.write"));
const client_v2_labs_1 = __importDefault(require("../v2-labs/client.v2.labs"));
/**
* Twitter v2 client with all rights (read/write/DMs)
*/
class TwitterApiv2 extends client_v2_write_1.default {
constructor() {
super(...arguments);
this._prefix = globals_1.API_V2_PREFIX;
}
/* Sub-clients */
/**
* Get a client with read/write rights.
*/
get readWrite() {
return this;
}
/**
* Get a client for v2 labs endpoints.
*/
get labs() {
if (this._labs)
return this._labs;
return this._labs = new client_v2_labs_1.default(this);
}
}
exports.TwitterApiv2 = TwitterApiv2;
exports.default = TwitterApiv2;

View File

@@ -0,0 +1,302 @@
import TwitterApiSubClient from '../client.subclient';
import { Tweetv2FieldsParams, Tweetv2SearchParams, UserV2Result, UsersV2Result, UsersV2Params, StreamingV2GetRulesParams, StreamingV2GetRulesResult, TweetV2LookupResult, TweetV2UserTimelineParams, StreamingV2AddRulesParams, StreamingV2DeleteRulesParams, StreamingV2UpdateRulesQuery, StreamingV2UpdateRulesDeleteResult, StreamingV2UpdateRulesAddResult, TweetV2SingleResult, TweetV2PaginableTimelineParams, TweetV2CountResult, TweetV2CountParams, TweetV2CountAllResult, TweetV2CountAllParams, TweetV2RetweetedByResult, TweetV2LikedByResult, UserV2TimelineParams, UserV2TimelineResult, FollowersV2ParamsWithPaginator, FollowersV2ParamsWithoutPaginator, TweetSearchV2StreamParams, TweetV2SingleStreamResult, TweetV2PaginableListParams, SpaceV2FieldsParams, SpaceV2LookupResult, SpaceV2CreatorLookupParams, SpaceV2SearchParams, SpaceV2SingleResult, BatchComplianceSearchV2Params, BatchComplianceListV2Result, BatchComplianceV2Result, BatchComplianceV2Params, BatchComplianceV2JobResult, BatchComplianceJobV2, GetListV2Params, ListGetV2Result, GetListTimelineV2Params, TweetRetweetedOrLikedByV2ParamsWithPaginator, TweetRetweetedOrLikedByV2ParamsWithoutPaginator, SpaceV2BuyersParams, TweetV2HomeTimelineParams } from '../types';
import { TweetSearchAllV2Paginator, TweetSearchRecentV2Paginator, TweetUserMentionTimelineV2Paginator, TweetUserTimelineV2Paginator, TweetV2UserLikedTweetsPaginator, UserOwnedListsV2Paginator, UserListMembershipsV2Paginator, UserListFollowedV2Paginator, TweetV2ListTweetsPaginator, TweetBookmarksTimelineV2Paginator, QuotedTweetsTimelineV2Paginator, TweetHomeTimelineV2Paginator } from '../paginators';
import TwitterApiv2LabsReadOnly from '../v2-labs/client.v2.labs.read';
import { TweetLikingUsersV2Paginator, TweetRetweetersUsersV2Paginator, UserBlockingUsersV2Paginator, UserFollowersV2Paginator, UserFollowingV2Paginator, UserListFollowersV2Paginator, UserListMembersV2Paginator, UserMutingUsersV2Paginator } from '../paginators/user.paginator.v2';
import TweetStream from '../stream/TweetStream';
import { PromiseOrType } from '../types/shared.types';
/**
* Base Twitter v2 client with only read right.
*/
export default class TwitterApiv2ReadOnly extends TwitterApiSubClient {
protected _prefix: string;
protected _labs?: TwitterApiv2LabsReadOnly;
/**
* Get a client for v2 labs endpoints.
*/
get labs(): TwitterApiv2LabsReadOnly;
/**
* The recent search endpoint returns Tweets from the last seven days that match a search query.
* https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-recent
*/
search(options: Partial<Tweetv2SearchParams>): Promise<TweetSearchRecentV2Paginator>;
search(query: string, options?: Partial<Tweetv2SearchParams>): Promise<TweetSearchRecentV2Paginator>;
/**
* The full-archive search endpoint returns the complete history of public Tweets matching a search query;
* since the first Tweet was created March 26, 2006.
*
* This endpoint is only available to those users who have been approved for the Academic Research product track.
* https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-all
*/
searchAll(query: string, options?: Partial<Tweetv2SearchParams>): Promise<TweetSearchAllV2Paginator>;
/**
* Returns a variety of information about a single Tweet specified by the requested ID.
* https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets-id
*
* OAuth2 scope: `users.read`, `tweet.read`
*/
singleTweet(tweetId: string, options?: Partial<Tweetv2FieldsParams>): Promise<TweetV2SingleResult>;
/**
* Returns a variety of information about tweets specified by list of IDs.
* https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets
*
* OAuth2 scope: `users.read`, `tweet.read`
*/
tweets(tweetIds: string | string[], options?: Partial<Tweetv2FieldsParams>): Promise<TweetV2LookupResult>;
/**
* The recent Tweet counts endpoint returns count of Tweets from the last seven days that match a search query.
* OAuth2 Bearer auth only.
* https://developer.twitter.com/en/docs/twitter-api/tweets/counts/api-reference/get-tweets-counts-recent
*/
tweetCountRecent(query: string, options?: Partial<TweetV2CountParams>): Promise<TweetV2CountResult>;
/**
* This endpoint is only available to those users who have been approved for the Academic Research product track.
* The full-archive search endpoint returns the complete history of public Tweets matching a search query;
* since the first Tweet was created March 26, 2006.
* OAuth2 Bearer auth only.
* **This endpoint has pagination, yet it is not supported by bundled paginators. Use `next_token` to fetch next page.**
* https://developer.twitter.com/en/docs/twitter-api/tweets/counts/api-reference/get-tweets-counts-all
*/
tweetCountAll(query: string, options?: Partial<TweetV2CountAllParams>): Promise<TweetV2CountAllResult>;
/**
* Allows you to get information about who has Retweeted a Tweet.
* https://developer.twitter.com/en/docs/twitter-api/tweets/retweets/api-reference/get-tweets-id-retweeted_by
*/
tweetRetweetedBy(tweetId: string, options?: Partial<TweetRetweetedOrLikedByV2ParamsWithoutPaginator>): Promise<TweetV2RetweetedByResult>;
tweetRetweetedBy(tweetId: string, options: TweetRetweetedOrLikedByV2ParamsWithPaginator): Promise<TweetRetweetersUsersV2Paginator>;
/**
* Allows you to get information about who has Liked a Tweet.
* https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/get-tweets-id-liking_users
*/
tweetLikedBy(tweetId: string, options?: Partial<TweetRetweetedOrLikedByV2ParamsWithoutPaginator>): Promise<TweetV2LikedByResult>;
tweetLikedBy(tweetId: string, options: TweetRetweetedOrLikedByV2ParamsWithPaginator): Promise<TweetLikingUsersV2Paginator>;
/**
* Allows you to retrieve a collection of the most recent Tweets and Retweets posted by you and users you follow, also known as home timeline.
* This endpoint returns up to the last 3200 Tweets.
* https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-reverse-chronological
*
* OAuth 2 scopes: `tweet.read` `users.read`
*/
homeTimeline(options?: Partial<TweetV2HomeTimelineParams>): Promise<TweetHomeTimelineV2Paginator>;
/**
* Returns Tweets composed by a single user, specified by the requested user ID.
* By default, the most recent ten Tweets are returned per request.
* Using pagination, the most recent 3,200 Tweets can be retrieved.
* https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-tweets
*/
userTimeline(userId: string, options?: Partial<TweetV2UserTimelineParams>): Promise<TweetUserTimelineV2Paginator>;
/**
* Returns Tweets mentioning a single user specified by the requested user ID.
* By default, the most recent ten Tweets are returned per request.
* Using pagination, up to the most recent 800 Tweets can be retrieved.
* https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-mentions
*/
userMentionTimeline(userId: string, options?: Partial<TweetV2PaginableTimelineParams>): Promise<TweetUserMentionTimelineV2Paginator>;
/**
* Returns Quote Tweets for a Tweet specified by the requested Tweet ID.
* https://developer.twitter.com/en/docs/twitter-api/tweets/quote-tweets/api-reference/get-tweets-id-quote_tweets
*
* OAuth2 scopes: `users.read` `tweet.read`
*/
quotes(tweetId: string, options?: Partial<TweetV2PaginableTimelineParams>): Promise<QuotedTweetsTimelineV2Paginator>;
/**
* Allows you to get information about a authenticated users 800 most recent bookmarked Tweets.
* https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/api-reference/get-users-id-bookmarks
*
* OAuth2 scopes: `users.read` `tweet.read` `bookmark.read`
*/
bookmarks(options?: Partial<TweetV2PaginableTimelineParams>): Promise<TweetBookmarksTimelineV2Paginator>;
/**
* Returns information about an authorized user.
* https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-me
*
* OAuth2 scopes: `tweet.read` & `users.read`
*/
me(options?: Partial<UsersV2Params>): Promise<UserV2Result>;
/**
* Returns a variety of information about a single user specified by the requested ID.
* https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-id
*/
user(userId: string, options?: Partial<UsersV2Params>): Promise<UserV2Result>;
/**
* Returns a variety of information about one or more users specified by the requested IDs.
* https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users
*/
users(userIds: string | string[], options?: Partial<UsersV2Params>): Promise<UsersV2Result>;
/**
* Returns a variety of information about a single user specified by their username.
* https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-by-username-username
*/
userByUsername(username: string, options?: Partial<UsersV2Params>): Promise<UserV2Result>;
/**
* Returns a variety of information about one or more users specified by their usernames.
* https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-by
*
* OAuth2 scope: `users.read`, `tweet.read`
*/
usersByUsernames(usernames: string | string[], options?: Partial<UsersV2Params>): Promise<UsersV2Result>;
/**
* Returns a list of users who are followers of the specified user ID.
* https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/get-users-id-followers
*/
followers(userId: string, options?: Partial<FollowersV2ParamsWithoutPaginator>): Promise<UserV2TimelineResult>;
followers(userId: string, options: FollowersV2ParamsWithPaginator): Promise<UserFollowersV2Paginator>;
/**
* Returns a list of users the specified user ID is following.
* https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/get-users-id-following
*
* OAuth2 scope: `follows.read`
*/
following(userId: string, options?: Partial<FollowersV2ParamsWithoutPaginator>): Promise<UserV2TimelineResult>;
following(userId: string, options: FollowersV2ParamsWithPaginator): Promise<UserFollowingV2Paginator>;
/**
* Allows you to get information about a users liked Tweets.
* https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/get-users-id-liked_tweets
*/
userLikedTweets(userId: string, options?: Partial<TweetV2PaginableListParams>): Promise<TweetV2UserLikedTweetsPaginator>;
/**
* Returns a list of users who are blocked by the authenticating user.
* https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/get-users-blocking
*/
userBlockingUsers(userId: string, options?: Partial<UserV2TimelineParams>): Promise<UserBlockingUsersV2Paginator>;
/**
* Returns a list of users who are muted by the authenticating user.
* https://developer.twitter.com/en/docs/twitter-api/users/mutes/api-reference/get-users-muting
*/
userMutingUsers(userId: string, options?: Partial<UserV2TimelineParams>): Promise<UserMutingUsersV2Paginator>;
/**
* Returns the details of a specified List.
* https://developer.twitter.com/en/docs/twitter-api/lists/list-lookup/api-reference/get-lists-id
*/
list(id: string, options?: Partial<GetListV2Params>): Promise<ListGetV2Result>;
/**
* Returns all Lists owned by the specified user.
* https://developer.twitter.com/en/docs/twitter-api/lists/list-lookup/api-reference/get-users-id-owned_lists
*/
listsOwned(userId: string, options?: Partial<GetListTimelineV2Params>): Promise<UserOwnedListsV2Paginator>;
/**
* Returns all Lists a specified user is a member of.
* https://developer.twitter.com/en/docs/twitter-api/lists/list-members/api-reference/get-users-id-list_memberships
*/
listMemberships(userId: string, options?: Partial<GetListTimelineV2Params>): Promise<UserListMembershipsV2Paginator>;
/**
* Returns all Lists a specified user follows.
* https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/api-reference/get-users-id-followed_lists
*/
listFollowed(userId: string, options?: Partial<GetListTimelineV2Params>): Promise<UserListFollowedV2Paginator>;
/**
* Returns a list of Tweets from the specified List.
* https://developer.twitter.com/en/docs/twitter-api/lists/list-tweets/api-reference/get-lists-id-tweets
*/
listTweets(listId: string, options?: Partial<TweetV2PaginableListParams>): Promise<TweetV2ListTweetsPaginator>;
/**
* Returns a list of users who are members of the specified List.
* https://developer.twitter.com/en/docs/twitter-api/lists/list-members/api-reference/get-lists-id-members
*/
listMembers(listId: string, options?: Partial<UserV2TimelineParams>): Promise<UserListMembersV2Paginator>;
/**
* Returns a list of users who are followers of the specified List.
* https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/api-reference/get-lists-id-followers
*/
listFollowers(listId: string, options?: Partial<UserV2TimelineParams>): Promise<UserListFollowersV2Paginator>;
/**
* Get a single space by ID.
* https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-id
*
* OAuth2 scopes: `tweet.read`, `users.read`, `space.read`.
*/
space(spaceId: string, options?: Partial<SpaceV2FieldsParams>): Promise<SpaceV2SingleResult>;
/**
* Get spaces using their IDs.
* https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces
*
* OAuth2 scopes: `tweet.read`, `users.read`, `space.read`.
*/
spaces(spaceIds: string | string[], options?: Partial<SpaceV2FieldsParams>): Promise<SpaceV2LookupResult>;
/**
* Get spaces using their creator user ID(s). (no pagination available)
* https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-by-creator-ids
*
* OAuth2 scopes: `tweet.read`, `users.read`, `space.read`.
*/
spacesByCreators(creatorIds: string | string[], options?: Partial<SpaceV2CreatorLookupParams>): Promise<SpaceV2LookupResult>;
/**
* Search through spaces using multiple params. (no pagination available)
* https://developer.twitter.com/en/docs/twitter-api/spaces/search/api-reference/get-spaces-search
*/
searchSpaces(options: SpaceV2SearchParams): Promise<SpaceV2LookupResult>;
/**
* Returns a list of user who purchased a ticket to the requested Space.
* You must authenticate the request using the Access Token of the creator of the requested Space.
*
* **OAuth 2.0 Access Token required**
*
* https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-id-buyers
*
* OAuth2 scopes: `tweet.read`, `users.read`, `space.read`.
*/
spaceBuyers(spaceId: string, options?: Partial<SpaceV2BuyersParams>): Promise<UsersV2Result>;
/**
* Streams Tweets in real-time based on a specific set of filter rules.
* https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream
*/
searchStream(options?: Partial<TweetSearchV2StreamParams> & {
autoConnect?: true;
}): Promise<TweetStream<TweetV2SingleStreamResult>>;
searchStream(options: Partial<TweetSearchV2StreamParams> & {
autoConnect: false;
}): TweetStream<TweetV2SingleStreamResult>;
searchStream(options?: Partial<TweetSearchV2StreamParams> & {
autoConnect?: boolean;
}): PromiseOrType<TweetStream<TweetV2SingleStreamResult>>;
/**
* Return a list of rules currently active on the streaming endpoint, either as a list or individually.
* https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream-rules
*/
streamRules(options?: Partial<StreamingV2GetRulesParams>): Promise<StreamingV2GetRulesResult>;
/**
* Add or delete rules to your stream.
* To create one or more rules, submit an add JSON body with an array of rules and operators.
* Similarly, to delete one or more rules, submit a delete JSON body with an array of list of existing rule IDs.
* https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/post-tweets-search-stream-rules
*/
updateStreamRules(options: StreamingV2AddRulesParams, query?: Partial<StreamingV2UpdateRulesQuery>): Promise<StreamingV2UpdateRulesAddResult>;
updateStreamRules(options: StreamingV2DeleteRulesParams, query?: Partial<StreamingV2UpdateRulesQuery>): Promise<StreamingV2UpdateRulesDeleteResult>;
/**
* Streams about 1% of all Tweets in real-time.
* https://developer.twitter.com/en/docs/twitter-api/tweets/volume-streams/api-reference/get-tweets-sample-stream
*/
sampleStream(options?: Partial<Tweetv2FieldsParams> & {
autoConnect?: true;
}): Promise<TweetStream<TweetV2SingleResult>>;
sampleStream(options: Partial<Tweetv2FieldsParams> & {
autoConnect: false;
}): TweetStream<TweetV2SingleResult>;
sampleStream(options?: Partial<Tweetv2FieldsParams> & {
autoConnect?: boolean;
}): PromiseOrType<TweetStream<TweetV2SingleResult>>;
/**
* Returns a list of recent compliance jobs.
* https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/api-reference/get-compliance-jobs
*/
complianceJobs(options: BatchComplianceSearchV2Params): Promise<BatchComplianceListV2Result>;
/**
* Get a single compliance job with the specified ID.
* https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/api-reference/get-compliance-jobs-id
*/
complianceJob(jobId: string): Promise<BatchComplianceV2Result>;
/**
* Creates a new compliance job for Tweet IDs or user IDs, send your file, await result and parse it into an array.
* You can run one batch job at a time. Returns the created job, but **not the job result!**.
*
* You can obtain the result (**after job is completed**) with `.complianceJobResult`.
* https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/api-reference/post-compliance-jobs
*/
sendComplianceJob(jobParams: BatchComplianceV2Params): Promise<BatchComplianceV2Result>;
/**
* Get the result of a running or completed job, obtained through `.complianceJob`, `.complianceJobs` or `.sendComplianceJob`.
* If job is still running (`in_progress`), it will await until job is completed. **This could be quite long!**
* https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/api-reference/post-compliance-jobs
*/
complianceJobResult(job: BatchComplianceJobV2): Promise<BatchComplianceV2JobResult[]>;
}

View File

@@ -0,0 +1,568 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const client_subclient_1 = __importDefault(require("../client.subclient"));
const globals_1 = require("../globals");
const paginators_1 = require("../paginators");
const client_v2_labs_read_1 = __importDefault(require("../v2-labs/client.v2.labs.read"));
const user_paginator_v2_1 = require("../paginators/user.paginator.v2");
const helpers_1 = require("../helpers");
/**
* Base Twitter v2 client with only read right.
*/
class TwitterApiv2ReadOnly extends client_subclient_1.default {
constructor() {
super(...arguments);
this._prefix = globals_1.API_V2_PREFIX;
}
/* Sub-clients */
/**
* Get a client for v2 labs endpoints.
*/
get labs() {
if (this._labs)
return this._labs;
return this._labs = new client_v2_labs_read_1.default(this);
}
async search(queryOrOptions, options = {}) {
const query = typeof queryOrOptions === 'string' ? queryOrOptions : undefined;
const realOptions = typeof queryOrOptions === 'object' && queryOrOptions !== null ? queryOrOptions : options;
const queryParams = { ...realOptions, query };
const initialRq = await this.get('tweets/search/recent', queryParams, { fullResponse: true });
return new paginators_1.TweetSearchRecentV2Paginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams,
});
}
/**
* The full-archive search endpoint returns the complete history of public Tweets matching a search query;
* since the first Tweet was created March 26, 2006.
*
* This endpoint is only available to those users who have been approved for the Academic Research product track.
* https://developer.twitter.com/en/docs/twitter-api/tweets/search/api-reference/get-tweets-search-all
*/
async searchAll(query, options = {}) {
const queryParams = { ...options, query };
const initialRq = await this.get('tweets/search/all', queryParams, { fullResponse: true });
return new paginators_1.TweetSearchAllV2Paginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams,
});
}
/**
* Returns a variety of information about a single Tweet specified by the requested ID.
* https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets-id
*
* OAuth2 scope: `users.read`, `tweet.read`
*/
singleTweet(tweetId, options = {}) {
return this.get('tweets/:id', options, { params: { id: tweetId } });
}
/**
* Returns a variety of information about tweets specified by list of IDs.
* https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets
*
* OAuth2 scope: `users.read`, `tweet.read`
*/
tweets(tweetIds, options = {}) {
return this.get('tweets', { ids: tweetIds, ...options });
}
/**
* The recent Tweet counts endpoint returns count of Tweets from the last seven days that match a search query.
* OAuth2 Bearer auth only.
* https://developer.twitter.com/en/docs/twitter-api/tweets/counts/api-reference/get-tweets-counts-recent
*/
tweetCountRecent(query, options = {}) {
return this.get('tweets/counts/recent', { query, ...options });
}
/**
* This endpoint is only available to those users who have been approved for the Academic Research product track.
* The full-archive search endpoint returns the complete history of public Tweets matching a search query;
* since the first Tweet was created March 26, 2006.
* OAuth2 Bearer auth only.
* **This endpoint has pagination, yet it is not supported by bundled paginators. Use `next_token` to fetch next page.**
* https://developer.twitter.com/en/docs/twitter-api/tweets/counts/api-reference/get-tweets-counts-all
*/
tweetCountAll(query, options = {}) {
return this.get('tweets/counts/all', { query, ...options });
}
async tweetRetweetedBy(tweetId, options = {}) {
const { asPaginator, ...parameters } = options;
const initialRq = await this.get('tweets/:id/retweeted_by', parameters, {
fullResponse: true,
params: { id: tweetId },
});
if (!asPaginator) {
return initialRq.data;
}
return new user_paginator_v2_1.TweetRetweetersUsersV2Paginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams: parameters,
sharedParams: { id: tweetId },
});
}
async tweetLikedBy(tweetId, options = {}) {
const { asPaginator, ...parameters } = options;
const initialRq = await this.get('tweets/:id/liking_users', parameters, {
fullResponse: true,
params: { id: tweetId },
});
if (!asPaginator) {
return initialRq.data;
}
return new user_paginator_v2_1.TweetLikingUsersV2Paginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams: parameters,
sharedParams: { id: tweetId },
});
}
/**
* Allows you to retrieve a collection of the most recent Tweets and Retweets posted by you and users you follow, also known as home timeline.
* This endpoint returns up to the last 3200 Tweets.
* https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-reverse-chronological
*
* OAuth 2 scopes: `tweet.read` `users.read`
*/
async homeTimeline(options = {}) {
const meUser = await this.getCurrentUserV2Object();
const initialRq = await this.get('users/:id/timelines/reverse_chronological', options, {
fullResponse: true,
params: { id: meUser.data.id },
});
return new paginators_1.TweetHomeTimelineV2Paginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams: options,
sharedParams: { id: meUser.data.id },
});
}
/**
* Returns Tweets composed by a single user, specified by the requested user ID.
* By default, the most recent ten Tweets are returned per request.
* Using pagination, the most recent 3,200 Tweets can be retrieved.
* https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-tweets
*/
async userTimeline(userId, options = {}) {
const initialRq = await this.get('users/:id/tweets', options, {
fullResponse: true,
params: { id: userId },
});
return new paginators_1.TweetUserTimelineV2Paginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams: options,
sharedParams: { id: userId },
});
}
/**
* Returns Tweets mentioning a single user specified by the requested user ID.
* By default, the most recent ten Tweets are returned per request.
* Using pagination, up to the most recent 800 Tweets can be retrieved.
* https://developer.twitter.com/en/docs/twitter-api/tweets/timelines/api-reference/get-users-id-mentions
*/
async userMentionTimeline(userId, options = {}) {
const initialRq = await this.get('users/:id/mentions', options, {
fullResponse: true,
params: { id: userId },
});
return new paginators_1.TweetUserMentionTimelineV2Paginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams: options,
sharedParams: { id: userId },
});
}
/**
* Returns Quote Tweets for a Tweet specified by the requested Tweet ID.
* https://developer.twitter.com/en/docs/twitter-api/tweets/quote-tweets/api-reference/get-tweets-id-quote_tweets
*
* OAuth2 scopes: `users.read` `tweet.read`
*/
async quotes(tweetId, options = {}) {
const initialRq = await this.get('tweets/:id/quote_tweets', options, {
fullResponse: true,
params: { id: tweetId },
});
return new paginators_1.QuotedTweetsTimelineV2Paginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams: options,
sharedParams: { id: tweetId },
});
}
/* Bookmarks */
/**
* Allows you to get information about a authenticated users 800 most recent bookmarked Tweets.
* https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/api-reference/get-users-id-bookmarks
*
* OAuth2 scopes: `users.read` `tweet.read` `bookmark.read`
*/
async bookmarks(options = {}) {
const user = await this.getCurrentUserV2Object();
const initialRq = await this.get('users/:id/bookmarks', options, {
fullResponse: true,
params: { id: user.data.id },
});
return new paginators_1.TweetBookmarksTimelineV2Paginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams: options,
sharedParams: { id: user.data.id },
});
}
/* Users */
/**
* Returns information about an authorized user.
* https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-me
*
* OAuth2 scopes: `tweet.read` & `users.read`
*/
me(options = {}) {
return this.get('users/me', options);
}
/**
* Returns a variety of information about a single user specified by the requested ID.
* https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-id
*/
user(userId, options = {}) {
return this.get('users/:id', options, { params: { id: userId } });
}
/**
* Returns a variety of information about one or more users specified by the requested IDs.
* https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users
*/
users(userIds, options = {}) {
const ids = Array.isArray(userIds) ? userIds.join(',') : userIds;
return this.get('users', { ...options, ids });
}
/**
* Returns a variety of information about a single user specified by their username.
* https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-by-username-username
*/
userByUsername(username, options = {}) {
return this.get('users/by/username/:username', options, { params: { username } });
}
/**
* Returns a variety of information about one or more users specified by their usernames.
* https://developer.twitter.com/en/docs/twitter-api/users/lookup/api-reference/get-users-by
*
* OAuth2 scope: `users.read`, `tweet.read`
*/
usersByUsernames(usernames, options = {}) {
usernames = Array.isArray(usernames) ? usernames.join(',') : usernames;
return this.get('users/by', { ...options, usernames });
}
async followers(userId, options = {}) {
const { asPaginator, ...parameters } = options;
const params = { id: userId };
if (!asPaginator) {
return this.get('users/:id/followers', parameters, { params });
}
const initialRq = await this.get('users/:id/followers', parameters, { fullResponse: true, params });
return new user_paginator_v2_1.UserFollowersV2Paginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams: parameters,
sharedParams: params,
});
}
async following(userId, options = {}) {
const { asPaginator, ...parameters } = options;
const params = { id: userId };
if (!asPaginator) {
return this.get('users/:id/following', parameters, { params });
}
const initialRq = await this.get('users/:id/following', parameters, { fullResponse: true, params });
return new user_paginator_v2_1.UserFollowingV2Paginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams: parameters,
sharedParams: params,
});
}
/**
* Allows you to get information about a users liked Tweets.
* https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/get-users-id-liked_tweets
*/
async userLikedTweets(userId, options = {}) {
const params = { id: userId };
const initialRq = await this.get('users/:id/liked_tweets', options, { fullResponse: true, params });
return new paginators_1.TweetV2UserLikedTweetsPaginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams: { ...options },
sharedParams: params,
});
}
/**
* Returns a list of users who are blocked by the authenticating user.
* https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/get-users-blocking
*/
async userBlockingUsers(userId, options = {}) {
const params = { id: userId };
const initialRq = await this.get('users/:id/blocking', options, { fullResponse: true, params });
return new user_paginator_v2_1.UserBlockingUsersV2Paginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams: { ...options },
sharedParams: params,
});
}
/**
* Returns a list of users who are muted by the authenticating user.
* https://developer.twitter.com/en/docs/twitter-api/users/mutes/api-reference/get-users-muting
*/
async userMutingUsers(userId, options = {}) {
const params = { id: userId };
const initialRq = await this.get('users/:id/muting', options, { fullResponse: true, params });
return new user_paginator_v2_1.UserMutingUsersV2Paginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams: { ...options },
sharedParams: params,
});
}
/* Lists */
/**
* Returns the details of a specified List.
* https://developer.twitter.com/en/docs/twitter-api/lists/list-lookup/api-reference/get-lists-id
*/
list(id, options = {}) {
return this.get('lists/:id', options, { params: { id } });
}
/**
* Returns all Lists owned by the specified user.
* https://developer.twitter.com/en/docs/twitter-api/lists/list-lookup/api-reference/get-users-id-owned_lists
*/
async listsOwned(userId, options = {}) {
const params = { id: userId };
const initialRq = await this.get('users/:id/owned_lists', options, { fullResponse: true, params });
return new paginators_1.UserOwnedListsV2Paginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams: { ...options },
sharedParams: params,
});
}
/**
* Returns all Lists a specified user is a member of.
* https://developer.twitter.com/en/docs/twitter-api/lists/list-members/api-reference/get-users-id-list_memberships
*/
async listMemberships(userId, options = {}) {
const params = { id: userId };
const initialRq = await this.get('users/:id/list_memberships', options, { fullResponse: true, params });
return new paginators_1.UserListMembershipsV2Paginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams: { ...options },
sharedParams: params,
});
}
/**
* Returns all Lists a specified user follows.
* https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/api-reference/get-users-id-followed_lists
*/
async listFollowed(userId, options = {}) {
const params = { id: userId };
const initialRq = await this.get('users/:id/followed_lists', options, { fullResponse: true, params });
return new paginators_1.UserListFollowedV2Paginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams: { ...options },
sharedParams: params,
});
}
/**
* Returns a list of Tweets from the specified List.
* https://developer.twitter.com/en/docs/twitter-api/lists/list-tweets/api-reference/get-lists-id-tweets
*/
async listTweets(listId, options = {}) {
const params = { id: listId };
const initialRq = await this.get('lists/:id/tweets', options, { fullResponse: true, params });
return new paginators_1.TweetV2ListTweetsPaginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams: { ...options },
sharedParams: params,
});
}
/**
* Returns a list of users who are members of the specified List.
* https://developer.twitter.com/en/docs/twitter-api/lists/list-members/api-reference/get-lists-id-members
*/
async listMembers(listId, options = {}) {
const params = { id: listId };
const initialRq = await this.get('lists/:id/members', options, { fullResponse: true, params });
return new user_paginator_v2_1.UserListMembersV2Paginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams: { ...options },
sharedParams: params,
});
}
/**
* Returns a list of users who are followers of the specified List.
* https://developer.twitter.com/en/docs/twitter-api/lists/list-follows/api-reference/get-lists-id-followers
*/
async listFollowers(listId, options = {}) {
const params = { id: listId };
const initialRq = await this.get('lists/:id/followers', options, { fullResponse: true, params });
return new user_paginator_v2_1.UserListFollowersV2Paginator({
realData: initialRq.data,
rateLimit: initialRq.rateLimit,
instance: this,
queryParams: { ...options },
sharedParams: params,
});
}
/* Spaces */
/**
* Get a single space by ID.
* https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-id
*
* OAuth2 scopes: `tweet.read`, `users.read`, `space.read`.
*/
space(spaceId, options = {}) {
return this.get('spaces/:id', options, { params: { id: spaceId } });
}
/**
* Get spaces using their IDs.
* https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces
*
* OAuth2 scopes: `tweet.read`, `users.read`, `space.read`.
*/
spaces(spaceIds, options = {}) {
return this.get('spaces', { ids: spaceIds, ...options });
}
/**
* Get spaces using their creator user ID(s). (no pagination available)
* https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-by-creator-ids
*
* OAuth2 scopes: `tweet.read`, `users.read`, `space.read`.
*/
spacesByCreators(creatorIds, options = {}) {
return this.get('spaces/by/creator_ids', { user_ids: creatorIds, ...options });
}
/**
* Search through spaces using multiple params. (no pagination available)
* https://developer.twitter.com/en/docs/twitter-api/spaces/search/api-reference/get-spaces-search
*/
searchSpaces(options) {
return this.get('spaces/search', options);
}
/**
* Returns a list of user who purchased a ticket to the requested Space.
* You must authenticate the request using the Access Token of the creator of the requested Space.
*
* **OAuth 2.0 Access Token required**
*
* https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-id-buyers
*
* OAuth2 scopes: `tweet.read`, `users.read`, `space.read`.
*/
spaceBuyers(spaceId, options = {}) {
return this.get('spaces/:id/buyers', options, { params: { id: spaceId } });
}
searchStream({ autoConnect, ...options } = {}) {
return this.getStream('tweets/search/stream', options, { payloadIsError: helpers_1.isTweetStreamV2ErrorPayload, autoConnect });
}
/**
* Return a list of rules currently active on the streaming endpoint, either as a list or individually.
* https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream-rules
*/
streamRules(options = {}) {
return this.get('tweets/search/stream/rules', options);
}
updateStreamRules(options, query = {}) {
return this.post('tweets/search/stream/rules', options, { query });
}
sampleStream({ autoConnect, ...options } = {}) {
return this.getStream('tweets/sample/stream', options, { payloadIsError: helpers_1.isTweetStreamV2ErrorPayload, autoConnect });
}
/* Batch compliance */
/**
* Returns a list of recent compliance jobs.
* https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/api-reference/get-compliance-jobs
*/
complianceJobs(options) {
return this.get('compliance/jobs', options);
}
/**
* Get a single compliance job with the specified ID.
* https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/api-reference/get-compliance-jobs-id
*/
complianceJob(jobId) {
return this.get('compliance/jobs/:id', undefined, { params: { id: jobId } });
}
/**
* Creates a new compliance job for Tweet IDs or user IDs, send your file, await result and parse it into an array.
* You can run one batch job at a time. Returns the created job, but **not the job result!**.
*
* You can obtain the result (**after job is completed**) with `.complianceJobResult`.
* https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/api-reference/post-compliance-jobs
*/
async sendComplianceJob(jobParams) {
const job = await this.post('compliance/jobs', { type: jobParams.type, name: jobParams.name });
// Send the IDs
const rawIdsBody = jobParams.ids instanceof Buffer ? jobParams.ids : Buffer.from(jobParams.ids.join('\n'));
// Upload the IDs
await this.put(job.data.upload_url, rawIdsBody, {
forceBodyMode: 'raw',
enableAuth: false,
headers: { 'Content-Type': 'text/plain' },
prefix: '',
});
return job;
}
/**
* Get the result of a running or completed job, obtained through `.complianceJob`, `.complianceJobs` or `.sendComplianceJob`.
* If job is still running (`in_progress`), it will await until job is completed. **This could be quite long!**
* https://developer.twitter.com/en/docs/twitter-api/compliance/batch-compliance/api-reference/post-compliance-jobs
*/
async complianceJobResult(job) {
let runningJob = job;
while (runningJob.status !== 'complete') {
if (runningJob.status === 'expired' || runningJob.status === 'failed') {
throw new Error('Job failed to be completed.');
}
await new Promise(resolve => setTimeout(resolve, 3500));
runningJob = (await this.complianceJob(job.id)).data;
}
// Download and parse result
const result = await this.get(job.download_url, undefined, {
enableAuth: false,
prefix: '',
});
return result
.trim()
.split('\n')
.filter(line => line)
.map(line => JSON.parse(line));
}
}
exports.default = TwitterApiv2ReadOnly;

View File

@@ -0,0 +1,187 @@
import TwitterApiv2ReadOnly from './client.v2.read';
import type { ListCreateV2Params, ListCreateV2Result, ListDeleteV2Result, ListFollowV2Result, ListMemberV2Result, ListPinV2Result, ListUpdateV2Params, ListUpdateV2Result, TweetV2DeleteTweetResult, SendTweetV2Params, TweetV2HideReplyResult, TweetV2LikeResult, TweetV2PostTweetResult, TweetV2RetweetResult, UserV2BlockResult, UserV2FollowResult, UserV2MuteResult, UserV2UnfollowResult, TweetV2BookmarkResult } from '../types';
import TwitterApiv2LabsReadWrite from '../v2-labs/client.v2.labs.write';
/**
* Base Twitter v2 client with read/write rights.
*/
export default class TwitterApiv2ReadWrite extends TwitterApiv2ReadOnly {
protected _prefix: string;
protected _labs?: TwitterApiv2LabsReadWrite;
/**
* Get a client with only read rights.
*/
get readOnly(): TwitterApiv2ReadOnly;
/**
* Get a client for v2 labs endpoints.
*/
get labs(): TwitterApiv2LabsReadWrite;
/**
* Hides or unhides a reply to a Tweet.
* https://developer.twitter.com/en/docs/twitter-api/tweets/hide-replies/api-reference/put-tweets-id-hidden
*/
hideReply(tweetId: string, makeHidden: boolean): Promise<TweetV2HideReplyResult>;
/**
* Causes the user ID identified in the path parameter to Like the target Tweet.
* https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/post-users-user_id-likes
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
like(loggedUserId: string, targetTweetId: string): Promise<TweetV2LikeResult>;
/**
* Allows a user or authenticated user ID to unlike a Tweet.
* The request succeeds with no action when the user sends a request to a user they're not liking the Tweet or have already unliked the Tweet.
* https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/delete-users-id-likes-tweet_id
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
unlike(loggedUserId: string, targetTweetId: string): Promise<TweetV2LikeResult>;
/**
* Causes the user ID identified in the path parameter to Retweet the target Tweet.
* https://developer.twitter.com/en/docs/twitter-api/tweets/retweets/api-reference/post-users-id-retweets
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
retweet(loggedUserId: string, targetTweetId: string): Promise<TweetV2RetweetResult>;
/**
* Allows a user or authenticated user ID to remove the Retweet of a Tweet.
* The request succeeds with no action when the user sends a request to a user they're not Retweeting the Tweet or have already removed the Retweet of.
* https://developer.twitter.com/en/docs/twitter-api/tweets/retweets/api-reference/delete-users-id-retweets-tweet_id
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
unretweet(loggedUserId: string, targetTweetId: string): Promise<TweetV2RetweetResult>;
/**
* Creates a Tweet on behalf of an authenticated user.
* https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/post-tweets
*/
tweet(status: string, payload?: Partial<SendTweetV2Params>): Promise<TweetV2PostTweetResult>;
tweet(payload: SendTweetV2Params): Promise<TweetV2PostTweetResult>;
/**
* Reply to a Tweet on behalf of an authenticated user.
* https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/post-tweets
*/
reply(status: string, toTweetId: string, payload?: Partial<SendTweetV2Params>): Promise<TweetV2PostTweetResult>;
/**
* Quote an existing Tweet on behalf of an authenticated user.
* https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/post-tweets
*/
quote(status: string, quotedTweetId: string, payload?: Partial<SendTweetV2Params>): Promise<TweetV2PostTweetResult>;
/**
* Post a series of tweets.
* https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/post-tweets
*/
tweetThread(tweets: (SendTweetV2Params | string)[]): Promise<TweetV2PostTweetResult[]>;
/**
* Allows a user or authenticated user ID to delete a Tweet
* https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/delete-tweets-id
*/
deleteTweet(tweetId: string): Promise<TweetV2DeleteTweetResult>;
/**
* Causes the user ID of an authenticated user identified in the path parameter to Bookmark the target Tweet provided in the request body.
* https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/api-reference/post-users-id-bookmarks
*
* OAuth2 scopes: `users.read` `tweet.read` `bookmark.write`
*/
bookmark(tweetId: string): Promise<TweetV2BookmarkResult>;
/**
* Allows a user or authenticated user ID to remove a Bookmark of a Tweet.
* https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/api-reference/delete-users-id-bookmarks-tweet_id
*
* OAuth2 scopes: `users.read` `tweet.read` `bookmark.write`
*/
deleteBookmark(tweetId: string): Promise<TweetV2BookmarkResult>;
/**
* Allows a user ID to follow another user.
* If the target user does not have public Tweets, this endpoint will send a follow request.
* https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/post-users-source_user_id-following
*
* OAuth2 scope: `follows.write`
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
follow(loggedUserId: string, targetUserId: string): Promise<UserV2FollowResult>;
/**
* Allows a user ID to unfollow another user.
* https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/delete-users-source_id-following
*
* OAuth2 scope: `follows.write`
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
unfollow(loggedUserId: string, targetUserId: string): Promise<UserV2UnfollowResult>;
/**
* Causes the user (in the path) to block the target user.
* The user (in the path) must match the user context authorizing the request.
* https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/post-users-user_id-blocking
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
block(loggedUserId: string, targetUserId: string): Promise<UserV2BlockResult>;
/**
* Allows a user or authenticated user ID to unblock another user.
* https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/delete-users-user_id-blocking
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
unblock(loggedUserId: string, targetUserId: string): Promise<UserV2BlockResult>;
/**
* Allows an authenticated user ID to mute the target user.
* https://developer.twitter.com/en/docs/twitter-api/users/mutes/api-reference/post-users-user_id-muting
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
mute(loggedUserId: string, targetUserId: string): Promise<UserV2MuteResult>;
/**
* Allows an authenticated user ID to unmute the target user.
* The request succeeds with no action when the user sends a request to a user they're not muting or have already unmuted.
* https://developer.twitter.com/en/docs/twitter-api/users/mutes/api-reference/delete-users-user_id-muting
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
unmute(loggedUserId: string, targetUserId: string): Promise<UserV2MuteResult>;
/**
* Creates a new list for the authenticated user.
* https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/post-lists
*/
createList(options: ListCreateV2Params): Promise<ListCreateV2Result>;
/**
* Updates the specified list. The authenticated user must own the list to be able to update it.
* https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/put-lists-id
*/
updateList(listId: string, options?: ListUpdateV2Params): Promise<ListUpdateV2Result>;
/**
* Deletes the specified list. The authenticated user must own the list to be able to destroy it.
* https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/delete-lists-id
*/
removeList(listId: string): Promise<ListDeleteV2Result>;
/**
* Adds a member to a list.
* https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/post-lists-id-members
*/
addListMember(listId: string, userId: string): Promise<ListMemberV2Result>;
/**
* Remember a member to a list.
* https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/delete-lists-id-members-user_id
*/
removeListMember(listId: string, userId: string): Promise<ListMemberV2Result>;
/**
* Subscribes the authenticated user to the specified list.
* https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/post-users-id-followed-lists
*/
subscribeToList(loggedUserId: string, listId: string): Promise<ListFollowV2Result>;
/**
* Unsubscribes the authenticated user to the specified list.
* https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/delete-users-id-followed-lists-list_id
*/
unsubscribeOfList(loggedUserId: string, listId: string): Promise<ListFollowV2Result>;
/**
* Enables the authenticated user to pin a List.
* https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/post-users-id-pinned-lists
*/
pinList(loggedUserId: string, listId: string): Promise<ListPinV2Result>;
/**
* Enables the authenticated user to unpin a List.
* https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/delete-users-id-pinned-lists-list_id
*/
unpinList(loggedUserId: string, listId: string): Promise<ListPinV2Result>;
}

View File

@@ -0,0 +1,296 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const globals_1 = require("../globals");
const client_v2_read_1 = __importDefault(require("./client.v2.read"));
const client_v2_labs_write_1 = __importDefault(require("../v2-labs/client.v2.labs.write"));
/**
* Base Twitter v2 client with read/write rights.
*/
class TwitterApiv2ReadWrite extends client_v2_read_1.default {
constructor() {
super(...arguments);
this._prefix = globals_1.API_V2_PREFIX;
}
/* Sub-clients */
/**
* Get a client with only read rights.
*/
get readOnly() {
return this;
}
/**
* Get a client for v2 labs endpoints.
*/
get labs() {
if (this._labs)
return this._labs;
return this._labs = new client_v2_labs_write_1.default(this);
}
/* Tweets */
/**
* Hides or unhides a reply to a Tweet.
* https://developer.twitter.com/en/docs/twitter-api/tweets/hide-replies/api-reference/put-tweets-id-hidden
*/
hideReply(tweetId, makeHidden) {
return this.put('tweets/:id/hidden', { hidden: makeHidden }, { params: { id: tweetId } });
}
/**
* Causes the user ID identified in the path parameter to Like the target Tweet.
* https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/post-users-user_id-likes
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
like(loggedUserId, targetTweetId) {
return this.post('users/:id/likes', { tweet_id: targetTweetId }, { params: { id: loggedUserId } });
}
/**
* Allows a user or authenticated user ID to unlike a Tweet.
* The request succeeds with no action when the user sends a request to a user they're not liking the Tweet or have already unliked the Tweet.
* https://developer.twitter.com/en/docs/twitter-api/tweets/likes/api-reference/delete-users-id-likes-tweet_id
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
unlike(loggedUserId, targetTweetId) {
return this.delete('users/:id/likes/:tweet_id', undefined, {
params: { id: loggedUserId, tweet_id: targetTweetId },
});
}
/**
* Causes the user ID identified in the path parameter to Retweet the target Tweet.
* https://developer.twitter.com/en/docs/twitter-api/tweets/retweets/api-reference/post-users-id-retweets
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
retweet(loggedUserId, targetTweetId) {
return this.post('users/:id/retweets', { tweet_id: targetTweetId }, { params: { id: loggedUserId } });
}
/**
* Allows a user or authenticated user ID to remove the Retweet of a Tweet.
* The request succeeds with no action when the user sends a request to a user they're not Retweeting the Tweet or have already removed the Retweet of.
* https://developer.twitter.com/en/docs/twitter-api/tweets/retweets/api-reference/delete-users-id-retweets-tweet_id
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
unretweet(loggedUserId, targetTweetId) {
return this.delete('users/:id/retweets/:tweet_id', undefined, {
params: { id: loggedUserId, tweet_id: targetTweetId },
});
}
tweet(status, payload = {}) {
if (typeof status === 'object') {
payload = status;
}
else {
payload = { text: status, ...payload };
}
return this.post('tweets', payload);
}
/**
* Reply to a Tweet on behalf of an authenticated user.
* https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/post-tweets
*/
reply(status, toTweetId, payload = {}) {
var _a;
const reply = { in_reply_to_tweet_id: toTweetId, ...(_a = payload.reply) !== null && _a !== void 0 ? _a : {} };
return this.post('tweets', { text: status, ...payload, reply });
}
/**
* Quote an existing Tweet on behalf of an authenticated user.
* https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/post-tweets
*/
quote(status, quotedTweetId, payload = {}) {
return this.tweet(status, { ...payload, quote_tweet_id: quotedTweetId });
}
/**
* Post a series of tweets.
* https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/post-tweets
*/
async tweetThread(tweets) {
var _a, _b;
const postedTweets = [];
for (const tweet of tweets) {
// Retrieve the last sent tweet
const lastTweet = postedTweets.length ? postedTweets[postedTweets.length - 1] : null;
// Build the tweet query params
const queryParams = { ...(typeof tweet === 'string' ? ({ text: tweet }) : tweet) };
// Reply to an existing tweet if needed
const inReplyToId = lastTweet ? lastTweet.data.id : (_a = queryParams.reply) === null || _a === void 0 ? void 0 : _a.in_reply_to_tweet_id;
const status = (_b = queryParams.text) !== null && _b !== void 0 ? _b : '';
if (inReplyToId) {
postedTweets.push(await this.reply(status, inReplyToId, queryParams));
}
else {
postedTweets.push(await this.tweet(status, queryParams));
}
}
return postedTweets;
}
/**
* Allows a user or authenticated user ID to delete a Tweet
* https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/delete-tweets-id
*/
deleteTweet(tweetId) {
return this.delete('tweets/:id', undefined, {
params: {
id: tweetId,
},
});
}
/* Bookmarks */
/**
* Causes the user ID of an authenticated user identified in the path parameter to Bookmark the target Tweet provided in the request body.
* https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/api-reference/post-users-id-bookmarks
*
* OAuth2 scopes: `users.read` `tweet.read` `bookmark.write`
*/
async bookmark(tweetId) {
const user = await this.getCurrentUserV2Object();
return this.post('users/:id/bookmarks', { tweet_id: tweetId }, { params: { id: user.data.id } });
}
/**
* Allows a user or authenticated user ID to remove a Bookmark of a Tweet.
* https://developer.twitter.com/en/docs/twitter-api/tweets/bookmarks/api-reference/delete-users-id-bookmarks-tweet_id
*
* OAuth2 scopes: `users.read` `tweet.read` `bookmark.write`
*/
async deleteBookmark(tweetId) {
const user = await this.getCurrentUserV2Object();
return this.delete('users/:id/bookmarks/:tweet_id', undefined, { params: { id: user.data.id, tweet_id: tweetId } });
}
/* Users */
/**
* Allows a user ID to follow another user.
* If the target user does not have public Tweets, this endpoint will send a follow request.
* https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/post-users-source_user_id-following
*
* OAuth2 scope: `follows.write`
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
follow(loggedUserId, targetUserId) {
return this.post('users/:id/following', { target_user_id: targetUserId }, { params: { id: loggedUserId } });
}
/**
* Allows a user ID to unfollow another user.
* https://developer.twitter.com/en/docs/twitter-api/users/follows/api-reference/delete-users-source_id-following
*
* OAuth2 scope: `follows.write`
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
unfollow(loggedUserId, targetUserId) {
return this.delete('users/:source_user_id/following/:target_user_id', undefined, {
params: { source_user_id: loggedUserId, target_user_id: targetUserId },
});
}
/**
* Causes the user (in the path) to block the target user.
* The user (in the path) must match the user context authorizing the request.
* https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/post-users-user_id-blocking
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
block(loggedUserId, targetUserId) {
return this.post('users/:id/blocking', { target_user_id: targetUserId }, { params: { id: loggedUserId } });
}
/**
* Allows a user or authenticated user ID to unblock another user.
* https://developer.twitter.com/en/docs/twitter-api/users/blocks/api-reference/delete-users-user_id-blocking
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
unblock(loggedUserId, targetUserId) {
return this.delete('users/:source_user_id/blocking/:target_user_id', undefined, {
params: { source_user_id: loggedUserId, target_user_id: targetUserId },
});
}
/**
* Allows an authenticated user ID to mute the target user.
* https://developer.twitter.com/en/docs/twitter-api/users/mutes/api-reference/post-users-user_id-muting
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
mute(loggedUserId, targetUserId) {
return this.post('users/:id/muting', { target_user_id: targetUserId }, { params: { id: loggedUserId } });
}
/**
* Allows an authenticated user ID to unmute the target user.
* The request succeeds with no action when the user sends a request to a user they're not muting or have already unmuted.
* https://developer.twitter.com/en/docs/twitter-api/users/mutes/api-reference/delete-users-user_id-muting
*
* **Note**: You must specify the currently logged user ID ; you can obtain it through v1.1 API.
*/
unmute(loggedUserId, targetUserId) {
return this.delete('users/:source_user_id/muting/:target_user_id', undefined, {
params: { source_user_id: loggedUserId, target_user_id: targetUserId },
});
}
/* Lists */
/**
* Creates a new list for the authenticated user.
* https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/post-lists
*/
createList(options) {
return this.post('lists', options);
}
/**
* Updates the specified list. The authenticated user must own the list to be able to update it.
* https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/put-lists-id
*/
updateList(listId, options = {}) {
return this.put('lists/:id', options, { params: { id: listId } });
}
/**
* Deletes the specified list. The authenticated user must own the list to be able to destroy it.
* https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/delete-lists-id
*/
removeList(listId) {
return this.delete('lists/:id', undefined, { params: { id: listId } });
}
/**
* Adds a member to a list.
* https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/post-lists-id-members
*/
addListMember(listId, userId) {
return this.post('lists/:id/members', { user_id: userId }, { params: { id: listId } });
}
/**
* Remember a member to a list.
* https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/delete-lists-id-members-user_id
*/
removeListMember(listId, userId) {
return this.delete('lists/:id/members/:user_id', undefined, { params: { id: listId, user_id: userId } });
}
/**
* Subscribes the authenticated user to the specified list.
* https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/post-users-id-followed-lists
*/
subscribeToList(loggedUserId, listId) {
return this.post('users/:id/followed_lists', { list_id: listId }, { params: { id: loggedUserId } });
}
/**
* Unsubscribes the authenticated user to the specified list.
* https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/delete-users-id-followed-lists-list_id
*/
unsubscribeOfList(loggedUserId, listId) {
return this.delete('users/:id/followed_lists/:list_id', undefined, { params: { id: loggedUserId, list_id: listId } });
}
/**
* Enables the authenticated user to pin a List.
* https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/post-users-id-pinned-lists
*/
pinList(loggedUserId, listId) {
return this.post('users/:id/pinned_lists', { list_id: listId }, { params: { id: loggedUserId } });
}
/**
* Enables the authenticated user to unpin a List.
* https://developer.twitter.com/en/docs/twitter-api/lists/manage-lists/api-reference/delete-users-id-pinned-lists-list_id
*/
unpinList(loggedUserId, listId) {
return this.delete('users/:id/pinned_lists/:list_id', undefined, { params: { id: loggedUserId, list_id: listId } });
}
}
exports.default = TwitterApiv2ReadWrite;

View File

@@ -0,0 +1,82 @@
import type { ApiV2Includes, ListV2, SpaceV2, TweetV2, UserV2 } from '../types';
export declare type TTwitterV2IncludesResult = {
includes?: ApiV2Includes;
};
/**
* Provide helpers for `.includes` of a v2 API result.
* Needed expansions for a method to work are specified (*`like this`*).
*/
export declare class TwitterV2IncludesHelper implements ApiV2Includes {
protected result: TTwitterV2IncludesResult;
constructor(result: TTwitterV2IncludesResult);
get tweets(): TweetV2[];
static tweets(result: TTwitterV2IncludesResult): TweetV2[];
tweetById(id: string): TweetV2 | undefined;
static tweetById(result: TTwitterV2IncludesResult, id: string): TweetV2 | undefined;
/** Retweet associated with the given tweet (*`referenced_tweets.id`*) */
retweet(tweet: TweetV2): TweetV2 | undefined;
/** Retweet associated with the given tweet (*`referenced_tweets.id`*) */
static retweet(result: TTwitterV2IncludesResult, tweet: TweetV2): TweetV2 | undefined;
/** Quoted tweet associated with the given tweet (*`referenced_tweets.id`*) */
quote(tweet: TweetV2): TweetV2 | undefined;
/** Quoted tweet associated with the given tweet (*`referenced_tweets.id`*) */
static quote(result: TTwitterV2IncludesResult, tweet: TweetV2): TweetV2 | undefined;
/** Tweet whose has been answered by the given tweet (*`referenced_tweets.id`*) */
repliedTo(tweet: TweetV2): TweetV2 | undefined;
/** Tweet whose has been answered by the given tweet (*`referenced_tweets.id`*) */
static repliedTo(result: TTwitterV2IncludesResult, tweet: TweetV2): TweetV2 | undefined;
/** Tweet author user object of the given tweet (*`author_id`* or *`referenced_tweets.id.author_id`*) */
author(tweet: TweetV2): UserV2 | undefined;
/** Tweet author user object of the given tweet (*`author_id`* or *`referenced_tweets.id.author_id`*) */
static author(result: TTwitterV2IncludesResult, tweet: TweetV2): UserV2 | undefined;
/** Tweet author user object of the tweet answered by the given tweet (*`in_reply_to_user_id`*) */
repliedToAuthor(tweet: TweetV2): UserV2 | undefined;
/** Tweet author user object of the tweet answered by the given tweet (*`in_reply_to_user_id`*) */
static repliedToAuthor(result: TTwitterV2IncludesResult, tweet: TweetV2): UserV2 | undefined;
get users(): UserV2[];
static users(result: TTwitterV2IncludesResult): UserV2[];
userById(id: string): UserV2 | undefined;
static userById(result: TTwitterV2IncludesResult, id: string): UserV2 | undefined;
/** Pinned tweet of the given user (*`pinned_tweet_id`*) */
pinnedTweet(user: UserV2): TweetV2 | undefined;
/** Pinned tweet of the given user (*`pinned_tweet_id`*) */
static pinnedTweet(result: TTwitterV2IncludesResult, user: UserV2): TweetV2 | undefined;
get media(): import("../types").MediaObjectV2[];
static media(result: TTwitterV2IncludesResult): import("../types").MediaObjectV2[];
/** Medias associated with the given tweet (*`attachments.media_keys`*) */
medias(tweet: TweetV2): import("../types").MediaObjectV2[];
/** Medias associated with the given tweet (*`attachments.media_keys`*) */
static medias(result: TTwitterV2IncludesResult, tweet: TweetV2): import("../types").MediaObjectV2[];
get polls(): import("../types").PollV2[];
static polls(result: TTwitterV2IncludesResult): import("../types").PollV2[];
/** Poll associated with the given tweet (*`attachments.poll_ids`*) */
poll(tweet: TweetV2): import("../types").PollV2 | undefined;
/** Poll associated with the given tweet (*`attachments.poll_ids`*) */
static poll(result: TTwitterV2IncludesResult, tweet: TweetV2): import("../types").PollV2 | undefined;
get places(): import("../types").PlaceV2[];
static places(result: TTwitterV2IncludesResult): import("../types").PlaceV2[];
/** Place associated with the given tweet (*`geo.place_id`*) */
place(tweet: TweetV2): import("../types").PlaceV2 | undefined;
/** Place associated with the given tweet (*`geo.place_id`*) */
static place(result: TTwitterV2IncludesResult, tweet: TweetV2): import("../types").PlaceV2 | undefined;
/** List owner of the given list (*`owner_id`*) */
listOwner(list: ListV2): UserV2 | undefined;
/** List owner of the given list (*`owner_id`*) */
static listOwner(result: TTwitterV2IncludesResult, list: ListV2): UserV2 | undefined;
/** Creator of the given space (*`creator_id`*) */
spaceCreator(space: SpaceV2): UserV2 | undefined;
/** Creator of the given space (*`creator_id`*) */
static spaceCreator(result: TTwitterV2IncludesResult, space: SpaceV2): UserV2 | undefined;
/** Current hosts of the given space (*`host_ids`*) */
spaceHosts(space: SpaceV2): UserV2[];
/** Current hosts of the given space (*`host_ids`*) */
static spaceHosts(result: TTwitterV2IncludesResult, space: SpaceV2): UserV2[];
/** Current speakers of the given space (*`speaker_ids`*) */
spaceSpeakers(space: SpaceV2): UserV2[];
/** Current speakers of the given space (*`speaker_ids`*) */
static spaceSpeakers(result: TTwitterV2IncludesResult, space: SpaceV2): UserV2[];
/** Current invited users of the given space (*`invited_user_ids`*) */
spaceInvitedUsers(space: SpaceV2): UserV2[];
/** Current invited users of the given space (*`invited_user_ids`*) */
static spaceInvitedUsers(result: TTwitterV2IncludesResult, space: SpaceV2): UserV2[];
}

View File

@@ -0,0 +1,211 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TwitterV2IncludesHelper = void 0;
/**
* Provide helpers for `.includes` of a v2 API result.
* Needed expansions for a method to work are specified (*`like this`*).
*/
class TwitterV2IncludesHelper {
constructor(result) {
this.result = result;
}
/* Tweets */
get tweets() {
return TwitterV2IncludesHelper.tweets(this.result);
}
static tweets(result) {
var _a, _b;
return (_b = (_a = result.includes) === null || _a === void 0 ? void 0 : _a.tweets) !== null && _b !== void 0 ? _b : [];
}
tweetById(id) {
return TwitterV2IncludesHelper.tweetById(this.result, id);
}
static tweetById(result, id) {
return this.tweets(result).find(tweet => tweet.id === id);
}
/** Retweet associated with the given tweet (*`referenced_tweets.id`*) */
retweet(tweet) {
return TwitterV2IncludesHelper.retweet(this.result, tweet);
}
/** Retweet associated with the given tweet (*`referenced_tweets.id`*) */
static retweet(result, tweet) {
var _a;
const retweetIds = ((_a = tweet.referenced_tweets) !== null && _a !== void 0 ? _a : [])
.filter(ref => ref.type === 'retweeted')
.map(ref => ref.id);
return this.tweets(result).find(t => retweetIds.includes(t.id));
}
/** Quoted tweet associated with the given tweet (*`referenced_tweets.id`*) */
quote(tweet) {
return TwitterV2IncludesHelper.quote(this.result, tweet);
}
/** Quoted tweet associated with the given tweet (*`referenced_tweets.id`*) */
static quote(result, tweet) {
var _a;
const quoteIds = ((_a = tweet.referenced_tweets) !== null && _a !== void 0 ? _a : [])
.filter(ref => ref.type === 'quoted')
.map(ref => ref.id);
return this.tweets(result).find(t => quoteIds.includes(t.id));
}
/** Tweet whose has been answered by the given tweet (*`referenced_tweets.id`*) */
repliedTo(tweet) {
return TwitterV2IncludesHelper.repliedTo(this.result, tweet);
}
/** Tweet whose has been answered by the given tweet (*`referenced_tweets.id`*) */
static repliedTo(result, tweet) {
var _a;
const repliesIds = ((_a = tweet.referenced_tweets) !== null && _a !== void 0 ? _a : [])
.filter(ref => ref.type === 'replied_to')
.map(ref => ref.id);
return this.tweets(result).find(t => repliesIds.includes(t.id));
}
/** Tweet author user object of the given tweet (*`author_id`* or *`referenced_tweets.id.author_id`*) */
author(tweet) {
return TwitterV2IncludesHelper.author(this.result, tweet);
}
/** Tweet author user object of the given tweet (*`author_id`* or *`referenced_tweets.id.author_id`*) */
static author(result, tweet) {
const authorId = tweet.author_id;
return authorId ? this.users(result).find(u => u.id === authorId) : undefined;
}
/** Tweet author user object of the tweet answered by the given tweet (*`in_reply_to_user_id`*) */
repliedToAuthor(tweet) {
return TwitterV2IncludesHelper.repliedToAuthor(this.result, tweet);
}
/** Tweet author user object of the tweet answered by the given tweet (*`in_reply_to_user_id`*) */
static repliedToAuthor(result, tweet) {
const inReplyUserId = tweet.in_reply_to_user_id;
return inReplyUserId ? this.users(result).find(u => u.id === inReplyUserId) : undefined;
}
/* Users */
get users() {
return TwitterV2IncludesHelper.users(this.result);
}
static users(result) {
var _a, _b;
return (_b = (_a = result.includes) === null || _a === void 0 ? void 0 : _a.users) !== null && _b !== void 0 ? _b : [];
}
userById(id) {
return TwitterV2IncludesHelper.userById(this.result, id);
}
static userById(result, id) {
return this.users(result).find(u => u.id === id);
}
/** Pinned tweet of the given user (*`pinned_tweet_id`*) */
pinnedTweet(user) {
return TwitterV2IncludesHelper.pinnedTweet(this.result, user);
}
/** Pinned tweet of the given user (*`pinned_tweet_id`*) */
static pinnedTweet(result, user) {
return user.pinned_tweet_id ? this.tweets(result).find(t => t.id === user.pinned_tweet_id) : undefined;
}
/* Medias */
get media() {
return TwitterV2IncludesHelper.media(this.result);
}
static media(result) {
var _a, _b;
return (_b = (_a = result.includes) === null || _a === void 0 ? void 0 : _a.media) !== null && _b !== void 0 ? _b : [];
}
/** Medias associated with the given tweet (*`attachments.media_keys`*) */
medias(tweet) {
return TwitterV2IncludesHelper.medias(this.result, tweet);
}
/** Medias associated with the given tweet (*`attachments.media_keys`*) */
static medias(result, tweet) {
var _a, _b;
const keys = (_b = (_a = tweet.attachments) === null || _a === void 0 ? void 0 : _a.media_keys) !== null && _b !== void 0 ? _b : [];
return this.media(result).filter(m => keys.includes(m.media_key));
}
/* Polls */
get polls() {
return TwitterV2IncludesHelper.polls(this.result);
}
static polls(result) {
var _a, _b;
return (_b = (_a = result.includes) === null || _a === void 0 ? void 0 : _a.polls) !== null && _b !== void 0 ? _b : [];
}
/** Poll associated with the given tweet (*`attachments.poll_ids`*) */
poll(tweet) {
return TwitterV2IncludesHelper.poll(this.result, tweet);
}
/** Poll associated with the given tweet (*`attachments.poll_ids`*) */
static poll(result, tweet) {
var _a, _b;
const pollIds = (_b = (_a = tweet.attachments) === null || _a === void 0 ? void 0 : _a.poll_ids) !== null && _b !== void 0 ? _b : [];
if (pollIds.length) {
const pollId = pollIds[0];
return this.polls(result).find(p => p.id === pollId);
}
return undefined;
}
/* Places */
get places() {
return TwitterV2IncludesHelper.places(this.result);
}
static places(result) {
var _a, _b;
return (_b = (_a = result.includes) === null || _a === void 0 ? void 0 : _a.places) !== null && _b !== void 0 ? _b : [];
}
/** Place associated with the given tweet (*`geo.place_id`*) */
place(tweet) {
return TwitterV2IncludesHelper.place(this.result, tweet);
}
/** Place associated with the given tweet (*`geo.place_id`*) */
static place(result, tweet) {
var _a;
const placeId = (_a = tweet.geo) === null || _a === void 0 ? void 0 : _a.place_id;
return placeId ? this.places(result).find(p => p.id === placeId) : undefined;
}
/* Lists */
/** List owner of the given list (*`owner_id`*) */
listOwner(list) {
return TwitterV2IncludesHelper.listOwner(this.result, list);
}
/** List owner of the given list (*`owner_id`*) */
static listOwner(result, list) {
const creatorId = list.owner_id;
return creatorId ? this.users(result).find(p => p.id === creatorId) : undefined;
}
/* Spaces */
/** Creator of the given space (*`creator_id`*) */
spaceCreator(space) {
return TwitterV2IncludesHelper.spaceCreator(this.result, space);
}
/** Creator of the given space (*`creator_id`*) */
static spaceCreator(result, space) {
const creatorId = space.creator_id;
return creatorId ? this.users(result).find(p => p.id === creatorId) : undefined;
}
/** Current hosts of the given space (*`host_ids`*) */
spaceHosts(space) {
return TwitterV2IncludesHelper.spaceHosts(this.result, space);
}
/** Current hosts of the given space (*`host_ids`*) */
static spaceHosts(result, space) {
var _a;
const hostIds = (_a = space.host_ids) !== null && _a !== void 0 ? _a : [];
return this.users(result).filter(u => hostIds.includes(u.id));
}
/** Current speakers of the given space (*`speaker_ids`*) */
spaceSpeakers(space) {
return TwitterV2IncludesHelper.spaceSpeakers(this.result, space);
}
/** Current speakers of the given space (*`speaker_ids`*) */
static spaceSpeakers(result, space) {
var _a;
const speakerIds = (_a = space.speaker_ids) !== null && _a !== void 0 ? _a : [];
return this.users(result).filter(u => speakerIds.includes(u.id));
}
/** Current invited users of the given space (*`invited_user_ids`*) */
spaceInvitedUsers(space) {
return TwitterV2IncludesHelper.spaceInvitedUsers(this.result, space);
}
/** Current invited users of the given space (*`invited_user_ids`*) */
static spaceInvitedUsers(result, space) {
var _a;
const invitedUserIds = (_a = space.invited_user_ids) !== null && _a !== void 0 ? _a : [];
return this.users(result).filter(u => invitedUserIds.includes(u.id));
}
}
exports.TwitterV2IncludesHelper = TwitterV2IncludesHelper;