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.
Files changed (139) hide show
  1. package/.eslintrc.js +73 -5
  2. package/.tool-versions +1 -0
  3. package/README.md +87 -20
  4. package/dist/Rettiwt.js +0 -1
  5. package/dist/Rettiwt.js.map +1 -1
  6. package/dist/cli.js +2 -4
  7. package/dist/cli.js.map +1 -1
  8. package/dist/collections/Extractors.d.ts +37 -0
  9. package/dist/collections/Extractors.js +67 -0
  10. package/dist/collections/Extractors.js.map +1 -0
  11. package/dist/collections/Groups.d.ts +19 -0
  12. package/dist/collections/Groups.js +55 -0
  13. package/dist/collections/Groups.js.map +1 -0
  14. package/dist/collections/Requests.d.ts +12 -0
  15. package/dist/collections/Requests.js +46 -0
  16. package/dist/collections/Requests.js.map +1 -0
  17. package/dist/commands/Auth.d.ts +6 -0
  18. package/dist/commands/Auth.js +26 -8
  19. package/dist/commands/Auth.js.map +1 -1
  20. package/dist/commands/Tweet.js +237 -82
  21. package/dist/commands/Tweet.js.map +1 -1
  22. package/dist/commands/User.js +197 -36
  23. package/dist/commands/User.js.map +1 -1
  24. package/dist/enums/Api.d.ts +30 -0
  25. package/dist/enums/Api.js +32 -1
  26. package/dist/enums/Api.js.map +1 -1
  27. package/dist/enums/Data.d.ts +9 -0
  28. package/dist/enums/Data.js +14 -0
  29. package/dist/enums/Data.js.map +1 -0
  30. package/dist/enums/Http.d.ts +1 -1
  31. package/dist/enums/Http.js +1 -1
  32. package/dist/enums/Logging.d.ts +6 -5
  33. package/dist/enums/Logging.js +6 -5
  34. package/dist/enums/Logging.js.map +1 -1
  35. package/dist/enums/Resource.d.ts +33 -0
  36. package/dist/enums/Resource.js +42 -0
  37. package/dist/enums/Resource.js.map +1 -0
  38. package/dist/helper/CliUtils.d.ts +1 -1
  39. package/dist/helper/CliUtils.js.map +1 -1
  40. package/dist/index.d.ts +11 -9
  41. package/dist/index.js +11 -14
  42. package/dist/index.js.map +1 -1
  43. package/dist/models/args/FetchArgs.d.ts +129 -0
  44. package/dist/models/args/FetchArgs.js +263 -0
  45. package/dist/models/args/FetchArgs.js.map +1 -0
  46. package/dist/models/args/PostArgs.d.ts +116 -0
  47. package/dist/models/args/PostArgs.js +232 -0
  48. package/dist/models/args/PostArgs.js.map +1 -0
  49. package/dist/models/data/CursoredData.d.ts +11 -11
  50. package/dist/models/data/CursoredData.js +21 -16
  51. package/dist/models/data/CursoredData.js.map +1 -1
  52. package/dist/models/data/List.d.ts +8 -10
  53. package/dist/models/data/List.js +2 -4
  54. package/dist/models/data/List.js.map +1 -1
  55. package/dist/models/data/Tweet.d.ts +44 -29
  56. package/dist/models/data/Tweet.js +74 -15
  57. package/dist/models/data/Tweet.js.map +1 -1
  58. package/dist/models/data/User.d.ts +38 -20
  59. package/dist/models/data/User.js +71 -7
  60. package/dist/models/data/User.js.map +1 -1
  61. package/dist/models/errors/ApiError.d.ts +1 -3
  62. package/dist/models/errors/ApiError.js +1 -4
  63. package/dist/models/errors/ApiError.js.map +1 -1
  64. package/dist/models/errors/DataValidationError.d.ts +30 -0
  65. package/dist/models/errors/DataValidationError.js +34 -0
  66. package/dist/models/errors/DataValidationError.js.map +1 -0
  67. package/dist/models/errors/HttpError.d.ts +1 -3
  68. package/dist/models/errors/HttpError.js +1 -4
  69. package/dist/models/errors/HttpError.js.map +1 -1
  70. package/dist/models/errors/TimeoutError.d.ts +2 -4
  71. package/dist/models/errors/TimeoutError.js +2 -5
  72. package/dist/models/errors/TimeoutError.js.map +1 -1
  73. package/dist/services/internal/ErrorService.d.ts +45 -35
  74. package/dist/services/internal/ErrorService.js +70 -68
  75. package/dist/services/internal/ErrorService.js.map +1 -1
  76. package/dist/services/internal/LogService.d.ts +7 -5
  77. package/dist/services/internal/LogService.js +28 -9
  78. package/dist/services/internal/LogService.js.map +1 -1
  79. package/dist/services/public/AuthService.d.ts +24 -20
  80. package/dist/services/public/AuthService.js +38 -36
  81. package/dist/services/public/AuthService.js.map +1 -1
  82. package/dist/services/public/FetcherService.d.ts +89 -0
  83. package/dist/services/public/FetcherService.js +240 -0
  84. package/dist/services/public/FetcherService.js.map +1 -0
  85. package/dist/services/public/TweetService.d.ts +213 -94
  86. package/dist/services/public/TweetService.js +409 -209
  87. package/dist/services/public/TweetService.js.map +1 -1
  88. package/dist/services/public/UserService.d.ts +185 -52
  89. package/dist/services/public/UserService.js +338 -103
  90. package/dist/services/public/UserService.js.map +1 -1
  91. package/dist/types/ReturnTypes.d.ts +21 -0
  92. package/dist/types/ReturnTypes.js +3 -0
  93. package/dist/types/ReturnTypes.js.map +1 -0
  94. package/package.json +4 -2
  95. package/src/Rettiwt.ts +0 -3
  96. package/src/cli.ts +2 -4
  97. package/src/collections/Extractors.ts +84 -0
  98. package/src/collections/Groups.ts +54 -0
  99. package/src/collections/Requests.ts +52 -0
  100. package/src/commands/Auth.ts +19 -7
  101. package/src/commands/Tweet.ts +179 -91
  102. package/src/commands/User.ts +118 -25
  103. package/src/enums/Api.ts +31 -0
  104. package/src/enums/Data.ts +9 -0
  105. package/src/enums/Http.ts +1 -1
  106. package/src/enums/Logging.ts +6 -5
  107. package/src/enums/Resource.ts +40 -0
  108. package/src/helper/CliUtils.ts +1 -1
  109. package/src/index.ts +41 -14
  110. package/src/models/args/FetchArgs.ts +296 -0
  111. package/src/models/args/PostArgs.ts +263 -0
  112. package/src/models/data/CursoredData.ts +23 -15
  113. package/src/models/data/List.ts +12 -15
  114. package/src/models/data/Tweet.ts +108 -39
  115. package/src/models/data/User.ts +99 -30
  116. package/src/models/errors/ApiError.ts +1 -4
  117. package/src/models/errors/DataValidationError.ts +44 -0
  118. package/src/models/errors/HttpError.ts +1 -4
  119. package/src/models/errors/TimeoutError.ts +2 -5
  120. package/src/services/internal/ErrorService.ts +76 -75
  121. package/src/services/internal/LogService.ts +20 -10
  122. package/src/services/public/AuthService.ts +39 -38
  123. package/src/services/public/FetcherService.ts +209 -0
  124. package/src/services/public/TweetService.ts +384 -179
  125. package/src/services/public/UserService.ts +319 -86
  126. package/src/types/RettiwtConfig.ts +0 -1
  127. package/src/types/ReturnTypes.ts +24 -0
  128. package/dist/models/args/TweetArgs.d.ts +0 -44
  129. package/dist/models/args/TweetArgs.js +0 -82
  130. package/dist/models/args/TweetArgs.js.map +0 -1
  131. package/dist/models/data/Media.d.ts +0 -14
  132. package/dist/models/data/Media.js +0 -19
  133. package/dist/models/data/Media.js.map +0 -1
  134. package/dist/services/internal/FetcherService.d.ts +0 -106
  135. package/dist/services/internal/FetcherService.js +0 -365
  136. package/dist/services/internal/FetcherService.js.map +0 -1
  137. package/src/models/args/TweetArgs.ts +0 -98
  138. package/src/models/data/Media.ts +0 -19
  139. package/src/services/internal/FetcherService.ts +0 -365
