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