rettiwt-api 2.7.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +73 -5
- package/.tool-versions +1 -0
- package/README.md +87 -20
- package/dist/Rettiwt.js +0 -1
- package/dist/Rettiwt.js.map +1 -1
- package/dist/cli.js +2 -4
- package/dist/cli.js.map +1 -1
- package/dist/collections/Extractors.d.ts +10 -0
- package/dist/collections/Extractors.js +43 -0
- package/dist/collections/Extractors.js.map +1 -0
- package/dist/collections/Groups.d.ts +19 -0
- package/dist/collections/Groups.js +55 -0
- package/dist/collections/Groups.js.map +1 -0
- package/dist/collections/Requests.d.ts +12 -0
- package/dist/collections/Requests.js +46 -0
- package/dist/collections/Requests.js.map +1 -0
- package/dist/commands/Auth.d.ts +6 -0
- package/dist/commands/Auth.js +26 -8
- package/dist/commands/Auth.js.map +1 -1
- package/dist/commands/Tweet.js +237 -82
- package/dist/commands/Tweet.js.map +1 -1
- package/dist/commands/User.js +197 -36
- package/dist/commands/User.js.map +1 -1
- package/dist/enums/Api.d.ts +30 -0
- package/dist/enums/Api.js +32 -1
- package/dist/enums/Api.js.map +1 -1
- package/dist/enums/Data.d.ts +9 -0
- package/dist/enums/Data.js +14 -0
- package/dist/enums/Data.js.map +1 -0
- package/dist/enums/Http.d.ts +1 -1
- package/dist/enums/Http.js +1 -1
- package/dist/enums/Logging.d.ts +6 -5
- package/dist/enums/Logging.js +6 -5
- package/dist/enums/Logging.js.map +1 -1
- package/dist/enums/Resource.d.ts +33 -0
- package/dist/enums/Resource.js +42 -0
- package/dist/enums/Resource.js.map +1 -0
- package/dist/helper/CliUtils.d.ts +1 -1
- package/dist/helper/CliUtils.js.map +1 -1
- package/dist/index.d.ts +11 -9
- package/dist/index.js +11 -14
- package/dist/index.js.map +1 -1
- package/dist/models/args/FetchArgs.d.ts +129 -0
- package/dist/models/args/FetchArgs.js +263 -0
- package/dist/models/args/FetchArgs.js.map +1 -0
- package/dist/models/args/PostArgs.d.ts +116 -0
- package/dist/models/args/PostArgs.js +232 -0
- package/dist/models/args/PostArgs.js.map +1 -0
- package/dist/models/data/CursoredData.d.ts +11 -11
- package/dist/models/data/CursoredData.js +21 -16
- package/dist/models/data/CursoredData.js.map +1 -1
- package/dist/models/data/List.d.ts +8 -10
- package/dist/models/data/List.js +2 -4
- package/dist/models/data/List.js.map +1 -1
- package/dist/models/data/Tweet.d.ts +41 -29
- package/dist/models/data/Tweet.js +71 -15
- package/dist/models/data/Tweet.js.map +1 -1
- package/dist/models/data/User.d.ts +36 -20
- package/dist/models/data/User.js +69 -7
- package/dist/models/data/User.js.map +1 -1
- package/dist/models/errors/ApiError.d.ts +1 -3
- package/dist/models/errors/ApiError.js +1 -4
- package/dist/models/errors/ApiError.js.map +1 -1
- package/dist/models/errors/DataValidationError.d.ts +30 -0
- package/dist/models/errors/DataValidationError.js +34 -0
- package/dist/models/errors/DataValidationError.js.map +1 -0
- package/dist/models/errors/HttpError.d.ts +1 -3
- package/dist/models/errors/HttpError.js +1 -4
- package/dist/models/errors/HttpError.js.map +1 -1
- package/dist/models/errors/TimeoutError.d.ts +2 -4
- package/dist/models/errors/TimeoutError.js +2 -5
- package/dist/models/errors/TimeoutError.js.map +1 -1
- package/dist/services/internal/ErrorService.d.ts +45 -35
- package/dist/services/internal/ErrorService.js +70 -68
- package/dist/services/internal/ErrorService.js.map +1 -1
- package/dist/services/internal/LogService.d.ts +7 -5
- package/dist/services/internal/LogService.js +28 -9
- package/dist/services/internal/LogService.js.map +1 -1
- package/dist/services/public/AuthService.d.ts +24 -20
- package/dist/services/public/AuthService.js +38 -36
- package/dist/services/public/AuthService.js.map +1 -1
- package/dist/services/public/FetcherService.d.ts +99 -0
- package/dist/services/public/FetcherService.js +254 -0
- package/dist/services/public/FetcherService.js.map +1 -0
- package/dist/services/public/TweetService.d.ts +213 -94
- package/dist/services/public/TweetService.js +405 -208
- package/dist/services/public/TweetService.js.map +1 -1
- package/dist/services/public/UserService.d.ts +185 -52
- package/dist/services/public/UserService.js +333 -103
- package/dist/services/public/UserService.js.map +1 -1
- package/dist/types/ReturnTypes.d.ts +21 -0
- package/dist/types/ReturnTypes.js +3 -0
- package/dist/types/ReturnTypes.js.map +1 -0
- package/package.json +4 -2
- package/src/Rettiwt.ts +0 -3
- package/src/cli.ts +2 -4
- package/src/collections/Extractors.ts +63 -0
- package/src/collections/Groups.ts +54 -0
- package/src/collections/Requests.ts +52 -0
- package/src/commands/Auth.ts +19 -7
- package/src/commands/Tweet.ts +179 -91
- package/src/commands/User.ts +118 -25
- package/src/enums/Api.ts +31 -0
- package/src/enums/Data.ts +9 -0
- package/src/enums/Http.ts +1 -1
- package/src/enums/Logging.ts +6 -5
- package/src/enums/Resource.ts +40 -0
- package/src/helper/CliUtils.ts +1 -1
- package/src/index.ts +41 -14
- package/src/models/args/FetchArgs.ts +296 -0
- package/src/models/args/PostArgs.ts +263 -0
- package/src/models/data/CursoredData.ts +23 -15
- package/src/models/data/List.ts +12 -15
- package/src/models/data/Tweet.ts +105 -39
- package/src/models/data/User.ts +97 -30
- package/src/models/errors/ApiError.ts +1 -4
- package/src/models/errors/DataValidationError.ts +44 -0
- package/src/models/errors/HttpError.ts +1 -4
- package/src/models/errors/TimeoutError.ts +2 -5
- package/src/services/internal/ErrorService.ts +76 -75
- package/src/services/internal/LogService.ts +20 -10
- package/src/services/public/AuthService.ts +39 -38
- package/src/services/public/FetcherService.ts +230 -0
- package/src/services/public/TweetService.ts +381 -179
- package/src/services/public/UserService.ts +314 -86
- package/src/types/RettiwtConfig.ts +0 -1
- package/src/types/ReturnTypes.ts +24 -0
- package/dist/models/args/TweetArgs.d.ts +0 -44
- package/dist/models/args/TweetArgs.js +0 -82
- package/dist/models/args/TweetArgs.js.map +0 -1
- package/dist/models/data/Media.d.ts +0 -14
- package/dist/models/data/Media.js +0 -19
- package/dist/models/data/Media.js.map +0 -1
- package/dist/services/internal/FetcherService.d.ts +0 -106
- package/dist/services/internal/FetcherService.js +0 -365
- package/dist/services/internal/FetcherService.js.map +0 -1
- package/src/models/args/TweetArgs.ts +0 -98
- package/src/models/data/Media.ts +0 -19
- package/src/services/internal/FetcherService.ts +0 -365
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rettiwt-api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"description": "An API for fetching data from TwitterAPI, without any rate limits!",
|
|
@@ -30,17 +30,19 @@
|
|
|
30
30
|
"homepage": "https://rishikant181.github.io/Rettiwt-API/",
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"axios": "1.6.3",
|
|
33
|
+
"chalk": "4.1.2",
|
|
33
34
|
"class-validator": "0.14.1",
|
|
34
35
|
"commander": "11.1.0",
|
|
35
36
|
"https-proxy-agent": "7.0.2",
|
|
36
37
|
"rettiwt-auth": "2.1.0",
|
|
37
|
-
"rettiwt-core": "
|
|
38
|
+
"rettiwt-core": "4.0.0"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@types/node": "20.4.1",
|
|
41
42
|
"@typescript-eslint/eslint-plugin": "6.0.0",
|
|
42
43
|
"@typescript-eslint/parser": "6.0.0",
|
|
43
44
|
"eslint": "8.44.0",
|
|
45
|
+
"eslint-plugin-import": "2.29.1",
|
|
44
46
|
"eslint-plugin-tsdoc": "0.2.17",
|
|
45
47
|
"nodemon": "2.0.20",
|
|
46
48
|
"prettier": "3.0.0",
|
package/src/Rettiwt.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
// SERVICES
|
|
2
1
|
import { AuthService } from './services/public/AuthService';
|
|
3
2
|
import { TweetService } from './services/public/TweetService';
|
|
4
3
|
import { UserService } from './services/public/UserService';
|
|
5
|
-
|
|
6
|
-
// TYPES
|
|
7
4
|
import { IRettiwtConfig } from './types/RettiwtConfig';
|
|
8
5
|
|
|
9
6
|
/**
|
package/src/cli.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
2
|
|
|
3
|
-
// PACKAGES
|
|
4
3
|
import { createCommand } from 'commander';
|
|
5
|
-
import { Rettiwt } from './Rettiwt';
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
import auth from './commands/Auth';
|
|
8
6
|
import tweet from './commands/Tweet';
|
|
9
7
|
import user from './commands/User';
|
|
10
|
-
import
|
|
8
|
+
import { Rettiwt } from './Rettiwt';
|
|
11
9
|
|
|
12
10
|
// Creating a new commandline program
|
|
13
11
|
const program = createCommand('rettiwt')
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IInitializeMediaUploadResponse,
|
|
3
|
+
IListDetailsResponse,
|
|
4
|
+
IResponse,
|
|
5
|
+
ITweetLikeResponse,
|
|
6
|
+
ITweetPostResponse,
|
|
7
|
+
ITweetRetweetResponse,
|
|
8
|
+
ITweetUnlikeResponse,
|
|
9
|
+
ITweetUnpostResponse,
|
|
10
|
+
ITweetUnretweetResponse,
|
|
11
|
+
IUserFollowResponse,
|
|
12
|
+
IUserUnfollowResponse,
|
|
13
|
+
} from 'rettiwt-core';
|
|
14
|
+
|
|
15
|
+
import { EBaseType } from '../enums/Data';
|
|
16
|
+
import { EResourceType } from '../enums/Resource';
|
|
17
|
+
import { CursoredData } from '../models/data/CursoredData';
|
|
18
|
+
import { Tweet } from '../models/data/Tweet';
|
|
19
|
+
import { User } from '../models/data/User';
|
|
20
|
+
import { AllReturnTypes } from '../types/ReturnTypes';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Collection of data extractors for each resource.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export const extractors: {
|
|
28
|
+
[key in keyof typeof EResourceType]: (response: NonNullable<unknown>) => AllReturnTypes | undefined;
|
|
29
|
+
} = {
|
|
30
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
31
|
+
LIST_TWEETS: (response) => new CursoredData<Tweet>(response as IListDetailsResponse, EBaseType.TWEET),
|
|
32
|
+
|
|
33
|
+
MEDIA_UPLOAD_APPEND: () => undefined,
|
|
34
|
+
MEDIA_UPLOAD_FINALIZE: () => undefined,
|
|
35
|
+
MEDIA_UPLOAD_INITIALIZE: (response) => (response as IInitializeMediaUploadResponse).media_id_string ?? undefined,
|
|
36
|
+
|
|
37
|
+
TWEET_DETAILS: (response) => Tweet.single(response as IResponse<unknown>),
|
|
38
|
+
TWEET_LIKE: (response) => ((response as ITweetLikeResponse)?.data?.favorite_tweet ? true : false),
|
|
39
|
+
TWEET_LIKERS: (response) => new CursoredData<User>(response as IResponse<unknown>, EBaseType.USER),
|
|
40
|
+
TWEET_POST: (response) =>
|
|
41
|
+
(response as ITweetPostResponse)?.data?.create_tweet?.tweet_results?.result?.rest_id ?? undefined,
|
|
42
|
+
TWEET_RETWEET: (response) => ((response as ITweetRetweetResponse)?.data?.create_retweet ? true : false),
|
|
43
|
+
TWEET_RETWEETERS: (response) => new CursoredData<User>(response as IResponse<unknown>, EBaseType.USER),
|
|
44
|
+
TWEET_SEARCH: (response) => new CursoredData<Tweet>(response as IResponse<unknown>, EBaseType.TWEET),
|
|
45
|
+
TWEET_UNLIKE: (response) => ((response as ITweetUnlikeResponse)?.data?.unfavorite_tweet ? true : false),
|
|
46
|
+
TWEET_UNPOST: (response) => ((response as ITweetUnpostResponse)?.data?.delete_tweet ? true : false),
|
|
47
|
+
TWEET_UNRETWEET: (response) =>
|
|
48
|
+
(response as ITweetUnretweetResponse)?.data?.unretweet?.source_tweet_results?.result ? true : false,
|
|
49
|
+
|
|
50
|
+
USER_DETAILS_BY_USERNAME: (response) => User.single(response as IResponse<unknown>),
|
|
51
|
+
USER_DETAILS_BY_ID: (response) => User.single(response as IResponse<unknown>),
|
|
52
|
+
USER_FOLLOW: (response) => ((response as IUserFollowResponse)?.id ? true : false),
|
|
53
|
+
USER_FOLLOWING: (response) => new CursoredData<User>(response as IResponse<unknown>, EBaseType.USER),
|
|
54
|
+
USER_FOLLOWERS: (response) => new CursoredData<User>(response as IResponse<unknown>, EBaseType.USER),
|
|
55
|
+
USER_HIGHLIGHTS: (response) => new CursoredData<Tweet>(response as IResponse<unknown>, EBaseType.TWEET),
|
|
56
|
+
USER_LIKES: (response) => new CursoredData<Tweet>(response as IResponse<unknown>, EBaseType.TWEET),
|
|
57
|
+
USER_MEDIA: (response) => new CursoredData<Tweet>(response as IResponse<unknown>, EBaseType.TWEET),
|
|
58
|
+
USER_SUBSCRIPTIONS: (response) => new CursoredData<User>(response as IResponse<unknown>, EBaseType.USER),
|
|
59
|
+
USER_TIMELINE: (response) => new CursoredData<Tweet>(response as IResponse<unknown>, EBaseType.TWEET),
|
|
60
|
+
USER_TIMELINE_AND_REPLIES: (response) => new CursoredData<Tweet>(response as IResponse<unknown>, EBaseType.TWEET),
|
|
61
|
+
USER_UNFOLLOW: (response) => ((response as IUserUnfollowResponse)?.id ? true : false),
|
|
62
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
63
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { EResourceType } from '../enums/Resource';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Collection of resources that allow guest authentication.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export const allowGuestAuthentication = [
|
|
9
|
+
EResourceType.TWEET_DETAILS,
|
|
10
|
+
EResourceType.USER_DETAILS_BY_USERNAME,
|
|
11
|
+
EResourceType.USER_TIMELINE,
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Collection of resources that can be fetched.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export const fetchResources = [
|
|
20
|
+
EResourceType.LIST_TWEETS,
|
|
21
|
+
EResourceType.TWEET_DETAILS,
|
|
22
|
+
EResourceType.TWEET_LIKERS,
|
|
23
|
+
EResourceType.TWEET_RETWEETERS,
|
|
24
|
+
EResourceType.TWEET_SEARCH,
|
|
25
|
+
EResourceType.USER_DETAILS_BY_USERNAME,
|
|
26
|
+
EResourceType.USER_DETAILS_BY_ID,
|
|
27
|
+
EResourceType.USER_FOLLOWING,
|
|
28
|
+
EResourceType.USER_FOLLOWERS,
|
|
29
|
+
EResourceType.USER_HIGHLIGHTS,
|
|
30
|
+
EResourceType.USER_LIKES,
|
|
31
|
+
EResourceType.USER_MEDIA,
|
|
32
|
+
EResourceType.USER_SUBSCRIPTIONS,
|
|
33
|
+
EResourceType.USER_TIMELINE,
|
|
34
|
+
EResourceType.USER_TIMELINE_AND_REPLIES,
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Collection of resources that can be posted.
|
|
39
|
+
*
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
export const postResources = [
|
|
43
|
+
EResourceType.MEDIA_UPLOAD_APPEND,
|
|
44
|
+
EResourceType.MEDIA_UPLOAD_FINALIZE,
|
|
45
|
+
EResourceType.MEDIA_UPLOAD_INITIALIZE,
|
|
46
|
+
EResourceType.TWEET_LIKE,
|
|
47
|
+
EResourceType.TWEET_POST,
|
|
48
|
+
EResourceType.TWEET_RETWEET,
|
|
49
|
+
EResourceType.TWEET_UNLIKE,
|
|
50
|
+
EResourceType.TWEET_UNPOST,
|
|
51
|
+
EResourceType.TWEET_UNRETWEET,
|
|
52
|
+
EResourceType.USER_FOLLOW,
|
|
53
|
+
EResourceType.USER_UNFOLLOW,
|
|
54
|
+
];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { Request } from 'rettiwt-core';
|
|
3
|
+
|
|
4
|
+
import { EResourceType } from '../enums/Resource';
|
|
5
|
+
import { FetchArgs } from '../models/args/FetchArgs';
|
|
6
|
+
import { PostArgs } from '../models/args/PostArgs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The request generator from rettiwt-core.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
const request = new Request();
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The collection of requests to various resources.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export const requests: { [key in keyof typeof EResourceType]: (args: FetchArgs | PostArgs) => AxiosRequestConfig } = {
|
|
21
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
22
|
+
LIST_TWEETS: (args: FetchArgs) => request.list.tweets(args.id!, args.count, args.cursor),
|
|
23
|
+
|
|
24
|
+
MEDIA_UPLOAD_APPEND: (args: PostArgs) => request.media.appendUpload(args.upload!.id!, args.upload!.media!),
|
|
25
|
+
MEDIA_UPLOAD_FINALIZE: (args: PostArgs) => request.media.finalizeUpload(args.upload!.id!),
|
|
26
|
+
MEDIA_UPLOAD_INITIALIZE: (args: PostArgs) => request.media.initializeUpload(args.upload!.size!),
|
|
27
|
+
|
|
28
|
+
TWEET_DETAILS: (args: FetchArgs) => request.tweet.details(args.id!),
|
|
29
|
+
TWEET_LIKE: (args: PostArgs) => request.tweet.like(args.id!),
|
|
30
|
+
TWEET_LIKERS: (args: FetchArgs) => request.tweet.likers(args.id!, args.count, args.cursor),
|
|
31
|
+
TWEET_POST: (args: PostArgs) => request.tweet.post(args.tweet!),
|
|
32
|
+
TWEET_RETWEET: (args: PostArgs) => request.tweet.retweet(args.id!),
|
|
33
|
+
TWEET_RETWEETERS: (args: FetchArgs) => request.tweet.retweeters(args.id!, args.count, args.cursor),
|
|
34
|
+
TWEET_SEARCH: (args: FetchArgs) => request.tweet.search(args.filter!, args.count, args.cursor),
|
|
35
|
+
TWEET_UNLIKE: (args: PostArgs) => request.tweet.unlike(args.id!),
|
|
36
|
+
TWEET_UNPOST: (args: PostArgs) => request.tweet.unpost(args.id!),
|
|
37
|
+
TWEET_UNRETWEET: (args: PostArgs) => request.tweet.unretweet(args.id!),
|
|
38
|
+
|
|
39
|
+
USER_DETAILS_BY_USERNAME: (args: FetchArgs) => request.user.detailsByUsername(args.id!),
|
|
40
|
+
USER_DETAILS_BY_ID: (args: FetchArgs) => request.user.detailsById(args.id!),
|
|
41
|
+
USER_FOLLOW: (args: PostArgs) => request.user.follow(args.id!),
|
|
42
|
+
USER_FOLLOWING: (args: FetchArgs) => request.user.following(args.id!, args.count, args.cursor),
|
|
43
|
+
USER_FOLLOWERS: (args: FetchArgs) => request.user.followers(args.id!, args.count, args.cursor),
|
|
44
|
+
USER_HIGHLIGHTS: (args: FetchArgs) => request.user.highlights(args.id!, args.count, args.cursor),
|
|
45
|
+
USER_LIKES: (args: FetchArgs) => request.user.likes(args.id!, args.count, args.cursor),
|
|
46
|
+
USER_MEDIA: (args: FetchArgs) => request.user.media(args.id!, args.count, args.cursor),
|
|
47
|
+
USER_SUBSCRIPTIONS: (args: FetchArgs) => request.user.subscriptions(args.id!, args.count, args.cursor),
|
|
48
|
+
USER_TIMELINE: (args: FetchArgs) => request.user.tweets(args.id!, args.count, args.cursor),
|
|
49
|
+
USER_TIMELINE_AND_REPLIES: (args: FetchArgs) => request.user.tweetsAndReplies(args.id!, args.count, args.cursor),
|
|
50
|
+
USER_UNFOLLOW: (args: PostArgs) => request.user.unfollow(args.id!),
|
|
51
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
52
|
+
};
|
package/src/commands/Auth.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
// PACKAGES
|
|
2
1
|
import { Command, createCommand } from 'commander';
|
|
3
|
-
import { Rettiwt } from '../Rettiwt';
|
|
4
2
|
|
|
5
|
-
// UTILITY
|
|
6
3
|
import { output } from '../helper/CliUtils';
|
|
4
|
+
import { Rettiwt } from '../Rettiwt';
|
|
7
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new 'auth' command which uses the given Rettiwt instance.
|
|
8
|
+
*
|
|
9
|
+
* @param rettiwt - The Rettiwt instance to use.
|
|
10
|
+
* @returns The created 'auth' command.
|
|
11
|
+
*/
|
|
8
12
|
function createAuthCommand(rettiwt: Rettiwt): Command {
|
|
9
13
|
// Creating the 'auth' command
|
|
10
14
|
const auth = createCommand('auth').description('Manage authentication');
|
|
@@ -16,16 +20,24 @@ function createAuthCommand(rettiwt: Rettiwt): Command {
|
|
|
16
20
|
.argument('<username>', 'The username associated with the Twitter account')
|
|
17
21
|
.argument('<password>', 'The password to the Twitter account')
|
|
18
22
|
.action(async (email: string, username: string, password: string) => {
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
try {
|
|
24
|
+
const apiKey: string = await rettiwt.auth.login(email, username, password);
|
|
25
|
+
output(apiKey);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
output(error);
|
|
28
|
+
}
|
|
21
29
|
});
|
|
22
30
|
|
|
23
31
|
// Guest
|
|
24
32
|
auth.command('guest')
|
|
25
33
|
.description('Generate a new guest key')
|
|
26
34
|
.action(async () => {
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
try {
|
|
36
|
+
const guestKey: string = await rettiwt.auth.guest();
|
|
37
|
+
output(guestKey);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
output(error);
|
|
40
|
+
}
|
|
29
41
|
});
|
|
30
42
|
|
|
31
43
|
return auth;
|
package/src/commands/Tweet.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
// PACKAGES
|
|
2
1
|
import { Command, createCommand } from 'commander';
|
|
3
|
-
import { Rettiwt } from '../Rettiwt';
|
|
4
2
|
import { TweetFilter } from 'rettiwt-core';
|
|
5
3
|
|
|
6
|
-
// UTILITY
|
|
7
4
|
import { output } from '../helper/CliUtils';
|
|
5
|
+
import { Rettiwt } from '../Rettiwt';
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
8
|
* Creates a new 'tweet' command which uses the given Rettiwt instance.
|
|
@@ -22,8 +20,113 @@ function createTweetCommand(rettiwt: Rettiwt): Command {
|
|
|
22
20
|
.description('Fetch the details of tweet with the given id')
|
|
23
21
|
.argument('<id>', 'The id of the tweet whose details are to be fetched')
|
|
24
22
|
.action(async (id: string) => {
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
try {
|
|
24
|
+
const details = await rettiwt.tweet.details(id);
|
|
25
|
+
output(details);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
output(error);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Like
|
|
32
|
+
tweet
|
|
33
|
+
.command('like')
|
|
34
|
+
.description('Like a tweet')
|
|
35
|
+
.argument('<id>', 'The tweet to like')
|
|
36
|
+
.action(async (id: string) => {
|
|
37
|
+
try {
|
|
38
|
+
const result = await rettiwt.tweet.like(id);
|
|
39
|
+
output(result);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
output(error);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Likers
|
|
46
|
+
tweet
|
|
47
|
+
.command('likers')
|
|
48
|
+
.description('Fetch the list of users who liked the given tweets')
|
|
49
|
+
.argument('<id>', 'The id of the tweet')
|
|
50
|
+
.argument('[count]', 'The number of likers to fetch')
|
|
51
|
+
.argument('[cursor]', 'The cursor to the batch of likers to fetch')
|
|
52
|
+
.action(async (id: string, count?: string, cursor?: string) => {
|
|
53
|
+
try {
|
|
54
|
+
const tweets = await rettiwt.tweet.likers(id, count ? parseInt(count) : undefined, cursor);
|
|
55
|
+
output(tweets);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
output(error);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// List
|
|
62
|
+
tweet
|
|
63
|
+
.command('list')
|
|
64
|
+
.description('Fetch the list of tweets in the tweet list with the given id')
|
|
65
|
+
.argument('<id>', 'The id of the tweet list')
|
|
66
|
+
.argument('[count]', 'The number of tweets to fetch')
|
|
67
|
+
.argument('[cursor]', 'The cursor to the batch of tweets to fetch')
|
|
68
|
+
.action(async (id: string, count?: string, cursor?: string) => {
|
|
69
|
+
try {
|
|
70
|
+
const tweets = await rettiwt.tweet.list(id, count ? parseInt(count) : undefined, cursor);
|
|
71
|
+
output(tweets);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
output(error);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Post
|
|
78
|
+
tweet
|
|
79
|
+
.command('post')
|
|
80
|
+
.description('Post a tweet (text only)')
|
|
81
|
+
.argument('<text>', 'The text to post as a tweet')
|
|
82
|
+
.option('-m, --media [string]', 'Comma-separated list of ids of the media item(s) to be posted')
|
|
83
|
+
.option('-q, --quote [string]', 'The id of the tweet to quote in the tweet to be posted')
|
|
84
|
+
.option(
|
|
85
|
+
'-r, --reply [string]',
|
|
86
|
+
'The id of the tweet to which the reply is to be made, if the tweet is to be a reply',
|
|
87
|
+
)
|
|
88
|
+
.action(async (text: string, options?: { media?: string; quote?: string; reply?: string }) => {
|
|
89
|
+
try {
|
|
90
|
+
const result = await rettiwt.tweet.post({
|
|
91
|
+
text: text,
|
|
92
|
+
media: options?.media ? options?.media.split(',').map((item) => ({ id: item })) : undefined,
|
|
93
|
+
quote: options?.quote,
|
|
94
|
+
replyTo: options?.reply,
|
|
95
|
+
});
|
|
96
|
+
output(result);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
output(error);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Retweet
|
|
103
|
+
tweet
|
|
104
|
+
.command('retweet')
|
|
105
|
+
.description('Retweet a tweet')
|
|
106
|
+
.argument('<id>', 'The tweet to retweet')
|
|
107
|
+
.action(async (id: string) => {
|
|
108
|
+
try {
|
|
109
|
+
const result = await rettiwt.tweet.retweet(id);
|
|
110
|
+
output(result);
|
|
111
|
+
} catch (error) {
|
|
112
|
+
output(error);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Retweeters
|
|
117
|
+
tweet
|
|
118
|
+
.command('retweeters')
|
|
119
|
+
.description('Fetch the list of users who retweeted the given tweets')
|
|
120
|
+
.argument('<id>', 'The id of the tweet')
|
|
121
|
+
.argument('[count]', 'The number of retweeters to fetch')
|
|
122
|
+
.argument('[cursor]', 'The cursor to the batch of retweeters to fetch')
|
|
123
|
+
.action(async (id: string, count?: string, cursor?: string) => {
|
|
124
|
+
try {
|
|
125
|
+
const tweets = await rettiwt.tweet.retweeters(id, count ? parseInt(count) : undefined, cursor);
|
|
126
|
+
output(tweets);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
output(error);
|
|
129
|
+
}
|
|
27
130
|
});
|
|
28
131
|
|
|
29
132
|
// Search
|
|
@@ -60,99 +163,84 @@ function createTweetCommand(rettiwt: Rettiwt): Command {
|
|
|
60
163
|
.option('--stream', 'Stream the filtered tweets in pseudo-realtime')
|
|
61
164
|
.option('-i, --interval <number>', 'The polling interval (in ms) to use for streaming. Default is 60000')
|
|
62
165
|
.action(async (count?: string, cursor?: string, options?: TweetSearchOptions) => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
166
|
+
try {
|
|
167
|
+
// If search results are to be streamed
|
|
168
|
+
if (options?.stream) {
|
|
169
|
+
for await (const tweet of rettiwt.tweet.stream(
|
|
170
|
+
new TweetSearchOptions(options).toTweetFilter(),
|
|
171
|
+
options?.interval,
|
|
172
|
+
)) {
|
|
173
|
+
output(tweet);
|
|
174
|
+
}
|
|
70
175
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
176
|
+
// If a normal search is to be done
|
|
177
|
+
else {
|
|
178
|
+
const tweets = await rettiwt.tweet.search(
|
|
179
|
+
new TweetSearchOptions(options).toTweetFilter(),
|
|
180
|
+
count ? parseInt(count) : undefined,
|
|
181
|
+
cursor,
|
|
182
|
+
);
|
|
183
|
+
output(tweets);
|
|
184
|
+
}
|
|
185
|
+
} catch (error) {
|
|
186
|
+
output(error);
|
|
80
187
|
}
|
|
81
188
|
});
|
|
82
189
|
|
|
83
|
-
//
|
|
190
|
+
// Unlike
|
|
84
191
|
tweet
|
|
85
|
-
.command('
|
|
86
|
-
.description('
|
|
87
|
-
.argument('<id>', 'The id of the tweet list')
|
|
88
|
-
.argument('[count]', 'The number of tweets to fetch')
|
|
89
|
-
.argument('[cursor]', 'The cursor to the batch of tweets to fetch')
|
|
90
|
-
.action(async (id: string, count?: string, cursor?: string) => {
|
|
91
|
-
const tweets = await rettiwt.tweet.list(id, count ? parseInt(count) : undefined, cursor);
|
|
92
|
-
output(tweets);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// Likes
|
|
96
|
-
tweet
|
|
97
|
-
.command('likes')
|
|
98
|
-
.description('Fetch the list of users who liked the given tweets')
|
|
192
|
+
.command('unlike')
|
|
193
|
+
.description('Unlike a tweet')
|
|
99
194
|
.argument('<id>', 'The id of the tweet')
|
|
100
|
-
.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
195
|
+
.action(async (id: string) => {
|
|
196
|
+
try {
|
|
197
|
+
const result = await rettiwt.tweet.unlike(id);
|
|
198
|
+
output(result);
|
|
199
|
+
} catch (error) {
|
|
200
|
+
output(error);
|
|
201
|
+
}
|
|
105
202
|
});
|
|
106
203
|
|
|
107
|
-
//
|
|
204
|
+
// Unpost
|
|
108
205
|
tweet
|
|
109
|
-
.command('
|
|
110
|
-
.description('
|
|
206
|
+
.command('unpost')
|
|
207
|
+
.description('Unpost a tweet')
|
|
111
208
|
.argument('<id>', 'The id of the tweet')
|
|
112
|
-
.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// Post
|
|
120
|
-
tweet
|
|
121
|
-
.command('post')
|
|
122
|
-
.description('Post a tweet (text only)')
|
|
123
|
-
.argument('<text>', 'The text to post as a tweet')
|
|
124
|
-
.option('-m, --media [string]', 'Comma-separated list of path(s) to the media item(s) to be posted')
|
|
125
|
-
.option(
|
|
126
|
-
'-r, --reply [string]',
|
|
127
|
-
'The id of the tweet to which the reply is to be made, if the tweet is to be a reply',
|
|
128
|
-
)
|
|
129
|
-
.action(async (text: string, options?: { media?: string; reply?: string }) => {
|
|
130
|
-
const result = await rettiwt.tweet.tweet(
|
|
131
|
-
text,
|
|
132
|
-
options?.media ? options?.media.split(',').map((item) => ({ path: item })) : undefined,
|
|
133
|
-
options?.reply,
|
|
134
|
-
);
|
|
135
|
-
output(result);
|
|
209
|
+
.action(async (id: string) => {
|
|
210
|
+
try {
|
|
211
|
+
const result = await rettiwt.tweet.unpost(id);
|
|
212
|
+
output(result);
|
|
213
|
+
} catch (error) {
|
|
214
|
+
output(error);
|
|
215
|
+
}
|
|
136
216
|
});
|
|
137
217
|
|
|
138
|
-
//
|
|
218
|
+
// Unretweet
|
|
139
219
|
tweet
|
|
140
|
-
.command('
|
|
141
|
-
.description('
|
|
142
|
-
.argument('<id>', 'The
|
|
220
|
+
.command('unretweet')
|
|
221
|
+
.description('Unretweet a tweet')
|
|
222
|
+
.argument('<id>', 'The id of the tweet')
|
|
143
223
|
.action(async (id: string) => {
|
|
144
|
-
|
|
145
|
-
|
|
224
|
+
try {
|
|
225
|
+
const result = await rettiwt.tweet.unretweet(id);
|
|
226
|
+
output(result);
|
|
227
|
+
} catch (error) {
|
|
228
|
+
output(error);
|
|
229
|
+
}
|
|
146
230
|
});
|
|
147
231
|
|
|
148
|
-
//
|
|
232
|
+
// Upload
|
|
149
233
|
tweet
|
|
150
|
-
.command('
|
|
151
|
-
.description('
|
|
152
|
-
.argument('<
|
|
153
|
-
.action(async (
|
|
154
|
-
|
|
155
|
-
|
|
234
|
+
.command('upload')
|
|
235
|
+
.description('Upload a media file and returns the alloted id (valid for 24 hrs)')
|
|
236
|
+
.argument('<path>', 'The path to the media to upload')
|
|
237
|
+
.action(async (path: string) => {
|
|
238
|
+
try {
|
|
239
|
+
const id = await rettiwt.tweet.upload(path);
|
|
240
|
+
output(id);
|
|
241
|
+
} catch (error) {
|
|
242
|
+
output(error);
|
|
243
|
+
}
|
|
156
244
|
});
|
|
157
245
|
|
|
158
246
|
return tweet;
|
|
@@ -164,24 +252,24 @@ function createTweetCommand(rettiwt: Rettiwt): Command {
|
|
|
164
252
|
* @remarks The search options are implementations of the ones offered by {@link TweetFilter}
|
|
165
253
|
*/
|
|
166
254
|
class TweetSearchOptions {
|
|
167
|
-
public
|
|
168
|
-
public
|
|
169
|
-
public
|
|
170
|
-
public phrase?: string;
|
|
171
|
-
public optionalWords?: string;
|
|
255
|
+
public end?: string;
|
|
256
|
+
public excludeLinks?: boolean = false;
|
|
257
|
+
public excludeReplies?: boolean = false;
|
|
172
258
|
public excludeWords?: string;
|
|
259
|
+
public from?: string;
|
|
173
260
|
public hashtags?: string;
|
|
261
|
+
public interval?: number;
|
|
174
262
|
public mentions?: string;
|
|
175
|
-
public minReplies?: number;
|
|
176
263
|
public minLikes?: number;
|
|
264
|
+
public minReplies?: number;
|
|
177
265
|
public minRetweets?: number;
|
|
266
|
+
public optionalWords?: string;
|
|
267
|
+
public phrase?: string;
|
|
178
268
|
public quoted?: string;
|
|
179
|
-
public excludeLinks?: boolean = false;
|
|
180
|
-
public excludeReplies?: boolean = false;
|
|
181
269
|
public start?: string;
|
|
182
|
-
public end?: string;
|
|
183
270
|
public stream?: boolean;
|
|
184
|
-
public
|
|
271
|
+
public to?: string;
|
|
272
|
+
public words?: string;
|
|
185
273
|
|
|
186
274
|
/**
|
|
187
275
|
* Initializes a new object from the given options.
|