rettiwt-api 2.3.0 → 2.4.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/README.md +81 -13
- package/dist/Rettiwt.d.ts +37 -1
- package/dist/Rettiwt.js +37 -1
- package/dist/Rettiwt.js.map +1 -1
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +39 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/Auth.d.ts +3 -0
- package/dist/commands/Auth.js +90 -0
- package/dist/commands/Auth.js.map +1 -0
- package/dist/commands/Tweet.d.ts +10 -0
- package/dist/commands/Tweet.js +242 -0
- package/dist/commands/Tweet.js.map +1 -0
- package/dist/commands/User.d.ts +10 -0
- package/dist/commands/User.js +162 -0
- package/dist/commands/User.js.map +1 -0
- package/dist/helper/CliUtils.d.ts +6 -0
- package/dist/helper/CliUtils.js +20 -0
- package/dist/helper/CliUtils.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/models/internal/RettiwtConfig.d.ts +1 -3
- package/dist/models/internal/RettiwtConfig.js +1 -0
- package/dist/models/internal/RettiwtConfig.js.map +1 -1
- package/dist/models/public/CursoredData.d.ts +0 -3
- package/dist/models/public/CursoredData.js +0 -1
- package/dist/models/public/CursoredData.js.map +1 -1
- package/dist/models/public/List.d.ts +0 -7
- package/dist/models/public/List.js.map +1 -1
- package/dist/models/public/Tweet.d.ts +0 -20
- package/dist/models/public/Tweet.js +0 -4
- package/dist/models/public/Tweet.js.map +1 -1
- package/dist/models/public/User.d.ts +0 -14
- package/dist/models/public/User.js.map +1 -1
- package/dist/services/internal/FetcherService.d.ts +7 -0
- package/dist/services/internal/FetcherService.js +25 -1
- package/dist/services/internal/FetcherService.js.map +1 -1
- package/dist/services/public/TweetService.d.ts +138 -0
- package/dist/services/public/TweetService.js +138 -0
- package/dist/services/public/TweetService.js.map +1 -1
- package/dist/services/public/UserService.d.ts +122 -1
- package/dist/services/public/UserService.js +122 -1
- package/dist/services/public/UserService.js.map +1 -1
- package/dist/types/internal/RettiwtConfig.d.ts +2 -0
- package/package.json +6 -2
- package/src/Rettiwt.ts +37 -1
- package/src/cli.ts +40 -0
- package/src/commands/Auth.ts +45 -0
- package/src/commands/Tweet.ts +163 -0
- package/src/commands/User.ts +85 -0
- package/src/helper/CliUtils.ts +15 -0
- package/src/index.ts +2 -0
- package/src/models/internal/RettiwtConfig.ts +2 -5
- package/src/models/public/CursoredData.ts +0 -4
- package/src/models/public/List.ts +0 -13
- package/src/models/public/Tweet.ts +0 -37
- package/src/models/public/User.ts +0 -27
- package/src/services/internal/FetcherService.ts +28 -1
- package/src/services/public/TweetService.ts +138 -0
- package/src/services/public/UserService.ts +122 -1
- package/src/types/internal/RettiwtConfig.ts +3 -0
|
@@ -77,6 +77,40 @@ var UserService = /** @class */ (function (_super) {
|
|
|
77
77
|
* @param id - The username/id of the target user.
|
|
78
78
|
* @returns The details of the given user.
|
|
79
79
|
*
|
|
80
|
+
* @example Fetching the details of the Twitter user with username 'user1'
|
|
81
|
+
* ```
|
|
82
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
83
|
+
*
|
|
84
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
85
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
86
|
+
*
|
|
87
|
+
* // Fetching the details of the User with username 'user1'
|
|
88
|
+
* rettiwt.user.details('user1')
|
|
89
|
+
* .then(res => {
|
|
90
|
+
* console.log(res);
|
|
91
|
+
* })
|
|
92
|
+
* .catch(err => {
|
|
93
|
+
* console.log(err);
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @example Fetching the details of the Twitter user with id '12345678'
|
|
98
|
+
* ```
|
|
99
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
100
|
+
*
|
|
101
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
102
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
103
|
+
*
|
|
104
|
+
* // Fetching the details of the User with id '12345678'
|
|
105
|
+
* rettiwt.user.details('12345678')
|
|
106
|
+
* .then(res => {
|
|
107
|
+
* console.log(res);
|
|
108
|
+
* })
|
|
109
|
+
* .catch(err => {
|
|
110
|
+
* console.log(err);
|
|
111
|
+
* });
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
80
114
|
* @public
|
|
81
115
|
*/
|
|
82
116
|
UserService.prototype.details = function (id) {
|
|
@@ -109,6 +143,23 @@ var UserService = /** @class */ (function (_super) {
|
|
|
109
143
|
* @param cursor - The cursor to the batch of following to fetch.
|
|
110
144
|
* @returns The list of users followed by the target user.
|
|
111
145
|
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```
|
|
148
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
149
|
+
*
|
|
150
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
151
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
152
|
+
*
|
|
153
|
+
* // Fetching the first 100 following of the User with id '12345678'
|
|
154
|
+
* rettiwt.user.following('12345678')
|
|
155
|
+
* .then(res => {
|
|
156
|
+
* console.log(res);
|
|
157
|
+
* })
|
|
158
|
+
* .catch(err => {
|
|
159
|
+
* console.log(err);
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
112
163
|
* @public
|
|
113
164
|
*/
|
|
114
165
|
UserService.prototype.following = function (userId, count, cursor) {
|
|
@@ -136,6 +187,23 @@ var UserService = /** @class */ (function (_super) {
|
|
|
136
187
|
* @param cursor - The cursor to the batch of followers to fetch.
|
|
137
188
|
* @returns The list of users following the target user.
|
|
138
189
|
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```
|
|
192
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
193
|
+
*
|
|
194
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
195
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
196
|
+
*
|
|
197
|
+
* // Fetching the first 100 followers of the User with id '12345678'
|
|
198
|
+
* rettiwt.user.followers('12345678')
|
|
199
|
+
* .then(res => {
|
|
200
|
+
* console.log(res);
|
|
201
|
+
* })
|
|
202
|
+
* .catch(err => {
|
|
203
|
+
* console.log(err);
|
|
204
|
+
* });
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
139
207
|
* @public
|
|
140
208
|
*/
|
|
141
209
|
UserService.prototype.followers = function (userId, count, cursor) {
|
|
@@ -163,6 +231,23 @@ var UserService = /** @class */ (function (_super) {
|
|
|
163
231
|
* @param cursor - The cursor to the batch of likes to fetch.
|
|
164
232
|
* @returns The list of tweets liked by the target user.
|
|
165
233
|
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```
|
|
236
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
237
|
+
*
|
|
238
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
239
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
240
|
+
*
|
|
241
|
+
* // Fetching the most recent 100 liked Tweets of the User with id '12345678'
|
|
242
|
+
* rettiwt.user.likes('12345678')
|
|
243
|
+
* .then(res => {
|
|
244
|
+
* console.log(res);
|
|
245
|
+
* })
|
|
246
|
+
* .catch(err => {
|
|
247
|
+
* console.log(err);
|
|
248
|
+
* });
|
|
249
|
+
* ```
|
|
250
|
+
*
|
|
166
251
|
* @public
|
|
167
252
|
*/
|
|
168
253
|
UserService.prototype.likes = function (userId, count, cursor) {
|
|
@@ -190,7 +275,26 @@ var UserService = /** @class */ (function (_super) {
|
|
|
190
275
|
* @param cursor - The cursor to the batch of timeline items to fetch.
|
|
191
276
|
* @returns The timeline of the target user.
|
|
192
277
|
*
|
|
193
|
-
* @
|
|
278
|
+
* @example
|
|
279
|
+
* ```
|
|
280
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
281
|
+
*
|
|
282
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
283
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
284
|
+
*
|
|
285
|
+
* // Fetching the first 20 timeline tweets of the User with id '12345678'
|
|
286
|
+
* rettiwt.user.timeline('12345678')
|
|
287
|
+
* .then(res => {
|
|
288
|
+
* console.log(res);
|
|
289
|
+
* })
|
|
290
|
+
* .catch(err => {
|
|
291
|
+
* console.log(err);
|
|
292
|
+
* });
|
|
293
|
+
* ```
|
|
294
|
+
*
|
|
295
|
+
* @remarks
|
|
296
|
+
* - If the target user has a pinned tweet, the returned timeline has one item extra and this is always the pinned tweet.
|
|
297
|
+
* - If timeline is fetched without authenticating, then the most popular tweets of the target user are returned instead.
|
|
194
298
|
*
|
|
195
299
|
* @public
|
|
196
300
|
*/
|
|
@@ -219,6 +323,23 @@ var UserService = /** @class */ (function (_super) {
|
|
|
219
323
|
* @param cursor - The cursor to the batch of replies to fetch.
|
|
220
324
|
* @returns The reply timeline of the target user.
|
|
221
325
|
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```
|
|
328
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
329
|
+
*
|
|
330
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
331
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
332
|
+
*
|
|
333
|
+
* // Fetching the first 100 timeline replies of the User with id '12345678'
|
|
334
|
+
* rettiwt.user.replies('12345678')
|
|
335
|
+
* .then(res => {
|
|
336
|
+
* console.log(res);
|
|
337
|
+
* })
|
|
338
|
+
* .catch(err => {
|
|
339
|
+
* console.log(err);
|
|
340
|
+
* });
|
|
341
|
+
* ```
|
|
342
|
+
*
|
|
222
343
|
* @remarks If the target user has a pinned tweet, the returned reply timeline has one item extra and this is always the pinned tweet.
|
|
223
344
|
*
|
|
224
345
|
* @public
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserService.js","sourceRoot":"","sources":["../../../src/services/public/UserService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,WAAW;AACX,6CAA6C;AAE7C,WAAW;AACX,6DAA4D;AAU5D;;;;GAIG;AACH;IAAiC,+BAAc;IAC9C;;;;OAIG;IACH,qBAAmB,MAAsB;eACxC,kBAAM,MAAM,CAAC;IACd,CAAC;IAED
|
|
1
|
+
{"version":3,"file":"UserService.js","sourceRoot":"","sources":["../../../src/services/public/UserService.ts"],"names":[],"mappings":"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"}
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
export interface IRettiwtConfig {
|
|
7
7
|
/** The apiKey (cookie) to use for authenticating Rettiwt against Twitter API. */
|
|
8
8
|
apiKey?: string;
|
|
9
|
+
/** The guestKey (guest token) to use for guest access to Twitter API. */
|
|
10
|
+
guestKey?: string;
|
|
9
11
|
/** Optional URL with proxy configuration to use for requests to Twitter API. */
|
|
10
12
|
proxyUrl?: URL;
|
|
11
13
|
/** Whether to write logs to console or not. */
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rettiwt-api",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.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!",
|
|
7
|
+
"bin": {
|
|
8
|
+
"rettiwt": "dist/cli.js"
|
|
9
|
+
},
|
|
7
10
|
"scripts": {
|
|
8
11
|
"build": "tsc",
|
|
9
12
|
"prepare": "tsc",
|
|
@@ -27,8 +30,9 @@
|
|
|
27
30
|
"homepage": "https://rishikant181.github.io/Rettiwt-API/",
|
|
28
31
|
"dependencies": {
|
|
29
32
|
"axios": "1.3.2",
|
|
33
|
+
"commander": "11.1.0",
|
|
30
34
|
"https-proxy-agent": "7.0.2",
|
|
31
|
-
"rettiwt-auth": "
|
|
35
|
+
"rettiwt-auth": "2.0.0",
|
|
32
36
|
"rettiwt-core": "3.2.1"
|
|
33
37
|
},
|
|
34
38
|
"devDependencies": {
|
package/src/Rettiwt.ts
CHANGED
|
@@ -6,7 +6,43 @@ import { UserService } from './services/public/UserService';
|
|
|
6
6
|
import { RettiwtConfig } from './models/internal/RettiwtConfig';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* The class for
|
|
9
|
+
* The class for accessing Twitter API.
|
|
10
|
+
*
|
|
11
|
+
* The created Rettiwt instance can be configured by passing in a configuration object to the constructor.
|
|
12
|
+
*
|
|
13
|
+
* For details regarding the available configuration options, refer to {@link RettiwtConfig}
|
|
14
|
+
*
|
|
15
|
+
* @example Creating a Rettiwt instance with 'guest' authentication:
|
|
16
|
+
* ```
|
|
17
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
18
|
+
*
|
|
19
|
+
* // Creating a new Rettiwt instance
|
|
20
|
+
* const rettiwt = new Rettiwt();
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @example Creating a Rettiwt instance with 'guest' authentication, using a pre-generated guest key:
|
|
24
|
+
* ```
|
|
25
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
26
|
+
*
|
|
27
|
+
* // Creating a new Rettiwt instance
|
|
28
|
+
* const rettiwt = new Rettiwt({ guestKey: 'GUEST_KEY' });
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example Creating a Rettiwt instance with 'user' authentication:
|
|
32
|
+
* ```
|
|
33
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
34
|
+
*
|
|
35
|
+
* // Creating a new Rettiwt instance
|
|
36
|
+
* const rettiwt = new Rettiwt({ apiKey: 'API_KEY' });
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example Creating a Rettiwt instance with 'user'authentication, along with enabling debug logs and using a proxy:
|
|
40
|
+
* ```
|
|
41
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
42
|
+
*
|
|
43
|
+
* // Creating a new Rettiwt instance
|
|
44
|
+
* const rettiwt = new Rettiwt({ apiKey: 'API_KEY', loggin: true, proxyUrl: 'URL_TO_PROXY_SERVER' });
|
|
45
|
+
* ```
|
|
10
46
|
*
|
|
11
47
|
* @public
|
|
12
48
|
*/
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// PACKAGES
|
|
4
|
+
import { createCommand } from 'commander';
|
|
5
|
+
import { Rettiwt } from './Rettiwt';
|
|
6
|
+
|
|
7
|
+
// SUB-COMMANDS
|
|
8
|
+
import tweet from './commands/Tweet';
|
|
9
|
+
import user from './commands/User';
|
|
10
|
+
import auth from './commands/Auth';
|
|
11
|
+
|
|
12
|
+
// Creating a new commandline program
|
|
13
|
+
const program = createCommand('rettiwt')
|
|
14
|
+
.description('A CLI tool for accessing the Twitter API for free!')
|
|
15
|
+
.passThroughOptions()
|
|
16
|
+
.enablePositionalOptions();
|
|
17
|
+
|
|
18
|
+
// Adding options
|
|
19
|
+
program
|
|
20
|
+
.option('-k, --key <string>', 'The API key to use for authentication')
|
|
21
|
+
.option('-l, --log', 'Enable logging to console')
|
|
22
|
+
.option('-p, --proxy <string>', 'The URL to the proxy to use');
|
|
23
|
+
|
|
24
|
+
// Parsing the program to get supplied options
|
|
25
|
+
program.parse();
|
|
26
|
+
|
|
27
|
+
// Initializing Rettiwt instance using the given options
|
|
28
|
+
const rettiwt: Rettiwt = new Rettiwt({
|
|
29
|
+
apiKey: process.env.API_KEY ?? (program.opts().key as string),
|
|
30
|
+
logging: program.opts().log ? true : false,
|
|
31
|
+
proxyUrl: program.opts().proxy as URL,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Adding sub-commands
|
|
35
|
+
program.addCommand(tweet(rettiwt));
|
|
36
|
+
program.addCommand(user(rettiwt));
|
|
37
|
+
program.addCommand(auth());
|
|
38
|
+
|
|
39
|
+
// Finalizing the CLI
|
|
40
|
+
program.parse();
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// PACKAGES
|
|
2
|
+
import { Command, createCommand } from 'commander';
|
|
3
|
+
import { Auth } from 'rettiwt-auth';
|
|
4
|
+
|
|
5
|
+
// UTILITY
|
|
6
|
+
import { output } from '../helper/CliUtils';
|
|
7
|
+
|
|
8
|
+
function createAuthCommand(): Command {
|
|
9
|
+
// Creating the 'auth' command
|
|
10
|
+
const auth = createCommand('auth').description('Manage authentication');
|
|
11
|
+
|
|
12
|
+
// Login
|
|
13
|
+
auth.command('login')
|
|
14
|
+
.description('Generate a new API key using Twitter account login credentials')
|
|
15
|
+
.argument('<email>', 'The email id of the Twitter account')
|
|
16
|
+
.argument('<username>', 'The username associated with the Twitter account')
|
|
17
|
+
.argument('<password>', 'The password to the Twitter account')
|
|
18
|
+
.action(async (email: string, username: string, password: string) => {
|
|
19
|
+
// Logging in and getting the credentials
|
|
20
|
+
let apiKey: string =
|
|
21
|
+
(
|
|
22
|
+
await new Auth().getUserCredential({ email: email, userName: username, password: password })
|
|
23
|
+
).toHeader().cookie ?? '';
|
|
24
|
+
|
|
25
|
+
// Converting the credentials to base64 string
|
|
26
|
+
apiKey = Buffer.from(apiKey).toString('base64');
|
|
27
|
+
output(apiKey);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Guest
|
|
31
|
+
auth.command('guest')
|
|
32
|
+
.description('Generate a new guest API key')
|
|
33
|
+
.action(async () => {
|
|
34
|
+
// Getting a new guest API key
|
|
35
|
+
let guestKey: string = (await new Auth().getGuestCredential()).guestToken ?? '';
|
|
36
|
+
|
|
37
|
+
// Converting the credentials to base64 string
|
|
38
|
+
guestKey = Buffer.from(guestKey).toString('base64');
|
|
39
|
+
output(guestKey);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return auth;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default createAuthCommand;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// PACKAGES
|
|
2
|
+
import { Command, createCommand } from 'commander';
|
|
3
|
+
import { Rettiwt } from '../Rettiwt';
|
|
4
|
+
import { TweetFilter } from 'rettiwt-core';
|
|
5
|
+
|
|
6
|
+
// UTILITY
|
|
7
|
+
import { output } from '../helper/CliUtils';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new 'tweet' command which uses the given Rettiwt instance.
|
|
11
|
+
*
|
|
12
|
+
* @param rettiwt - The Rettiwt instance to use.
|
|
13
|
+
* @returns The created 'tweet' command.
|
|
14
|
+
*/
|
|
15
|
+
function createTweetCommand(rettiwt: Rettiwt): Command {
|
|
16
|
+
// Creating the 'tweet' command
|
|
17
|
+
const tweet = createCommand('tweet').description('Access resources releated to tweets');
|
|
18
|
+
|
|
19
|
+
// Details
|
|
20
|
+
tweet
|
|
21
|
+
.command('details')
|
|
22
|
+
.description('Fetch the details of tweet with the given id')
|
|
23
|
+
.argument('<id>', 'The id of the tweet whose details are to be fetched')
|
|
24
|
+
.action(async (id: string) => {
|
|
25
|
+
const details = await rettiwt.tweet.details(id);
|
|
26
|
+
output(details);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Search
|
|
30
|
+
tweet
|
|
31
|
+
.command('search')
|
|
32
|
+
.description('Fetch the list of tweets that match the given filter options')
|
|
33
|
+
.argument('[count]', 'The number of tweets to fetch')
|
|
34
|
+
.argument('[cursor]', 'The cursor to the batch of tweets to fetch')
|
|
35
|
+
.option('-f, --from <string>', "Matches the tweets made by list of given users, separated by ';'")
|
|
36
|
+
.option('-t, --to <string>', "Matches the tweets made to the list of given users, separated by ';'")
|
|
37
|
+
.option('-w, --words <string>', "Matches the tweets containing the given list of words, separated by ';'")
|
|
38
|
+
.option('-h, --hashtags <string>', "Matches the tweets containing the given list of hashtags, separated by ';'")
|
|
39
|
+
.option('-s, --start <string>', 'Matches the tweets made since the given date (valid date string)')
|
|
40
|
+
.option('-e, --end <string>', 'Matches the tweets made upto the given date (valid date string)')
|
|
41
|
+
.action(async (count?: string, cursor?: string, options?: TweetSearchOptions) => {
|
|
42
|
+
const tweets = await rettiwt.tweet.search(
|
|
43
|
+
new TweetSearchOptions(options).toTweetFilter(),
|
|
44
|
+
count ? parseInt(count) : undefined,
|
|
45
|
+
cursor,
|
|
46
|
+
);
|
|
47
|
+
output(tweets);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// List
|
|
51
|
+
tweet
|
|
52
|
+
.command('list')
|
|
53
|
+
.description('Fetch the list of tweets in the tweet list with the given id')
|
|
54
|
+
.argument('<id>', 'The id of the tweet list')
|
|
55
|
+
.argument('[count]', 'The number of tweets to fetch')
|
|
56
|
+
.argument('[cursor]', 'The cursor to the batch of tweets to fetch')
|
|
57
|
+
.action(async (id: string, count?: string, cursor?: string) => {
|
|
58
|
+
const tweets = await rettiwt.tweet.list(id, count ? parseInt(count) : undefined, cursor);
|
|
59
|
+
output(tweets);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Likes
|
|
63
|
+
tweet
|
|
64
|
+
.command('likes')
|
|
65
|
+
.description('Fetch the list of users who liked the given tweets')
|
|
66
|
+
.argument('<id>', 'The id of the tweet')
|
|
67
|
+
.argument('[count]', 'The number of likers to fetch')
|
|
68
|
+
.argument('[cursor]', 'The cursor to the batch of likers to fetch')
|
|
69
|
+
.action(async (id: string, count?: string, cursor?: string) => {
|
|
70
|
+
const tweets = await rettiwt.tweet.favoriters(id, count ? parseInt(count) : undefined, cursor);
|
|
71
|
+
output(tweets);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Retweets
|
|
75
|
+
tweet
|
|
76
|
+
.command('retweets')
|
|
77
|
+
.description('Fetch the list of users who retweeted the given tweets')
|
|
78
|
+
.argument('<id>', 'The id of the tweet')
|
|
79
|
+
.argument('[count]', 'The number of retweeters to fetch')
|
|
80
|
+
.argument('[cursor]', 'The cursor to the batch of retweeters to fetch')
|
|
81
|
+
.action(async (id: string, count?: string, cursor?: string) => {
|
|
82
|
+
const tweets = await rettiwt.tweet.retweeters(id, count ? parseInt(count) : undefined, cursor);
|
|
83
|
+
output(tweets);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Post
|
|
87
|
+
tweet
|
|
88
|
+
.command('post')
|
|
89
|
+
.description('Post a tweet (text only)')
|
|
90
|
+
.argument('<text>', 'The text to post as a tweet')
|
|
91
|
+
.action(async (text: string) => {
|
|
92
|
+
const result = await rettiwt.tweet.tweet(text);
|
|
93
|
+
output(result);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Like
|
|
97
|
+
tweet
|
|
98
|
+
.command('like')
|
|
99
|
+
.description('Like a tweet')
|
|
100
|
+
.argument('<id>', 'The tweet to like')
|
|
101
|
+
.action(async (id: string) => {
|
|
102
|
+
const result = await rettiwt.tweet.favorite(id);
|
|
103
|
+
output(result);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Retweet
|
|
107
|
+
tweet
|
|
108
|
+
.command('retweet')
|
|
109
|
+
.description('Retweet a tweet')
|
|
110
|
+
.argument('<id>', 'The tweet to retweet')
|
|
111
|
+
.action(async (id: string) => {
|
|
112
|
+
const result = await rettiwt.tweet.retweet(id);
|
|
113
|
+
output(result);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
return tweet;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The search options supplied while searching for tweets.
|
|
121
|
+
*
|
|
122
|
+
* @remarks The search options are implementations of the ones offered by {@link TweetFilter}
|
|
123
|
+
*/
|
|
124
|
+
class TweetSearchOptions {
|
|
125
|
+
public from?: string;
|
|
126
|
+
public to?: string;
|
|
127
|
+
public words?: string;
|
|
128
|
+
public hashtags?: string;
|
|
129
|
+
public start?: string;
|
|
130
|
+
public end?: string;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Initializes a new object from the given options.
|
|
134
|
+
*
|
|
135
|
+
* @param options - The search options.
|
|
136
|
+
*/
|
|
137
|
+
public constructor(options?: TweetSearchOptions) {
|
|
138
|
+
this.from = options?.from;
|
|
139
|
+
this.to = options?.to;
|
|
140
|
+
this.words = options?.words;
|
|
141
|
+
this.hashtags = options?.hashtags;
|
|
142
|
+
this.start = options?.start;
|
|
143
|
+
this.end = options?.end;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Converts the filter options to a format recognizable by rettiwt-api.
|
|
148
|
+
*
|
|
149
|
+
* @returns The '{@link TweetFilter}' representation of filter options.
|
|
150
|
+
*/
|
|
151
|
+
public toTweetFilter(): TweetFilter {
|
|
152
|
+
return new TweetFilter({
|
|
153
|
+
fromUsers: this.from ? this.from.split(';') : undefined,
|
|
154
|
+
toUsers: this.to ? this.to.split(';') : undefined,
|
|
155
|
+
words: this.words ? this.words.split(';') : undefined,
|
|
156
|
+
hashtags: this.hashtags ? this.hashtags.split(';') : undefined,
|
|
157
|
+
startDate: this.start ? new Date(this.start) : undefined,
|
|
158
|
+
endDate: this.end ? new Date(this.end) : undefined,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export default createTweetCommand;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// PACKAGES
|
|
2
|
+
import { Command, createCommand } from 'commander';
|
|
3
|
+
import { Rettiwt } from '../Rettiwt';
|
|
4
|
+
|
|
5
|
+
// UTILITY
|
|
6
|
+
import { output } from '../helper/CliUtils';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new 'user' command which uses the given Rettiwt instance.
|
|
10
|
+
*
|
|
11
|
+
* @param rettiwt - The Rettiwt instance to use.
|
|
12
|
+
* @returns The created 'user' command.
|
|
13
|
+
*/
|
|
14
|
+
function createUserCommand(rettiwt: Rettiwt): Command {
|
|
15
|
+
// Creating the 'user' command
|
|
16
|
+
const user = createCommand('user').description('Access resources releated to users');
|
|
17
|
+
|
|
18
|
+
// Details
|
|
19
|
+
user.command('details')
|
|
20
|
+
.description('Fetch the details of the user with the given id/username')
|
|
21
|
+
.argument('<id>', 'The username/id of the user whose details are to be fetched')
|
|
22
|
+
.action(async (id: string) => {
|
|
23
|
+
const details = await rettiwt.user.details(id);
|
|
24
|
+
output(details);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Following
|
|
28
|
+
user.command('following')
|
|
29
|
+
.description('Fetch the list of users who are followed by the given user')
|
|
30
|
+
.argument('<id>', 'The id of the user')
|
|
31
|
+
.argument('[count]', 'The number of following to fetch')
|
|
32
|
+
.argument('[cursor]', 'The cursor to the batch of following to fetch')
|
|
33
|
+
.action(async (id: string, count?: string, cursor?: string) => {
|
|
34
|
+
const users = await rettiwt.user.following(id, count ? parseInt(count) : undefined, cursor);
|
|
35
|
+
output(users);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Followers
|
|
39
|
+
user.command('followers')
|
|
40
|
+
.description('Fetch the list of users who follow the given user')
|
|
41
|
+
.argument('<id>', 'The id of the user')
|
|
42
|
+
.argument('[count]', 'The number of followers to fetch')
|
|
43
|
+
.argument('[cursor]', 'The cursor to the batch of followers to fetch')
|
|
44
|
+
.action(async (id: string, count?: string, cursor?: string) => {
|
|
45
|
+
const users = await rettiwt.user.followers(id, count ? parseInt(count) : undefined, cursor);
|
|
46
|
+
output(users);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Likes
|
|
50
|
+
user.command('likes')
|
|
51
|
+
.description('Fetch the list of tweets liked by the given user')
|
|
52
|
+
.argument('<id>', 'The id of the user')
|
|
53
|
+
.argument('[count]', 'The number of liked tweets to fetch')
|
|
54
|
+
.argument('[cursor]', 'The cursor to the batch of liked tweets to fetch')
|
|
55
|
+
.action(async (id: string, count?: string, cursor?: string) => {
|
|
56
|
+
const users = await rettiwt.user.likes(id, count ? parseInt(count) : undefined, cursor);
|
|
57
|
+
output(users);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Timeline
|
|
61
|
+
user.command('timeline')
|
|
62
|
+
.description('Fetch the tweets timeline the given user')
|
|
63
|
+
.argument('<id>', 'The id of the user')
|
|
64
|
+
.argument('[count]', 'The number of tweets to fetch')
|
|
65
|
+
.argument('[cursor]', 'The cursor to the batch of tweets to fetch')
|
|
66
|
+
.action(async (id: string, count?: string, cursor?: string) => {
|
|
67
|
+
const users = await rettiwt.user.timeline(id, count ? parseInt(count) : undefined, cursor);
|
|
68
|
+
output(users);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Replies
|
|
72
|
+
user.command('replies')
|
|
73
|
+
.description('Fetch the replies timeline the given user')
|
|
74
|
+
.argument('<id>', 'The id of the user')
|
|
75
|
+
.argument('[count]', 'The number of replies to fetch')
|
|
76
|
+
.argument('[cursor]', 'The cursor to the batch of replies to fetch')
|
|
77
|
+
.action(async (id: string, count?: string, cursor?: string) => {
|
|
78
|
+
const users = await rettiwt.user.replies(id, count ? parseInt(count) : undefined, cursor);
|
|
79
|
+
output(users);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return user;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export default createUserCommand;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Outputs the given JSON data.
|
|
3
|
+
*
|
|
4
|
+
* @param data - The data to be output.
|
|
5
|
+
*/
|
|
6
|
+
export function output(data: NonNullable<unknown>): void {
|
|
7
|
+
// If data is string, output as is
|
|
8
|
+
if (typeof data == 'string') {
|
|
9
|
+
console.log(data);
|
|
10
|
+
}
|
|
11
|
+
// Else, format the output
|
|
12
|
+
else {
|
|
13
|
+
console.log(JSON.stringify(data, null, 4));
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ export * from './models/public/CursoredData';
|
|
|
12
12
|
export * from './models/public/List';
|
|
13
13
|
export * from './models/public/Tweet';
|
|
14
14
|
export * from './models/public/User';
|
|
15
|
+
export { TweetFilter } from 'rettiwt-core';
|
|
15
16
|
|
|
16
17
|
// Exporting services
|
|
17
18
|
export * from './services/internal/FetcherService';
|
|
@@ -25,3 +26,4 @@ export * from './types/public/CursoredData';
|
|
|
25
26
|
export * from './types/public/List';
|
|
26
27
|
export * from './types/public/Tweet';
|
|
27
28
|
export * from './types/public/User';
|
|
29
|
+
export { ITweetFilter } from 'rettiwt-core';
|
|
@@ -7,13 +7,9 @@ import { IRettiwtConfig } from '../../types/internal/RettiwtConfig';
|
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
9
|
export class RettiwtConfig implements IRettiwtConfig {
|
|
10
|
-
/** The apiKey (cookie) to use for authenticating Rettiwt against Twitter API. */
|
|
11
10
|
public apiKey?: string;
|
|
12
|
-
|
|
13
|
-
/** Optional URL with proxy configuration to use for requests to Twitter API. */
|
|
11
|
+
public guestKey?: string;
|
|
14
12
|
public proxyUrl?: URL;
|
|
15
|
-
|
|
16
|
-
/** Whether to write logs to console or not. */
|
|
17
13
|
public logging?: boolean;
|
|
18
14
|
|
|
19
15
|
/**
|
|
@@ -23,6 +19,7 @@ export class RettiwtConfig implements IRettiwtConfig {
|
|
|
23
19
|
*/
|
|
24
20
|
public constructor(config: RettiwtConfig) {
|
|
25
21
|
this.apiKey = config.apiKey;
|
|
22
|
+
this.guestKey = config.guestKey;
|
|
26
23
|
this.proxyUrl = config.proxyUrl;
|
|
27
24
|
this.logging = config.logging;
|
|
28
25
|
}
|
|
@@ -13,10 +13,7 @@ import { ICursor, ICursoredData } from '../../types/public/CursoredData';
|
|
|
13
13
|
* @public
|
|
14
14
|
*/
|
|
15
15
|
export class CursoredData<T extends Tweet | User> implements ICursoredData<T> {
|
|
16
|
-
/** The list of data of the given type. */
|
|
17
16
|
public list: T[] = [];
|
|
18
|
-
|
|
19
|
-
/** The cursor to the next batch of data. */
|
|
20
17
|
public next: Cursor;
|
|
21
18
|
|
|
22
19
|
/**
|
|
@@ -35,7 +32,6 @@ export class CursoredData<T extends Tweet | User> implements ICursoredData<T> {
|
|
|
35
32
|
* @public
|
|
36
33
|
*/
|
|
37
34
|
export class Cursor implements ICursor {
|
|
38
|
-
/** The cursor string. */
|
|
39
35
|
public value: string;
|
|
40
36
|
|
|
41
37
|
/**
|