rettiwt-api 5.0.0-alpha.3 → 5.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/README.md +160 -87
- package/dist/collections/Extractors.d.ts +6 -2
- package/dist/collections/Extractors.js +1 -0
- package/dist/collections/Extractors.js.map +1 -1
- package/dist/collections/Groups.js +1 -0
- package/dist/collections/Groups.js.map +1 -1
- package/dist/collections/Requests.d.ts +1 -1
- package/dist/collections/Requests.js +4 -2
- package/dist/collections/Requests.js.map +1 -1
- package/dist/collections/Tweet.d.ts +10 -0
- package/dist/collections/Tweet.js +17 -0
- package/dist/collections/Tweet.js.map +1 -0
- package/dist/commands/Tweet.js +0 -16
- package/dist/commands/Tweet.js.map +1 -1
- package/dist/commands/User.js +15 -15
- package/dist/commands/User.js.map +1 -1
- package/dist/enums/Api.d.ts +1 -51
- package/dist/enums/Api.js +1 -52
- package/dist/enums/Api.js.map +1 -1
- package/dist/enums/Resource.d.ts +1 -0
- package/dist/enums/Resource.js +1 -0
- package/dist/enums/Resource.js.map +1 -1
- package/dist/enums/Tweet.d.ts +8 -0
- package/dist/enums/Tweet.js +13 -0
- package/dist/enums/Tweet.js.map +1 -0
- package/dist/enums/raw/Tweet.d.ts +11 -1
- package/dist/enums/raw/Tweet.js +13 -2
- package/dist/enums/raw/Tweet.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +3 -5
- package/dist/index.js.map +1 -1
- package/dist/models/RettiwtConfig.d.ts +27 -3
- package/dist/models/RettiwtConfig.js +37 -4
- package/dist/models/RettiwtConfig.js.map +1 -1
- package/dist/models/args/FetchArgs.d.ts +3 -3
- package/dist/models/args/FetchArgs.js +3 -2
- package/dist/models/args/FetchArgs.js.map +1 -1
- package/dist/models/args/PostArgs.d.ts +2 -3
- package/dist/models/args/PostArgs.js +3 -3
- package/dist/models/args/PostArgs.js.map +1 -1
- package/dist/models/auth/AuthCookie.d.ts +1 -1
- package/dist/models/auth/AuthCookie.js +1 -1
- package/dist/models/auth/AuthCredential.d.ts +1 -1
- package/dist/models/auth/AuthCredential.js +1 -1
- package/dist/models/data/List.d.ts +4 -0
- package/dist/models/data/List.js +7 -0
- package/dist/models/data/List.js.map +1 -1
- package/dist/models/data/Notification.d.ts +4 -0
- package/dist/models/data/Notification.js +7 -0
- package/dist/models/data/Notification.js.map +1 -1
- package/dist/models/data/Tweet.d.ts +4 -0
- package/dist/models/data/Tweet.js +7 -0
- package/dist/models/data/Tweet.js.map +1 -1
- package/dist/models/data/User.d.ts +4 -0
- package/dist/models/data/User.js +7 -0
- package/dist/models/data/User.js.map +1 -1
- package/dist/models/errors/TwitterError.d.ts +37 -0
- package/dist/models/errors/TwitterError.js +60 -0
- package/dist/models/errors/TwitterError.js.map +1 -0
- package/dist/requests/List.js +28 -9
- package/dist/requests/List.js.map +1 -1
- package/dist/requests/Tweet.d.ts +2 -1
- package/dist/requests/Tweet.js +94 -38
- package/dist/requests/Tweet.js.map +1 -1
- package/dist/requests/User.js +231 -111
- package/dist/requests/User.js.map +1 -1
- package/dist/services/internal/AuthService.d.ts +6 -6
- package/dist/services/internal/AuthService.js +7 -8
- package/dist/services/internal/AuthService.js.map +1 -1
- package/dist/services/internal/ErrorService.d.ts +5 -76
- package/dist/services/internal/ErrorService.js +13 -116
- package/dist/services/internal/ErrorService.js.map +1 -1
- package/dist/services/internal/TidService.d.ts +4 -5
- package/dist/services/internal/TidService.js +18 -24
- package/dist/services/internal/TidService.js.map +1 -1
- package/dist/services/public/FetcherService.d.ts +4 -3
- package/dist/services/public/FetcherService.js +8 -7
- package/dist/services/public/FetcherService.js.map +1 -1
- package/dist/services/public/ListService.d.ts +6 -4
- package/dist/services/public/ListService.js +6 -4
- package/dist/services/public/ListService.js.map +1 -1
- package/dist/services/public/TweetService.d.ts +96 -74
- package/dist/services/public/TweetService.js +97 -87
- package/dist/services/public/TweetService.js.map +1 -1
- package/dist/services/public/UserService.d.ts +106 -38
- package/dist/services/public/UserService.js +126 -43
- package/dist/services/public/UserService.js.map +1 -1
- package/dist/types/args/FetchArgs.d.ts +8 -0
- package/dist/types/errors/TwitterError.d.ts +30 -0
- package/dist/types/{raw/generic/Error.js → errors/TwitterError.js} +1 -1
- package/dist/types/errors/TwitterError.js.map +1 -0
- package/dist/types/raw/base/Error.d.ts +32 -0
- package/dist/types/raw/base/Error.js +4 -0
- package/dist/types/raw/base/Error.js.map +1 -0
- package/dist/types/raw/generic/Response.d.ts +0 -2
- package/dist/types/raw/tweet/DetailsBulk.d.ts +288 -0
- package/dist/types/raw/tweet/DetailsBulk.js +4 -0
- package/dist/types/raw/tweet/DetailsBulk.js.map +1 -0
- package/dist/types/raw/user/DetailsBulk.d.ts +91 -0
- package/dist/types/raw/user/DetailsBulk.js +4 -0
- package/dist/types/raw/user/DetailsBulk.js.map +1 -0
- package/package.json +1 -1
- package/src/collections/Extractors.ts +8 -2
- package/src/collections/Groups.ts +1 -0
- package/src/collections/Requests.ts +6 -2
- package/src/collections/Tweet.ts +17 -0
- package/src/commands/Tweet.ts +0 -16
- package/src/commands/User.ts +15 -15
- package/src/enums/Api.ts +0 -51
- package/src/enums/Resource.ts +1 -0
- package/src/enums/Tweet.ts +8 -0
- package/src/enums/raw/Tweet.ts +12 -1
- package/src/index.ts +6 -6
- package/src/models/RettiwtConfig.ts +43 -4
- package/src/models/args/FetchArgs.ts +4 -3
- package/src/models/args/PostArgs.ts +3 -4
- package/src/models/auth/AuthCookie.ts +1 -1
- package/src/models/auth/AuthCredential.ts +1 -1
- package/src/models/data/List.ts +9 -0
- package/src/models/data/Notification.ts +10 -0
- package/src/models/data/Tweet.ts +9 -0
- package/src/models/data/User.ts +9 -0
- package/src/models/errors/TwitterError.ts +65 -0
- package/src/requests/List.ts +28 -9
- package/src/requests/Tweet.ts +95 -39
- package/src/requests/User.ts +231 -111
- package/src/services/internal/AuthService.ts +8 -9
- package/src/services/internal/ErrorService.ts +14 -132
- package/src/services/internal/TidService.ts +21 -28
- package/src/services/public/FetcherService.ts +8 -7
- package/src/services/public/ListService.ts +6 -4
- package/src/services/public/TweetService.ts +104 -95
- package/src/services/public/UserService.ts +143 -51
- package/src/types/args/FetchArgs.ts +10 -0
- package/src/types/errors/TwitterError.ts +37 -0
- package/src/types/raw/base/Error.ts +37 -0
- package/src/types/raw/generic/Response.ts +0 -3
- package/src/types/raw/tweet/DetailsBulk.ts +338 -0
- package/src/types/raw/user/DetailsBulk.ts +104 -0
- package/dist/enums/Http.d.ts +0 -68
- package/dist/enums/Http.js +0 -73
- package/dist/enums/Http.js.map +0 -1
- package/dist/models/errors/ApiError.d.ts +0 -15
- package/dist/models/errors/ApiError.js +0 -23
- package/dist/models/errors/ApiError.js.map +0 -1
- package/dist/models/errors/HttpError.d.ts +0 -15
- package/dist/models/errors/HttpError.js +0 -23
- package/dist/models/errors/HttpError.js.map +0 -1
- package/dist/models/errors/RettiwtError.d.ts +0 -9
- package/dist/models/errors/RettiwtError.js +0 -17
- package/dist/models/errors/RettiwtError.js.map +0 -1
- package/dist/models/errors/TimeoutError.d.ts +0 -12
- package/dist/models/errors/TimeoutError.js +0 -19
- package/dist/models/errors/TimeoutError.js.map +0 -1
- package/dist/types/raw/generic/Error.d.ts +0 -30
- package/dist/types/raw/generic/Error.js.map +0 -1
- package/src/enums/Http.ts +0 -68
- package/src/models/errors/ApiError.ts +0 -21
- package/src/models/errors/HttpError.ts +0 -21
- package/src/models/errors/RettiwtError.ts +0 -13
- package/src/models/errors/TimeoutError.ts +0 -15
- package/src/types/raw/generic/Error.ts +0 -35
|
@@ -5,8 +5,10 @@ import { Notification } from '../../models/data/Notification';
|
|
|
5
5
|
import { Tweet } from '../../models/data/Tweet';
|
|
6
6
|
import { User } from '../../models/data/User';
|
|
7
7
|
import { RettiwtConfig } from '../../models/RettiwtConfig';
|
|
8
|
+
import { IUserAffiliatesResponse } from '../../types/raw/user/Affiliates';
|
|
8
9
|
import { IUserBookmarksResponse } from '../../types/raw/user/Bookmarks';
|
|
9
10
|
import { IUserDetailsResponse } from '../../types/raw/user/Details';
|
|
11
|
+
import { IUserDetailsBulkResponse } from '../../types/raw/user/DetailsBulk';
|
|
10
12
|
import { IUserFollowResponse } from '../../types/raw/user/Follow';
|
|
11
13
|
import { IUserFollowedResponse } from '../../types/raw/user/Followed';
|
|
12
14
|
import { IUserFollowersResponse } from '../../types/raw/user/Followers';
|
|
@@ -38,6 +40,49 @@ export class UserService extends FetcherService {
|
|
|
38
40
|
super(config);
|
|
39
41
|
}
|
|
40
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Get the list affiliates of a user.
|
|
45
|
+
*
|
|
46
|
+
* @param id - The ID of the target user. If no id is provided, the logged-in user's id is used.
|
|
47
|
+
* @param count - The number of affiliates to fetch, must be \<= 100.
|
|
48
|
+
* @param cursor - The cursor to the batch of affiliates to fetch.
|
|
49
|
+
*
|
|
50
|
+
* @returns The list of users affiliated to the target user.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
56
|
+
*
|
|
57
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
58
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
59
|
+
*
|
|
60
|
+
* // Fetching the first 100 affiliates of the User with id '1234567890'
|
|
61
|
+
* rettiwt.user.affiliates('1234567890')
|
|
62
|
+
* .then(res => {
|
|
63
|
+
* console.log(res);
|
|
64
|
+
* })
|
|
65
|
+
* .catch(err => {
|
|
66
|
+
* console.log(err);
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
public async affiliates(id?: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
|
|
71
|
+
const resource = EResourceType.USER_AFFILIATES;
|
|
72
|
+
|
|
73
|
+
// Fetching raw list of affiliates
|
|
74
|
+
const response = await this.request<IUserAffiliatesResponse>(resource, {
|
|
75
|
+
id: id ?? this.config.userId,
|
|
76
|
+
count: count,
|
|
77
|
+
cursor: cursor,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Deserializing response
|
|
81
|
+
const data = extractors[resource](response);
|
|
82
|
+
|
|
83
|
+
return data;
|
|
84
|
+
}
|
|
85
|
+
|
|
41
86
|
/**
|
|
42
87
|
* Get the list of bookmarks of the logged in user.
|
|
43
88
|
*
|
|
@@ -47,7 +92,8 @@ export class UserService extends FetcherService {
|
|
|
47
92
|
* @returns The list of tweets bookmarked by the target user.
|
|
48
93
|
*
|
|
49
94
|
* @example
|
|
50
|
-
*
|
|
95
|
+
*
|
|
96
|
+
* ```ts
|
|
51
97
|
* import { Rettiwt } from 'rettiwt-api';
|
|
52
98
|
*
|
|
53
99
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
@@ -81,15 +127,19 @@ export class UserService extends FetcherService {
|
|
|
81
127
|
/**
|
|
82
128
|
* Get the details of a user.
|
|
83
129
|
*
|
|
84
|
-
* @param id - The username/
|
|
130
|
+
* @param id - The username/ID/IDs of the target user/users. If no ID is provided, the logged-in user's ID is used.
|
|
85
131
|
*
|
|
86
132
|
* @returns
|
|
87
133
|
* The details of the given user.
|
|
134
|
+
*
|
|
135
|
+
* If more than one ID is provided, returns a list.
|
|
136
|
+
*
|
|
88
137
|
* If no user matches the given id, returns `undefined`.
|
|
89
138
|
*
|
|
90
139
|
* @example
|
|
91
|
-
*
|
|
92
|
-
*
|
|
140
|
+
*
|
|
141
|
+
* #### Fetching the details of a single user using username
|
|
142
|
+
* ```ts
|
|
93
143
|
* import { Rettiwt } from 'rettiwt-api';
|
|
94
144
|
*
|
|
95
145
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
@@ -106,8 +156,9 @@ export class UserService extends FetcherService {
|
|
|
106
156
|
* ```
|
|
107
157
|
*
|
|
108
158
|
* @example
|
|
109
|
-
*
|
|
110
|
-
*
|
|
159
|
+
*
|
|
160
|
+
* #### Fetching the details of a single user using ID
|
|
161
|
+
* ```ts
|
|
111
162
|
* import { Rettiwt } from 'rettiwt-api';
|
|
112
163
|
*
|
|
113
164
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
@@ -116,14 +167,34 @@ export class UserService extends FetcherService {
|
|
|
116
167
|
* // Fetching the details of the User with id '1234567890'
|
|
117
168
|
* rettiwt.user.details('1234567890')
|
|
118
169
|
* .then(res => {
|
|
119
|
-
* console.log(res);
|
|
170
|
+
* console.log(res); # 'res' is a single tweet
|
|
171
|
+
* })
|
|
172
|
+
* .catch(err => {
|
|
173
|
+
* console.log(err);
|
|
174
|
+
* });
|
|
175
|
+
* ```
|
|
176
|
+
* * @example
|
|
177
|
+
*
|
|
178
|
+
* #### Fetching the details of multiple users
|
|
179
|
+
* ```ts
|
|
180
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
181
|
+
*
|
|
182
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
183
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
184
|
+
*
|
|
185
|
+
* // Fetching the details of the users with IDs '123', '456', '789'
|
|
186
|
+
* rettiwt.user.details(['123', '456', '789'])
|
|
187
|
+
* .then(res => {
|
|
188
|
+
* console.log(res); # 'res' is an array of users
|
|
120
189
|
* })
|
|
121
190
|
* .catch(err => {
|
|
122
191
|
* console.log(err);
|
|
123
192
|
* });
|
|
124
193
|
* ```
|
|
125
194
|
*/
|
|
126
|
-
public async details<T extends string | string[]
|
|
195
|
+
public async details<T extends string | string[] | undefined>(
|
|
196
|
+
id: T,
|
|
197
|
+
): Promise<T extends string | undefined ? User | undefined : User[]> {
|
|
127
198
|
let resource: EResourceType;
|
|
128
199
|
|
|
129
200
|
// If details of multiple users required
|
|
@@ -131,45 +202,51 @@ export class UserService extends FetcherService {
|
|
|
131
202
|
resource = EResourceType.USER_DETAILS_BY_IDS_BULK;
|
|
132
203
|
|
|
133
204
|
// Fetching raw details
|
|
134
|
-
const response = await this.request<
|
|
205
|
+
const response = await this.request<IUserDetailsBulkResponse>(resource, { ids: id });
|
|
135
206
|
|
|
136
207
|
// Deserializing response
|
|
137
208
|
const data = extractors[resource](response, id);
|
|
138
209
|
|
|
139
|
-
return data as T extends string ? User | undefined : User[];
|
|
210
|
+
return data as T extends string | undefined ? User | undefined : User[];
|
|
140
211
|
}
|
|
141
212
|
// If details of single user required
|
|
142
213
|
else {
|
|
143
214
|
// If username is given
|
|
144
|
-
if (isNaN(Number(id))) {
|
|
215
|
+
if (id && isNaN(Number(id))) {
|
|
145
216
|
resource = EResourceType.USER_DETAILS_BY_USERNAME;
|
|
146
217
|
}
|
|
147
|
-
// If id is given
|
|
218
|
+
// If id is given (or not, for self details)
|
|
148
219
|
else {
|
|
149
220
|
resource = EResourceType.USER_DETAILS_BY_ID;
|
|
150
221
|
}
|
|
151
222
|
|
|
223
|
+
// If no ID is given, and not authenticated, skip
|
|
224
|
+
if (!id && !this.config.userId) {
|
|
225
|
+
return undefined as T extends string | undefined ? User | undefined : User[];
|
|
226
|
+
}
|
|
227
|
+
|
|
152
228
|
// Fetching raw details
|
|
153
|
-
const response = await this.request<IUserDetailsResponse>(resource, { id: id });
|
|
229
|
+
const response = await this.request<IUserDetailsResponse>(resource, { id: id ?? this.config.userId });
|
|
154
230
|
|
|
155
231
|
// Deserializing response
|
|
156
232
|
const data = extractors[resource](response);
|
|
157
233
|
|
|
158
|
-
return data as T extends string ? User | undefined : User[];
|
|
234
|
+
return data as T extends string | undefined ? User | undefined : User[];
|
|
159
235
|
}
|
|
160
236
|
}
|
|
161
237
|
|
|
162
238
|
/**
|
|
163
239
|
* Follow a user.
|
|
164
240
|
*
|
|
165
|
-
* @param id - The
|
|
241
|
+
* @param id - The ID the user to be followed.
|
|
166
242
|
*
|
|
167
243
|
* @returns Whether following was successful or not.
|
|
168
244
|
*
|
|
169
245
|
* @throws Code 108 if given user id is invalid.
|
|
170
246
|
*
|
|
171
247
|
* @example
|
|
172
|
-
*
|
|
248
|
+
*
|
|
249
|
+
* ```ts
|
|
173
250
|
* import { Rettiwt } from 'rettiwt-api';
|
|
174
251
|
*
|
|
175
252
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
@@ -205,7 +282,8 @@ export class UserService extends FetcherService {
|
|
|
205
282
|
* @returns - The followed feed of the logged-in user.
|
|
206
283
|
*
|
|
207
284
|
* @example
|
|
208
|
-
*
|
|
285
|
+
*
|
|
286
|
+
* ```ts
|
|
209
287
|
* import { Rettiwt } from 'rettiwt-api';
|
|
210
288
|
*
|
|
211
289
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
@@ -240,14 +318,15 @@ export class UserService extends FetcherService {
|
|
|
240
318
|
/**
|
|
241
319
|
* Get the list followers of a user.
|
|
242
320
|
*
|
|
243
|
-
* @param id - The
|
|
321
|
+
* @param id - The ID of the target user. If no ID is provided, the logged-in user's ID is used.
|
|
244
322
|
* @param count - The number of followers to fetch, must be \<= 100.
|
|
245
323
|
* @param cursor - The cursor to the batch of followers to fetch.
|
|
246
324
|
*
|
|
247
325
|
* @returns The list of users following the target user.
|
|
248
326
|
*
|
|
249
327
|
* @example
|
|
250
|
-
*
|
|
328
|
+
*
|
|
329
|
+
* ```ts
|
|
251
330
|
* import { Rettiwt } from 'rettiwt-api';
|
|
252
331
|
*
|
|
253
332
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
@@ -263,12 +342,12 @@ export class UserService extends FetcherService {
|
|
|
263
342
|
* });
|
|
264
343
|
* ```
|
|
265
344
|
*/
|
|
266
|
-
public async followers(id
|
|
345
|
+
public async followers(id?: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
|
|
267
346
|
const resource = EResourceType.USER_FOLLOWERS;
|
|
268
347
|
|
|
269
348
|
// Fetching raw list of followers
|
|
270
349
|
const response = await this.request<IUserFollowersResponse>(resource, {
|
|
271
|
-
id: id,
|
|
350
|
+
id: id ?? this.config.userId,
|
|
272
351
|
count: count,
|
|
273
352
|
cursor: cursor,
|
|
274
353
|
});
|
|
@@ -282,14 +361,15 @@ export class UserService extends FetcherService {
|
|
|
282
361
|
/**
|
|
283
362
|
* Get the list of users who are followed by a user.
|
|
284
363
|
*
|
|
285
|
-
* @param id - The
|
|
364
|
+
* @param id - The ID of the target user. If no ID is provided, the logged-in user's ID is used.
|
|
286
365
|
* @param count - The number of following to fetch, must be \<= 100.
|
|
287
366
|
* @param cursor - The cursor to the batch of following to fetch.
|
|
288
367
|
*
|
|
289
368
|
* @returns The list of users followed by the target user.
|
|
290
369
|
*
|
|
291
370
|
* @example
|
|
292
|
-
*
|
|
371
|
+
*
|
|
372
|
+
* ```ts
|
|
293
373
|
* import { Rettiwt } from 'rettiwt-api';
|
|
294
374
|
*
|
|
295
375
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
@@ -305,12 +385,12 @@ export class UserService extends FetcherService {
|
|
|
305
385
|
* });
|
|
306
386
|
* ```
|
|
307
387
|
*/
|
|
308
|
-
public async following(id
|
|
388
|
+
public async following(id?: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
|
|
309
389
|
const resource = EResourceType.USER_FOLLOWING;
|
|
310
390
|
|
|
311
391
|
// Fetching raw list of following
|
|
312
392
|
const response = await this.request<IUserFollowingResponse>(resource, {
|
|
313
|
-
id: id,
|
|
393
|
+
id: id ?? this.config.userId,
|
|
314
394
|
count: count,
|
|
315
395
|
cursor: cursor,
|
|
316
396
|
});
|
|
@@ -324,14 +404,15 @@ export class UserService extends FetcherService {
|
|
|
324
404
|
/**
|
|
325
405
|
* Get the highlighted tweets of a user.
|
|
326
406
|
*
|
|
327
|
-
* @param id - The
|
|
407
|
+
* @param id - The ID of the target user. If no ID is provided, the logged-in user's ID is used.
|
|
328
408
|
* @param count - The number of followers to fetch, must be \<= 100.
|
|
329
409
|
* @param cursor - The cursor to the batch of followers to fetch.
|
|
330
410
|
*
|
|
331
411
|
* @returns The list of highlighted tweets of the target user.
|
|
332
412
|
*
|
|
333
413
|
* @example
|
|
334
|
-
*
|
|
414
|
+
*
|
|
415
|
+
* ```ts
|
|
335
416
|
* import { Rettiwt } from 'rettiwt-api';
|
|
336
417
|
*
|
|
337
418
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
@@ -352,7 +433,7 @@ export class UserService extends FetcherService {
|
|
|
352
433
|
|
|
353
434
|
// Fetching raw list of highlights
|
|
354
435
|
const response = await this.request<IUserHighlightsResponse>(resource, {
|
|
355
|
-
id: id,
|
|
436
|
+
id: id ?? this.config.userId,
|
|
356
437
|
count: count,
|
|
357
438
|
cursor: cursor,
|
|
358
439
|
});
|
|
@@ -372,7 +453,8 @@ export class UserService extends FetcherService {
|
|
|
372
453
|
* @returns The list of tweets liked by the target user.
|
|
373
454
|
*
|
|
374
455
|
* @example
|
|
375
|
-
*
|
|
456
|
+
*
|
|
457
|
+
* ```ts
|
|
376
458
|
* import { Rettiwt } from 'rettiwt-api';
|
|
377
459
|
*
|
|
378
460
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
@@ -407,14 +489,15 @@ export class UserService extends FetcherService {
|
|
|
407
489
|
/**
|
|
408
490
|
* Get the media timeline of a user.
|
|
409
491
|
*
|
|
410
|
-
* @param id - The
|
|
492
|
+
* @param id - The ID of the target user. If no ID is provided, the logged-in user's ID is used.
|
|
411
493
|
* @param count - The number of media to fetch, must be \<= 100.
|
|
412
494
|
* @param cursor - The cursor to the batch of media to fetch
|
|
413
495
|
*
|
|
414
496
|
* @returns The media timeline of the target user.
|
|
415
497
|
*
|
|
416
498
|
* @example
|
|
417
|
-
*
|
|
499
|
+
*
|
|
500
|
+
* ```ts
|
|
418
501
|
* import { Rettiwt } from 'rettiwt-api';
|
|
419
502
|
*
|
|
420
503
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
@@ -430,12 +513,12 @@ export class UserService extends FetcherService {
|
|
|
430
513
|
* });
|
|
431
514
|
* ```
|
|
432
515
|
*/
|
|
433
|
-
public async media(id
|
|
516
|
+
public async media(id?: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
|
|
434
517
|
const resource = EResourceType.USER_MEDIA;
|
|
435
518
|
|
|
436
519
|
// Fetching raw list of media
|
|
437
520
|
const response = await this.request<IUserMediaResponse>(resource, {
|
|
438
|
-
id: id,
|
|
521
|
+
id: id ?? this.config.userId,
|
|
439
522
|
count: count,
|
|
440
523
|
cursor: cursor,
|
|
441
524
|
});
|
|
@@ -454,7 +537,8 @@ export class UserService extends FetcherService {
|
|
|
454
537
|
* @returns An async generator that yields new notifications as they are received.
|
|
455
538
|
*
|
|
456
539
|
* @example
|
|
457
|
-
*
|
|
540
|
+
*
|
|
541
|
+
* ```ts
|
|
458
542
|
* import { Rettiwt } from 'rettiwt-api';
|
|
459
543
|
*
|
|
460
544
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
@@ -464,7 +548,7 @@ export class UserService extends FetcherService {
|
|
|
464
548
|
* async function streamNotifications() {
|
|
465
549
|
* try {
|
|
466
550
|
* // Awaiting for the notifications returned by the AsyncGenerator returned by the method
|
|
467
|
-
* for await (const notification of rettiwt.user.notifications(
|
|
551
|
+
* for await (const notification of rettiwt.user.notifications(5000)) {
|
|
468
552
|
* console.log(notification.message);
|
|
469
553
|
* }
|
|
470
554
|
* }
|
|
@@ -526,7 +610,8 @@ export class UserService extends FetcherService {
|
|
|
526
610
|
* @returns - The recommended feed of the logged-in user.
|
|
527
611
|
*
|
|
528
612
|
* @example
|
|
529
|
-
*
|
|
613
|
+
*
|
|
614
|
+
* ```ts
|
|
530
615
|
* import { Rettiwt } from 'rettiwt-api';
|
|
531
616
|
*
|
|
532
617
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
@@ -561,14 +646,15 @@ export class UserService extends FetcherService {
|
|
|
561
646
|
/**
|
|
562
647
|
* Get the reply timeline of a user.
|
|
563
648
|
*
|
|
564
|
-
* @param id - The
|
|
649
|
+
* @param id - The ID of the target user. If no ID is provided, the logged-in user's ID is used.
|
|
565
650
|
* @param count - The number of replies to fetch, must be \<= 20.
|
|
566
651
|
* @param cursor - The cursor to the batch of replies to fetch.
|
|
567
652
|
*
|
|
568
653
|
* @returns The reply timeline of the target user.
|
|
569
654
|
*
|
|
570
655
|
* @example
|
|
571
|
-
*
|
|
656
|
+
*
|
|
657
|
+
* ```ts
|
|
572
658
|
* import { Rettiwt } from 'rettiwt-api';
|
|
573
659
|
*
|
|
574
660
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
@@ -584,14 +670,16 @@ export class UserService extends FetcherService {
|
|
|
584
670
|
* });
|
|
585
671
|
* ```
|
|
586
672
|
*
|
|
587
|
-
* @remarks
|
|
673
|
+
* @remarks
|
|
674
|
+
*
|
|
675
|
+
* If the target user has a pinned tweet, the returned reply timeline has one item extra and this is always the pinned tweet.
|
|
588
676
|
*/
|
|
589
|
-
public async replies(id
|
|
677
|
+
public async replies(id?: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
|
|
590
678
|
const resource = EResourceType.USER_TIMELINE_AND_REPLIES;
|
|
591
679
|
|
|
592
680
|
// Fetching raw list of replies
|
|
593
681
|
const response = await this.request<IUserTweetsAndRepliesResponse>(resource, {
|
|
594
|
-
id: id,
|
|
682
|
+
id: id ?? this.config.userId,
|
|
595
683
|
count: count,
|
|
596
684
|
cursor: cursor,
|
|
597
685
|
});
|
|
@@ -605,14 +693,17 @@ export class UserService extends FetcherService {
|
|
|
605
693
|
/**
|
|
606
694
|
* Get the list of subscriptions of a user.
|
|
607
695
|
*
|
|
608
|
-
* @
|
|
696
|
+
* @deprecated Currently not working.
|
|
697
|
+
*
|
|
698
|
+
* @param id - The ID of the target user. If no ID is provided, the logged-in user's ID is used.
|
|
609
699
|
* @param count - The number of subscriptions to fetch, must be \<= 100.
|
|
610
700
|
* @param cursor - The cursor to the batch of subscriptions to fetch.
|
|
611
701
|
*
|
|
612
702
|
* @returns The list of subscriptions by the target user.
|
|
613
703
|
*
|
|
614
704
|
* @example
|
|
615
|
-
*
|
|
705
|
+
*
|
|
706
|
+
* ```ts
|
|
616
707
|
* import { Rettiwt } from 'rettiwt-api';
|
|
617
708
|
*
|
|
618
709
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
@@ -633,7 +724,7 @@ export class UserService extends FetcherService {
|
|
|
633
724
|
|
|
634
725
|
// Fetching raw list of subscriptions
|
|
635
726
|
const response = await this.request<IUserSubscriptionsResponse>(resource, {
|
|
636
|
-
id: id,
|
|
727
|
+
id: id ?? this.config.userId,
|
|
637
728
|
count: count,
|
|
638
729
|
cursor: cursor,
|
|
639
730
|
});
|
|
@@ -647,14 +738,15 @@ export class UserService extends FetcherService {
|
|
|
647
738
|
/**
|
|
648
739
|
* Get the tweet timeline of a user.
|
|
649
740
|
*
|
|
650
|
-
* @param id - The
|
|
741
|
+
* @param id - The ID of the target user. If no ID is provided, the logged-in user's ID is used.
|
|
651
742
|
* @param count - The number of timeline items to fetch, must be \<= 20.
|
|
652
743
|
* @param cursor - The cursor to the batch of timeline items to fetch.
|
|
653
744
|
*
|
|
654
745
|
* @returns The timeline of the target user.
|
|
655
746
|
*
|
|
656
747
|
* @example
|
|
657
|
-
*
|
|
748
|
+
*
|
|
749
|
+
* ```ts
|
|
658
750
|
* import { Rettiwt } from 'rettiwt-api';
|
|
659
751
|
*
|
|
660
752
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
@@ -671,6 +763,7 @@ export class UserService extends FetcherService {
|
|
|
671
763
|
* ```
|
|
672
764
|
*
|
|
673
765
|
* @remarks
|
|
766
|
+
*
|
|
674
767
|
* - If the target user has a pinned tweet, the returned timeline has one item extra and this is always the pinned tweet.
|
|
675
768
|
* - If timeline is fetched without authenticating, then the most popular tweets of the target user are returned instead.
|
|
676
769
|
*/
|
|
@@ -679,7 +772,7 @@ export class UserService extends FetcherService {
|
|
|
679
772
|
|
|
680
773
|
// Fetching raw list of tweets
|
|
681
774
|
const response = await this.request<IUserTweetsResponse>(resource, {
|
|
682
|
-
id: id,
|
|
775
|
+
id: id ?? this.config.userId,
|
|
683
776
|
count: count,
|
|
684
777
|
cursor: cursor,
|
|
685
778
|
});
|
|
@@ -693,14 +786,13 @@ export class UserService extends FetcherService {
|
|
|
693
786
|
/**
|
|
694
787
|
* Unfollow a user.
|
|
695
788
|
*
|
|
696
|
-
* @param id - The
|
|
789
|
+
* @param id - The ID the user to be unfollowed.
|
|
697
790
|
*
|
|
698
791
|
* @returns Whether unfollowing was successful or not.
|
|
699
792
|
*
|
|
700
|
-
* @throws Code 34 if given user id is invalid.
|
|
701
|
-
*
|
|
702
793
|
* @example
|
|
703
|
-
*
|
|
794
|
+
*
|
|
795
|
+
* ```ts
|
|
704
796
|
* import { Rettiwt } from 'rettiwt-api';
|
|
705
797
|
*
|
|
706
798
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ETweetRepliesSortType } from '../../enums/Tweet';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Options specifying the data that is to be fetched.
|
|
3
5
|
*
|
|
@@ -55,6 +57,14 @@ export interface IFetchArgs {
|
|
|
55
57
|
* - Required only for {@link EResourceType.TWEET_DETAILS_BULK} and {@link EResourceType.USER_DETAILS_BY_IDS_BULK}.
|
|
56
58
|
*/
|
|
57
59
|
ids?: string[];
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The sorting to use for tweet results.
|
|
63
|
+
*
|
|
64
|
+
* @remarks
|
|
65
|
+
* - Only works for {@link EResourceType.TWEET_REPLIES}.
|
|
66
|
+
*/
|
|
67
|
+
sortBy?: ETweetRepliesSortType;
|
|
58
68
|
}
|
|
59
69
|
|
|
60
70
|
/**
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The error thrown by Twitter API.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface ITwitterError extends Error {
|
|
7
|
+
/** The details of each error. */
|
|
8
|
+
details: ITwitterErrorDetails[];
|
|
9
|
+
|
|
10
|
+
/** The error message in the response. */
|
|
11
|
+
message: string;
|
|
12
|
+
|
|
13
|
+
/** The name of the error response. */
|
|
14
|
+
name: string;
|
|
15
|
+
|
|
16
|
+
/** The response status code. */
|
|
17
|
+
status: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The error details.
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export interface ITwitterErrorDetails {
|
|
26
|
+
/** The internal error code. */
|
|
27
|
+
code: number;
|
|
28
|
+
|
|
29
|
+
/** The message associated with the error. */
|
|
30
|
+
message: string;
|
|
31
|
+
|
|
32
|
+
/** The name of the error. */
|
|
33
|
+
name?: string;
|
|
34
|
+
|
|
35
|
+
/** The type of error. */
|
|
36
|
+
type?: string;
|
|
37
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Error details for multiple errors.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export interface IErrorData {
|
|
9
|
+
errors: IErrorDetails[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Error details of a single error.
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export interface IErrorDetails {
|
|
18
|
+
message: string;
|
|
19
|
+
extensions?: IErrorExtensions;
|
|
20
|
+
code: number;
|
|
21
|
+
kind?: string;
|
|
22
|
+
name?: string;
|
|
23
|
+
source?: string;
|
|
24
|
+
tracing?: IErrorTracing;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface IErrorExtensions {
|
|
28
|
+
name: string;
|
|
29
|
+
source: string;
|
|
30
|
+
code: number;
|
|
31
|
+
kind: string;
|
|
32
|
+
tracing: IErrorTracing;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface IErrorTracing {
|
|
36
|
+
trace_id: string;
|
|
37
|
+
}
|