rettiwt-api 2.7.1 → 3.0.1
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 +37 -0
- package/dist/collections/Extractors.js +67 -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 +44 -29
- package/dist/models/data/Tweet.js +74 -15
- package/dist/models/data/Tweet.js.map +1 -1
- package/dist/models/data/User.d.ts +38 -20
- package/dist/models/data/User.js +71 -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 +89 -0
- package/dist/services/public/FetcherService.js +240 -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 +409 -209
- package/dist/services/public/TweetService.js.map +1 -1
- package/dist/services/public/UserService.d.ts +185 -52
- package/dist/services/public/UserService.js +338 -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 +84 -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 +108 -39
- package/src/models/data/User.ts +99 -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 +209 -0
- package/src/services/public/TweetService.ts +384 -179
- package/src/services/public/UserService.ts +319 -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
|
@@ -1,21 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
IUserDetailsResponse,
|
|
3
|
+
IUserFollowersResponse,
|
|
4
|
+
IUserFollowingResponse,
|
|
5
|
+
IUserFollowResponse,
|
|
6
|
+
IUserHighlightsResponse,
|
|
7
|
+
IUserLikesResponse,
|
|
8
|
+
IUserMediaResponse,
|
|
9
|
+
IUserSubscriptionsResponse,
|
|
10
|
+
IUserTweetsAndRepliesResponse,
|
|
11
|
+
IUserTweetsResponse,
|
|
12
|
+
IUserUnfollowResponse,
|
|
13
|
+
} from 'rettiwt-core';
|
|
3
14
|
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
// TYPES
|
|
8
|
-
import { IRettiwtConfig } from '../../types/RettiwtConfig';
|
|
9
|
-
|
|
10
|
-
// MODELS
|
|
11
|
-
import { User } from '../../models/data/User';
|
|
15
|
+
import { extractors } from '../../collections/Extractors';
|
|
16
|
+
import { EResourceType } from '../../enums/Resource';
|
|
17
|
+
import { CursoredData } from '../../models/data/CursoredData';
|
|
12
18
|
import { Tweet } from '../../models/data/Tweet';
|
|
19
|
+
import { User } from '../../models/data/User';
|
|
20
|
+
import { IRettiwtConfig } from '../../types/RettiwtConfig';
|
|
13
21
|
|
|
14
|
-
|
|
15
|
-
import { CursoredData } from '../../models/data/CursoredData';
|
|
22
|
+
import { FetcherService } from './FetcherService';
|
|
16
23
|
|
|
17
24
|
/**
|
|
18
|
-
* Handles
|
|
25
|
+
* Handles interacting with resources related to user account
|
|
19
26
|
*
|
|
20
27
|
* @public
|
|
21
28
|
*/
|
|
@@ -33,9 +40,13 @@ export class UserService extends FetcherService {
|
|
|
33
40
|
* Get the details of a user.
|
|
34
41
|
*
|
|
35
42
|
* @param id - The username/id of the target user.
|
|
36
|
-
* @returns The details of the given user.
|
|
37
43
|
*
|
|
38
|
-
* @
|
|
44
|
+
* @returns
|
|
45
|
+
* The details of the given user.
|
|
46
|
+
* If no user matches the given id, returns `undefined`.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* Fetching the details using username
|
|
39
50
|
* ```
|
|
40
51
|
* import { Rettiwt } from 'rettiwt-api';
|
|
41
52
|
*
|
|
@@ -52,15 +63,16 @@ export class UserService extends FetcherService {
|
|
|
52
63
|
* });
|
|
53
64
|
* ```
|
|
54
65
|
*
|
|
55
|
-
* @example
|
|
66
|
+
* @example
|
|
67
|
+
* Fetching the details using id
|
|
56
68
|
* ```
|
|
57
69
|
* import { Rettiwt } from 'rettiwt-api';
|
|
58
70
|
*
|
|
59
71
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
60
72
|
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
61
73
|
*
|
|
62
|
-
* // Fetching the details of the User with id '
|
|
63
|
-
* rettiwt.user.details('
|
|
74
|
+
* // Fetching the details of the User with id '1234567890'
|
|
75
|
+
* rettiwt.user.details('1234567890')
|
|
64
76
|
* .then(res => {
|
|
65
77
|
* console.log(res);
|
|
66
78
|
* })
|
|
@@ -68,32 +80,115 @@ export class UserService extends FetcherService {
|
|
|
68
80
|
* console.log(err);
|
|
69
81
|
* });
|
|
70
82
|
* ```
|
|
71
|
-
*
|
|
72
|
-
* @public
|
|
73
83
|
*/
|
|
74
|
-
public async details(id: string): Promise<User> {
|
|
75
|
-
let
|
|
84
|
+
public async details(id: string): Promise<User | undefined> {
|
|
85
|
+
let resource: EResourceType;
|
|
76
86
|
|
|
77
87
|
// If username is given
|
|
78
88
|
if (isNaN(Number(id))) {
|
|
79
|
-
|
|
80
|
-
data = await this.fetch<User>(EResourceType.USER_DETAILS, { id: id });
|
|
89
|
+
resource = EResourceType.USER_DETAILS_BY_USERNAME;
|
|
81
90
|
}
|
|
82
91
|
// If id is given
|
|
83
92
|
else {
|
|
84
|
-
|
|
85
|
-
data = await this.fetch<User>(EResourceType.USER_DETAILS_BY_ID, { id: id });
|
|
93
|
+
resource = EResourceType.USER_DETAILS_BY_ID;
|
|
86
94
|
}
|
|
87
95
|
|
|
88
|
-
|
|
96
|
+
// Fetching raw details
|
|
97
|
+
const response = await this.request<IUserDetailsResponse>(resource, { id: id });
|
|
98
|
+
|
|
99
|
+
// Deserializing response
|
|
100
|
+
const data = extractors[resource](response);
|
|
101
|
+
|
|
102
|
+
return data;
|
|
89
103
|
}
|
|
90
104
|
|
|
91
105
|
/**
|
|
92
|
-
*
|
|
106
|
+
* Follow a user.
|
|
107
|
+
*
|
|
108
|
+
* @param id - The id the user to be followed.
|
|
109
|
+
*
|
|
110
|
+
* @returns Whether following was successful or not.
|
|
111
|
+
*
|
|
112
|
+
* @throws Code 108 if given user id is invalid.
|
|
93
113
|
*
|
|
94
|
-
* @
|
|
114
|
+
* @example
|
|
115
|
+
* ```
|
|
116
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
117
|
+
*
|
|
118
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
119
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
120
|
+
*
|
|
121
|
+
* // Following the User with id '1234567890'
|
|
122
|
+
* rettiwt.user.follow('1234567890')
|
|
123
|
+
* .then(res => {
|
|
124
|
+
* console.log(res);
|
|
125
|
+
* })
|
|
126
|
+
* .catch(err => {
|
|
127
|
+
* console.log(err);
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
public async follow(id: string): Promise<boolean> {
|
|
132
|
+
const resource = EResourceType.USER_FOLLOW;
|
|
133
|
+
|
|
134
|
+
// Following the user
|
|
135
|
+
const response = await this.request<IUserFollowResponse>(EResourceType.USER_FOLLOW, { id: id });
|
|
136
|
+
|
|
137
|
+
// Deserializing the response
|
|
138
|
+
const data = extractors[resource](response) ?? false;
|
|
139
|
+
|
|
140
|
+
return data;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Get the list followers of a user.
|
|
145
|
+
*
|
|
146
|
+
* @param id - The id of the target user.
|
|
147
|
+
* @param count - The number of followers to fetch, must be \<= 100.
|
|
148
|
+
* @param cursor - The cursor to the batch of followers to fetch.
|
|
149
|
+
*
|
|
150
|
+
* @returns The list of users following the target user.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```
|
|
154
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
155
|
+
*
|
|
156
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
157
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
158
|
+
*
|
|
159
|
+
* // Fetching the first 100 followers of the User with id '1234567890'
|
|
160
|
+
* rettiwt.user.followers('1234567890')
|
|
161
|
+
* .then(res => {
|
|
162
|
+
* console.log(res);
|
|
163
|
+
* })
|
|
164
|
+
* .catch(err => {
|
|
165
|
+
* console.log(err);
|
|
166
|
+
* });
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
public async followers(id: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
|
|
170
|
+
const resource = EResourceType.USER_FOLLOWERS;
|
|
171
|
+
|
|
172
|
+
// Fetching raw list of followers
|
|
173
|
+
const response = await this.request<IUserFollowersResponse>(resource, {
|
|
174
|
+
id: id,
|
|
175
|
+
count: count,
|
|
176
|
+
cursor: cursor,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// Deserializing response
|
|
180
|
+
const data = extractors[resource](response);
|
|
181
|
+
|
|
182
|
+
return data;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Get the list of users who are followed by a user.
|
|
187
|
+
*
|
|
188
|
+
* @param id - The id of the target user.
|
|
95
189
|
* @param count - The number of following to fetch, must be \<= 100.
|
|
96
190
|
* @param cursor - The cursor to the batch of following to fetch.
|
|
191
|
+
*
|
|
97
192
|
* @returns The list of users followed by the target user.
|
|
98
193
|
*
|
|
99
194
|
* @example
|
|
@@ -103,8 +198,8 @@ export class UserService extends FetcherService {
|
|
|
103
198
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
104
199
|
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
105
200
|
*
|
|
106
|
-
* // Fetching the first 100 following of the User with id '
|
|
107
|
-
* rettiwt.user.following('
|
|
201
|
+
* // Fetching the first 100 following of the User with id '1234567890'
|
|
202
|
+
* rettiwt.user.following('1234567890')
|
|
108
203
|
* .then(res => {
|
|
109
204
|
* console.log(res);
|
|
110
205
|
* })
|
|
@@ -112,27 +207,31 @@ export class UserService extends FetcherService {
|
|
|
112
207
|
* console.log(err);
|
|
113
208
|
* });
|
|
114
209
|
* ```
|
|
115
|
-
*
|
|
116
|
-
* @public
|
|
117
210
|
*/
|
|
118
|
-
public async following(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
211
|
+
public async following(id: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
|
|
212
|
+
const resource = EResourceType.USER_FOLLOWING;
|
|
213
|
+
|
|
214
|
+
// Fetching raw list of following
|
|
215
|
+
const response = await this.request<IUserFollowingResponse>(resource, {
|
|
216
|
+
id: id,
|
|
122
217
|
count: count,
|
|
123
218
|
cursor: cursor,
|
|
124
219
|
});
|
|
125
220
|
|
|
221
|
+
// Deserializing response
|
|
222
|
+
const data = extractors[resource](response);
|
|
223
|
+
|
|
126
224
|
return data;
|
|
127
225
|
}
|
|
128
226
|
|
|
129
227
|
/**
|
|
130
|
-
* Get the
|
|
228
|
+
* Get the highlighted tweets of a user.
|
|
131
229
|
*
|
|
132
|
-
* @param
|
|
230
|
+
* @param id - The id of the target user.
|
|
133
231
|
* @param count - The number of followers to fetch, must be \<= 100.
|
|
134
232
|
* @param cursor - The cursor to the batch of followers to fetch.
|
|
135
|
-
*
|
|
233
|
+
*
|
|
234
|
+
* @returns The list of highlighted tweets of the target user.
|
|
136
235
|
*
|
|
137
236
|
* @example
|
|
138
237
|
* ```
|
|
@@ -141,8 +240,8 @@ export class UserService extends FetcherService {
|
|
|
141
240
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
142
241
|
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
143
242
|
*
|
|
144
|
-
* // Fetching the
|
|
145
|
-
* rettiwt.user.
|
|
243
|
+
* // Fetching the top 100 highlights of the User with id '1234567890'
|
|
244
|
+
* rettiwt.user.highlights('1234567890')
|
|
146
245
|
* .then(res => {
|
|
147
246
|
* console.log(res);
|
|
148
247
|
* })
|
|
@@ -150,26 +249,30 @@ export class UserService extends FetcherService {
|
|
|
150
249
|
* console.log(err);
|
|
151
250
|
* });
|
|
152
251
|
* ```
|
|
153
|
-
*
|
|
154
|
-
* @public
|
|
155
252
|
*/
|
|
156
|
-
public async
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
253
|
+
public async highlights(id: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
|
|
254
|
+
const resource = EResourceType.USER_HIGHLIGHTS;
|
|
255
|
+
|
|
256
|
+
// Fetching raw list of highlights
|
|
257
|
+
const response = await this.request<IUserHighlightsResponse>(resource, {
|
|
258
|
+
id: id,
|
|
160
259
|
count: count,
|
|
161
260
|
cursor: cursor,
|
|
162
261
|
});
|
|
163
262
|
|
|
263
|
+
// Deserializing response
|
|
264
|
+
const data = extractors[resource](response);
|
|
265
|
+
|
|
164
266
|
return data;
|
|
165
267
|
}
|
|
166
268
|
|
|
167
269
|
/**
|
|
168
|
-
* Get the list of tweets liked by
|
|
270
|
+
* Get the list of tweets liked by a user.
|
|
169
271
|
*
|
|
170
|
-
* @param
|
|
272
|
+
* @param id - The id of the target user.
|
|
171
273
|
* @param count - The number of likes to fetch, must be \<= 100.
|
|
172
274
|
* @param cursor - The cursor to the batch of likes to fetch.
|
|
275
|
+
*
|
|
173
276
|
* @returns The list of tweets liked by the target user.
|
|
174
277
|
*
|
|
175
278
|
* @example
|
|
@@ -179,8 +282,8 @@ export class UserService extends FetcherService {
|
|
|
179
282
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
180
283
|
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
181
284
|
*
|
|
182
|
-
* // Fetching the most recent 100 liked Tweets of the User with id '
|
|
183
|
-
* rettiwt.user.likes('
|
|
285
|
+
* // Fetching the most recent 100 liked Tweets of the User with id '1234567890'
|
|
286
|
+
* rettiwt.user.likes('1234567890')
|
|
184
287
|
* .then(res => {
|
|
185
288
|
* console.log(res);
|
|
186
289
|
* })
|
|
@@ -188,27 +291,31 @@ export class UserService extends FetcherService {
|
|
|
188
291
|
* console.log(err);
|
|
189
292
|
* });
|
|
190
293
|
* ```
|
|
191
|
-
*
|
|
192
|
-
* @public
|
|
193
294
|
*/
|
|
194
|
-
public async likes(
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
295
|
+
public async likes(id: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
|
|
296
|
+
const resource = EResourceType.USER_LIKES;
|
|
297
|
+
|
|
298
|
+
// Fetching raw list of likes
|
|
299
|
+
const response = await this.request<IUserLikesResponse>(resource, {
|
|
300
|
+
id: id,
|
|
198
301
|
count: count,
|
|
199
302
|
cursor: cursor,
|
|
200
303
|
});
|
|
201
304
|
|
|
305
|
+
// Deserializing response
|
|
306
|
+
const data = extractors[resource](response);
|
|
307
|
+
|
|
202
308
|
return data;
|
|
203
309
|
}
|
|
204
310
|
|
|
205
311
|
/**
|
|
206
|
-
* Get the timeline of
|
|
312
|
+
* Get the media timeline of a user
|
|
207
313
|
*
|
|
208
|
-
* @param
|
|
209
|
-
* @param count - The number of
|
|
210
|
-
* @param cursor - The cursor to the batch of
|
|
211
|
-
*
|
|
314
|
+
* @param id - The id of the target user.
|
|
315
|
+
* @param count - The number of media to fetch, must be \<= 100.
|
|
316
|
+
* @param cursor - The cursor to the batch of media to fetch
|
|
317
|
+
*
|
|
318
|
+
* @returns The media timeline of the target user.
|
|
212
319
|
*
|
|
213
320
|
* @example
|
|
214
321
|
* ```
|
|
@@ -217,8 +324,8 @@ export class UserService extends FetcherService {
|
|
|
217
324
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
218
325
|
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
219
326
|
*
|
|
220
|
-
* // Fetching the first
|
|
221
|
-
* rettiwt.user.timeline('
|
|
327
|
+
* // Fetching the first 100 timeline media tweets of the User with id '1234567890'
|
|
328
|
+
* rettiwt.user.timeline('1234567890')
|
|
222
329
|
* .then(res => {
|
|
223
330
|
* console.log(res);
|
|
224
331
|
* })
|
|
@@ -226,30 +333,30 @@ export class UserService extends FetcherService {
|
|
|
226
333
|
* console.log(err);
|
|
227
334
|
* });
|
|
228
335
|
* ```
|
|
229
|
-
*
|
|
230
|
-
* @remarks
|
|
231
|
-
* - If the target user has a pinned tweet, the returned timeline has one item extra and this is always the pinned tweet.
|
|
232
|
-
* - If timeline is fetched without authenticating, then the most popular tweets of the target user are returned instead.
|
|
233
|
-
*
|
|
234
|
-
* @public
|
|
235
336
|
*/
|
|
236
|
-
public async
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
337
|
+
public async media(id: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
|
|
338
|
+
const resource = EResourceType.USER_MEDIA;
|
|
339
|
+
|
|
340
|
+
// Fetching raw list of media
|
|
341
|
+
const response = await this.request<IUserMediaResponse>(resource, {
|
|
342
|
+
id: id,
|
|
240
343
|
count: count,
|
|
241
344
|
cursor: cursor,
|
|
242
345
|
});
|
|
243
346
|
|
|
347
|
+
// Deserializing response
|
|
348
|
+
const data = extractors[resource](response);
|
|
349
|
+
|
|
244
350
|
return data;
|
|
245
351
|
}
|
|
246
352
|
|
|
247
353
|
/**
|
|
248
|
-
* Get the reply timeline of
|
|
354
|
+
* Get the reply timeline of a user.
|
|
249
355
|
*
|
|
250
|
-
* @param
|
|
356
|
+
* @param id - The id of the target user.
|
|
251
357
|
* @param count - The number of replies to fetch, must be \<= 20.
|
|
252
358
|
* @param cursor - The cursor to the batch of replies to fetch.
|
|
359
|
+
*
|
|
253
360
|
* @returns The reply timeline of the target user.
|
|
254
361
|
*
|
|
255
362
|
* @example
|
|
@@ -259,8 +366,8 @@ export class UserService extends FetcherService {
|
|
|
259
366
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
260
367
|
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
261
368
|
*
|
|
262
|
-
* // Fetching the first 100 timeline replies of the User with id '
|
|
263
|
-
* rettiwt.user.replies('
|
|
369
|
+
* // Fetching the first 100 timeline replies of the User with id '1234567890'
|
|
370
|
+
* rettiwt.user.replies('1234567890')
|
|
264
371
|
* .then(res => {
|
|
265
372
|
* console.log(res);
|
|
266
373
|
* })
|
|
@@ -270,19 +377,145 @@ export class UserService extends FetcherService {
|
|
|
270
377
|
* ```
|
|
271
378
|
*
|
|
272
379
|
* @remarks If the target user has a pinned tweet, the returned reply timeline has one item extra and this is always the pinned tweet.
|
|
380
|
+
*/
|
|
381
|
+
public async replies(id: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
|
|
382
|
+
const resource = EResourceType.USER_TIMELINE_AND_REPLIES;
|
|
383
|
+
|
|
384
|
+
// Fetching raw list of replies
|
|
385
|
+
const response = await this.request<IUserTweetsAndRepliesResponse>(resource, {
|
|
386
|
+
id: id,
|
|
387
|
+
count: count,
|
|
388
|
+
cursor: cursor,
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
// Deserializing response
|
|
392
|
+
const data = extractors[resource](response);
|
|
393
|
+
|
|
394
|
+
return data;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Get the list of subscriptions of a user.
|
|
399
|
+
*
|
|
400
|
+
* @param id - The id of the target user.
|
|
401
|
+
* @param count - The number of subscriptions to fetch, must be \<= 100.
|
|
402
|
+
* @param cursor - The cursor to the batch of subscriptions to fetch.
|
|
403
|
+
*
|
|
404
|
+
* @returns The list of subscriptions by the target user.
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* ```
|
|
408
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
409
|
+
*
|
|
410
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
411
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
273
412
|
*
|
|
274
|
-
*
|
|
413
|
+
* // Fetching the first 100 subscriptions of the User with id '1234567890'
|
|
414
|
+
* rettiwt.user.subscriptions('1234567890')
|
|
415
|
+
* .then(res => {
|
|
416
|
+
* console.log(res);
|
|
417
|
+
* })
|
|
418
|
+
* .catch(err => {
|
|
419
|
+
* console.log(err);
|
|
420
|
+
* });
|
|
421
|
+
* ```
|
|
275
422
|
*/
|
|
276
|
-
public async
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
423
|
+
public async subscriptions(id: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
|
|
424
|
+
const resource = EResourceType.USER_SUBSCRIPTIONS;
|
|
425
|
+
|
|
426
|
+
// Fetching raw list of subscriptions
|
|
427
|
+
const response = await this.request<IUserSubscriptionsResponse>(resource, {
|
|
428
|
+
id: id,
|
|
280
429
|
count: count,
|
|
281
430
|
cursor: cursor,
|
|
282
431
|
});
|
|
283
432
|
|
|
284
|
-
//
|
|
285
|
-
data
|
|
433
|
+
// Deserializing response
|
|
434
|
+
const data = extractors[resource](response);
|
|
435
|
+
|
|
436
|
+
return data;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Get the tweet timeline of a user.
|
|
441
|
+
*
|
|
442
|
+
* @param id - The id of the target user.
|
|
443
|
+
* @param count - The number of timeline items to fetch, must be \<= 20.
|
|
444
|
+
* @param cursor - The cursor to the batch of timeline items to fetch.
|
|
445
|
+
*
|
|
446
|
+
* @returns The timeline of the target user.
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* ```
|
|
450
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
451
|
+
*
|
|
452
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
453
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
454
|
+
*
|
|
455
|
+
* // Fetching the first 20 timeline tweets of the User with id '1234567890'
|
|
456
|
+
* rettiwt.user.timeline('1234567890')
|
|
457
|
+
* .then(res => {
|
|
458
|
+
* console.log(res);
|
|
459
|
+
* })
|
|
460
|
+
* .catch(err => {
|
|
461
|
+
* console.log(err);
|
|
462
|
+
* });
|
|
463
|
+
* ```
|
|
464
|
+
*
|
|
465
|
+
* @remarks
|
|
466
|
+
* - If the target user has a pinned tweet, the returned timeline has one item extra and this is always the pinned tweet.
|
|
467
|
+
* - If timeline is fetched without authenticating, then the most popular tweets of the target user are returned instead.
|
|
468
|
+
*/
|
|
469
|
+
public async timeline(id: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
|
|
470
|
+
const resource = EResourceType.USER_TIMELINE;
|
|
471
|
+
|
|
472
|
+
// Fetching raw list of tweets
|
|
473
|
+
const response = await this.request<IUserTweetsResponse>(resource, {
|
|
474
|
+
id: id,
|
|
475
|
+
count: count,
|
|
476
|
+
cursor: cursor,
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
// Deserializing response
|
|
480
|
+
const data = extractors[resource](response);
|
|
481
|
+
|
|
482
|
+
return data;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Unfollow a user.
|
|
487
|
+
*
|
|
488
|
+
* @param id - The id the user to be unfollowed.
|
|
489
|
+
*
|
|
490
|
+
* @returns Whether unfollowing was successful or not.
|
|
491
|
+
*
|
|
492
|
+
* @throws Code 34 if given user id is invalid.
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* ```
|
|
496
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
497
|
+
*
|
|
498
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
499
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
500
|
+
*
|
|
501
|
+
* // Unfollowing the User with id '12345678'
|
|
502
|
+
* rettiwt.user.unfollow('12345678')
|
|
503
|
+
* .then(res => {
|
|
504
|
+
* console.log(res);
|
|
505
|
+
* })
|
|
506
|
+
* .catch(err => {
|
|
507
|
+
* console.log(err);
|
|
508
|
+
* });
|
|
509
|
+
* ```
|
|
510
|
+
*/
|
|
511
|
+
public async unfollow(id: string): Promise<boolean> {
|
|
512
|
+
const resource = EResourceType.USER_UNFOLLOW;
|
|
513
|
+
|
|
514
|
+
// Unfollowing the user
|
|
515
|
+
const response = await this.request<IUserUnfollowResponse>(EResourceType.USER_UNFOLLOW, { id: id });
|
|
516
|
+
|
|
517
|
+
// Deserializing the response
|
|
518
|
+
const data = extractors[resource](response) ?? false;
|
|
286
519
|
|
|
287
520
|
return data;
|
|
288
521
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CursoredData } from '../models/data/CursoredData';
|
|
2
|
+
import { Tweet } from '../models/data/Tweet';
|
|
3
|
+
import { User } from '../models/data/User';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Collection of all return types.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export type AllReturnTypes = boolean | CursoredData<Tweet> | CursoredData<User> | string | Tweet | User;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Return type of fetch requests.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export type FetchReturnType = boolean | CursoredData<Tweet> | CursoredData<User> | Tweet | User;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Return type of post requests.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export type PostReturnType = boolean;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The arguments specifying the tweet to be posted.
|
|
3
|
-
*/
|
|
4
|
-
export declare class TweetArgs {
|
|
5
|
-
/**
|
|
6
|
-
* The text content of the tweet.
|
|
7
|
-
*
|
|
8
|
-
* @remarks Length must be \<= 280 characters.
|
|
9
|
-
*/
|
|
10
|
-
text: string;
|
|
11
|
-
/**
|
|
12
|
-
* The media content of the tweet.
|
|
13
|
-
*
|
|
14
|
-
* @remarks Max number of media that can be posted is 4.
|
|
15
|
-
*/
|
|
16
|
-
media?: TweetMediaArgs[];
|
|
17
|
-
/**
|
|
18
|
-
* @param tweet - The tweet arguments specifying the tweet.
|
|
19
|
-
*/
|
|
20
|
-
constructor(tweet: TweetArgs);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* The arguments specifying the media to be posted in a single tweet.
|
|
24
|
-
*
|
|
25
|
-
* @public
|
|
26
|
-
*/
|
|
27
|
-
export declare class TweetMediaArgs {
|
|
28
|
-
/**
|
|
29
|
-
* The path to the media file.
|
|
30
|
-
*
|
|
31
|
-
* @remarks The size of the media file must be \<= 5242880 bytes.
|
|
32
|
-
*/
|
|
33
|
-
path: string;
|
|
34
|
-
/**
|
|
35
|
-
* The list of id of users to be tagged in the media.
|
|
36
|
-
*
|
|
37
|
-
* @remarks Max number of tags is 10.
|
|
38
|
-
*/
|
|
39
|
-
tags?: string[];
|
|
40
|
-
/**
|
|
41
|
-
* @param media - The media arguments specifying the media.
|
|
42
|
-
*/
|
|
43
|
-
constructor(media: TweetMediaArgs);
|
|
44
|
-
}
|