@@ -1,21 +1,28 @@
1
- // PACKAGES
2
- import { EResourceType } from 'rettiwt-core';
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
- // SERVICES
5
- import { FetcherService } from '../internal/FetcherService';
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
- // TYPES
15
- import { CursoredData } from '../../models/data/CursoredData';
22
+ import { FetcherService } from './FetcherService';
16
23
 
17
24
  /**
18
- * Handles fetching of data related to user account
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
- * @example Fetching the details of the Twitter user with username 'user1'
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 Fetching the details of the Twitter user with id '12345678'
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 '12345678'
63
- * rettiwt.user.details('12345678')
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 data: CursoredData<User>;
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
- // Fetching the requested data
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
- // Fetching the requested data
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
- return data.list[0];
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
- * Get the list of users who are followed by the given user.
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
- * @param userId - The rest id of the target user.
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 '12345678'
107
- * rettiwt.user.following('12345678')
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(userId: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
119
- // Fetching the requested data
120
- const data = await this.fetch<User>(EResourceType.USER_FOLLOWING, {
121
- id: userId,
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 list followers of a given user.
228
+ * Get the highlighted tweets of a user.
131
229
  *
132
- * @param userId - The rest id of the target user.
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
- * @returns The list of users following the target user.
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 first 100 followers of the User with id '12345678'
145
- * rettiwt.user.followers('12345678')
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 followers(userId: string, count?: number, cursor?: string): Promise<CursoredData<User>> {
157
- // Fetching the requested data
158
- const data = await this.fetch<User>(EResourceType.USER_FOLLOWERS, {
159
- id: userId,
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 the given user.
270
+ * Get the list of tweets liked by a user.
169
271
  *
170
- * @param userId - The rest id of the target user.
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 '12345678'
183
- * rettiwt.user.likes('12345678')
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(userId: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
195
- // Fetching the requested data
196
- const data = await this.fetch<Tweet>(EResourceType.USER_LIKES, {
197
- id: userId,
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 the given user.
312
+ * Get the media timeline of a user
207
313
  *
208
- * @param userId - The rest id of the target user.
209
- * @param count - The number of timeline items to fetch, must be \<= 20.
210
- * @param cursor - The cursor to the batch of timeline items to fetch.
211
- * @returns The timeline of the target user.
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 20 timeline tweets of the User with id '12345678'
221
- * rettiwt.user.timeline('12345678')
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 timeline(userId: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
237
- // Fetching the requested data
238
- const data = await this.fetch<Tweet>(EResourceType.USER_TWEETS, {
239
- id: userId,
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 the given user.
354
+ * Get the reply timeline of a user.
249
355
  *
250
- * @param userId - The rest id of the target user.
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 '12345678'
263
- * rettiwt.user.replies('12345678')
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
- * @public
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 replies(userId: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
277
- // Fetching the requested data
278
- const data = await this.fetch<Tweet>(EResourceType.USER_TWEETS_AND_REPLIES, {
279
- id: userId,
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
- // Filtering out other tweets made by other users in the same threads
285
- data.list = data.list.filter((tweet) => tweet.tweetBy.id == userId);
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
  }
@@ -1,4 +1,3 @@
1
- // TYPES
2
1
  import { IErrorHandler } from './ErrorHandler';
3
2
 
4
3
  /**
@@ -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
- }