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.
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 +10 -0
  9. package/dist/collections/Extractors.js +43 -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 +41 -29
  56. package/dist/models/data/Tweet.js +71 -15
  57. package/dist/models/data/Tweet.js.map +1 -1
  58. package/dist/models/data/User.d.ts +36 -20
  59. package/dist/models/data/User.js +69 -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 +99 -0
  83. package/dist/services/public/FetcherService.js +254 -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 +405 -208
  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 +333 -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 +63 -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 +105 -39
  115. package/src/models/data/User.ts +97 -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 +230 -0
  124. package/src/services/public/TweetService.ts +381 -179
  125. package/src/services/public/UserService.ts +314 -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
@@ -52,12 +52,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
52
52
  };
53
53
  Object.defineProperty(exports, "__esModule", { value: true });
54
54
  exports.UserService = void 0;
55
- // PACKAGES
56
- var rettiwt_core_1 = require("rettiwt-core");
57
- // SERVICES
58
- var FetcherService_1 = require("../internal/FetcherService");
55
+ var Resource_1 = require("../../enums/Resource");
56
+ var FetcherService_1 = require("./FetcherService");
59
57
  /**
60
- * Handles fetching of data related to user account
58
+ * Handles interacting with resources related to user account
61
59
  *
62
60
  * @public
63
61
  */
@@ -75,9 +73,13 @@ var UserService = /** @class */ (function (_super) {
75
73
  * Get the details of a user.
76
74
  *
77
75
  * @param id - The username/id of the target user.
78
- * @returns The details of the given user.
79
76
  *
80
- * @example Fetching the details of the Twitter user with username 'user1'
77
+ * @returns
78
+ * The details of the given user.
79
+ * If no user matches the given id, returns `undefined`.
80
+ *
81
+ * @example
82
+ * Fetching the details using username
81
83
  * ```
82
84
  * import { Rettiwt } from 'rettiwt-api';
83
85
  *
@@ -94,15 +96,16 @@ var UserService = /** @class */ (function (_super) {
94
96
  * });
95
97
  * ```
96
98
  *
97
- * @example Fetching the details of the Twitter user with id '12345678'
99
+ * @example
100
+ * Fetching the details using id
98
101
  * ```
99
102
  * import { Rettiwt } from 'rettiwt-api';
100
103
  *
101
104
  * // Creating a new Rettiwt instance using the given 'API_KEY'
102
105
  * const rettiwt = new Rettiwt({ apiKey: API_KEY });
103
106
  *
104
- * // Fetching the details of the User with id '12345678'
105
- * rettiwt.user.details('12345678')
107
+ * // Fetching the details of the User with id '1234567890'
108
+ * rettiwt.user.details('1234567890')
106
109
  * .then(res => {
107
110
  * console.log(res);
108
111
  * })
@@ -110,37 +113,124 @@ var UserService = /** @class */ (function (_super) {
110
113
  * console.log(err);
111
114
  * });
112
115
  * ```
113
- *
114
- * @public
115
116
  */
116
117
  UserService.prototype.details = function (id) {
117
118
  return __awaiter(this, void 0, void 0, function () {
118
- var data;
119
+ var resource, response, data;
119
120
  return __generator(this, function (_a) {
120
121
  switch (_a.label) {
121
122
  case 0:
122
- if (!isNaN(Number(id))) return [3 /*break*/, 2];
123
- return [4 /*yield*/, this.fetch(rettiwt_core_1.EResourceType.USER_DETAILS, { id: id })];
123
+ // If username is given
124
+ if (isNaN(Number(id))) {
125
+ resource = Resource_1.EResourceType.USER_DETAILS_BY_USERNAME;
126
+ }
127
+ // If id is given
128
+ else {
129
+ resource = Resource_1.EResourceType.USER_DETAILS_BY_ID;
130
+ }
131
+ return [4 /*yield*/, this.request(resource, { id: id })];
124
132
  case 1:
125
- // Fetching the requested data
126
- data = _a.sent();
127
- return [3 /*break*/, 4];
128
- case 2: return [4 /*yield*/, this.fetch(rettiwt_core_1.EResourceType.USER_DETAILS_BY_ID, { id: id })];
129
- case 3:
130
- // Fetching the requested data
131
- data = _a.sent();
132
- _a.label = 4;
133
- case 4: return [2 /*return*/, data.list[0]];
133
+ response = _a.sent();
134
+ data = this.extract(response, resource);
135
+ return [2 /*return*/, data];
134
136
  }
135
137
  });
136
138
  });
137
139
  };
138
140
  /**
139
- * Get the list of users who are followed by the given user.
141
+ * Follow a user.
142
+ *
143
+ * @param id - The id the user to be followed.
144
+ *
145
+ * @returns Whether following was successful or not.
146
+ *
147
+ * @throws Code 108 if given user id is invalid.
148
+ *
149
+ * @example
150
+ * ```
151
+ * import { Rettiwt } from 'rettiwt-api';
140
152
  *
141
- * @param userId - The rest id of the target user.
153
+ * // Creating a new Rettiwt instance using the given 'API_KEY'
154
+ * const rettiwt = new Rettiwt({ apiKey: API_KEY });
155
+ *
156
+ * // Following the User with id '1234567890'
157
+ * rettiwt.user.follow('1234567890')
158
+ * .then(res => {
159
+ * console.log(res);
160
+ * })
161
+ * .catch(err => {
162
+ * console.log(err);
163
+ * });
164
+ * ```
165
+ */
166
+ UserService.prototype.follow = function (id) {
167
+ var _a;
168
+ return __awaiter(this, void 0, void 0, function () {
169
+ var response, data;
170
+ return __generator(this, function (_b) {
171
+ switch (_b.label) {
172
+ case 0: return [4 /*yield*/, this.request(Resource_1.EResourceType.USER_FOLLOW, { id: id })];
173
+ case 1:
174
+ response = _b.sent();
175
+ data = (_a = this.extract(response, Resource_1.EResourceType.USER_FOLLOW)) !== null && _a !== void 0 ? _a : false;
176
+ return [2 /*return*/, data];
177
+ }
178
+ });
179
+ });
180
+ };
181
+ /**
182
+ * Get the list followers of a user.
183
+ *
184
+ * @param id - The id of the target user.
185
+ * @param count - The number of followers to fetch, must be \<= 100.
186
+ * @param cursor - The cursor to the batch of followers to fetch.
187
+ *
188
+ * @returns The list of users following the target user.
189
+ *
190
+ * @example
191
+ * ```
192
+ * import { Rettiwt } from 'rettiwt-api';
193
+ *
194
+ * // Creating a new Rettiwt instance using the given 'API_KEY'
195
+ * const rettiwt = new Rettiwt({ apiKey: API_KEY });
196
+ *
197
+ * // Fetching the first 100 followers of the User with id '1234567890'
198
+ * rettiwt.user.followers('1234567890')
199
+ * .then(res => {
200
+ * console.log(res);
201
+ * })
202
+ * .catch(err => {
203
+ * console.log(err);
204
+ * });
205
+ * ```
206
+ */
207
+ UserService.prototype.followers = function (id, count, cursor) {
208
+ return __awaiter(this, void 0, void 0, function () {
209
+ var resource, response, data;
210
+ return __generator(this, function (_a) {
211
+ switch (_a.label) {
212
+ case 0:
213
+ resource = Resource_1.EResourceType.USER_FOLLOWERS;
214
+ return [4 /*yield*/, this.request(resource, {
215
+ id: id,
216
+ count: count,
217
+ cursor: cursor,
218
+ })];
219
+ case 1:
220
+ response = _a.sent();
221
+ data = this.extract(response, resource);
222
+ return [2 /*return*/, data];
223
+ }
224
+ });
225
+ });
226
+ };
227
+ /**
228
+ * Get the list of users who are followed by a user.
229
+ *
230
+ * @param id - The id of the target user.
142
231
  * @param count - The number of following to fetch, must be \<= 100.
143
232
  * @param cursor - The cursor to the batch of following to fetch.
233
+ *
144
234
  * @returns The list of users followed by the target user.
145
235
  *
146
236
  * @example
@@ -150,8 +240,8 @@ var UserService = /** @class */ (function (_super) {
150
240
  * // Creating a new Rettiwt instance using the given 'API_KEY'
151
241
  * const rettiwt = new Rettiwt({ apiKey: API_KEY });
152
242
  *
153
- * // Fetching the first 100 following of the User with id '12345678'
154
- * rettiwt.user.following('12345678')
243
+ * // Fetching the first 100 following of the User with id '1234567890'
244
+ * rettiwt.user.following('1234567890')
155
245
  * .then(res => {
156
246
  * console.log(res);
157
247
  * })
@@ -159,33 +249,35 @@ var UserService = /** @class */ (function (_super) {
159
249
  * console.log(err);
160
250
  * });
161
251
  * ```
162
- *
163
- * @public
164
252
  */
165
- UserService.prototype.following = function (userId, count, cursor) {
253
+ UserService.prototype.following = function (id, count, cursor) {
166
254
  return __awaiter(this, void 0, void 0, function () {
167
- var data;
255
+ var resource, response, data;
168
256
  return __generator(this, function (_a) {
169
257
  switch (_a.label) {
170
- case 0: return [4 /*yield*/, this.fetch(rettiwt_core_1.EResourceType.USER_FOLLOWING, {
171
- id: userId,
172
- count: count,
173
- cursor: cursor,
174
- })];
258
+ case 0:
259
+ resource = Resource_1.EResourceType.USER_FOLLOWING;
260
+ return [4 /*yield*/, this.request(resource, {
261
+ id: id,
262
+ count: count,
263
+ cursor: cursor,
264
+ })];
175
265
  case 1:
176
- data = _a.sent();
266
+ response = _a.sent();
267
+ data = this.extract(response, resource);
177
268
  return [2 /*return*/, data];
178
269
  }
179
270
  });
180
271
  });
181
272
  };
182
273
  /**
183
- * Get the list followers of a given user.
274
+ * Get the highlighted tweets of a user.
184
275
  *
185
- * @param userId - The rest id of the target user.
276
+ * @param id - The id of the target user.
186
277
  * @param count - The number of followers to fetch, must be \<= 100.
187
278
  * @param cursor - The cursor to the batch of followers to fetch.
188
- * @returns The list of users following the target user.
279
+ *
280
+ * @returns The list of highlighted tweets of the target user.
189
281
  *
190
282
  * @example
191
283
  * ```
@@ -194,8 +286,8 @@ var UserService = /** @class */ (function (_super) {
194
286
  * // Creating a new Rettiwt instance using the given 'API_KEY'
195
287
  * const rettiwt = new Rettiwt({ apiKey: API_KEY });
196
288
  *
197
- * // Fetching the first 100 followers of the User with id '12345678'
198
- * rettiwt.user.followers('12345678')
289
+ * // Fetching the top 100 highlights of the User with id '1234567890'
290
+ * rettiwt.user.highlights('1234567890')
199
291
  * .then(res => {
200
292
  * console.log(res);
201
293
  * })
@@ -203,32 +295,34 @@ var UserService = /** @class */ (function (_super) {
203
295
  * console.log(err);
204
296
  * });
205
297
  * ```
206
- *
207
- * @public
208
298
  */
209
- UserService.prototype.followers = function (userId, count, cursor) {
299
+ UserService.prototype.highlights = function (id, count, cursor) {
210
300
  return __awaiter(this, void 0, void 0, function () {
211
- var data;
301
+ var resource, response, data;
212
302
  return __generator(this, function (_a) {
213
303
  switch (_a.label) {
214
- case 0: return [4 /*yield*/, this.fetch(rettiwt_core_1.EResourceType.USER_FOLLOWERS, {
215
- id: userId,
216
- count: count,
217
- cursor: cursor,
218
- })];
304
+ case 0:
305
+ resource = Resource_1.EResourceType.USER_HIGHLIGHTS;
306
+ return [4 /*yield*/, this.request(resource, {
307
+ id: id,
308
+ count: count,
309
+ cursor: cursor,
310
+ })];
219
311
  case 1:
220
- data = _a.sent();
312
+ response = _a.sent();
313
+ data = this.extract(response, resource);
221
314
  return [2 /*return*/, data];
222
315
  }
223
316
  });
224
317
  });
225
318
  };
226
319
  /**
227
- * Get the list of tweets liked by the given user.
320
+ * Get the list of tweets liked by a user.
228
321
  *
229
- * @param userId - The rest id of the target user.
322
+ * @param id - The id of the target user.
230
323
  * @param count - The number of likes to fetch, must be \<= 100.
231
324
  * @param cursor - The cursor to the batch of likes to fetch.
325
+ *
232
326
  * @returns The list of tweets liked by the target user.
233
327
  *
234
328
  * @example
@@ -238,8 +332,8 @@ var UserService = /** @class */ (function (_super) {
238
332
  * // Creating a new Rettiwt instance using the given 'API_KEY'
239
333
  * const rettiwt = new Rettiwt({ apiKey: API_KEY });
240
334
  *
241
- * // Fetching the most recent 100 liked Tweets of the User with id '12345678'
242
- * rettiwt.user.likes('12345678')
335
+ * // Fetching the most recent 100 liked Tweets of the User with id '1234567890'
336
+ * rettiwt.user.likes('1234567890')
243
337
  * .then(res => {
244
338
  * console.log(res);
245
339
  * })
@@ -247,33 +341,35 @@ var UserService = /** @class */ (function (_super) {
247
341
  * console.log(err);
248
342
  * });
249
343
  * ```
250
- *
251
- * @public
252
344
  */
253
- UserService.prototype.likes = function (userId, count, cursor) {
345
+ UserService.prototype.likes = function (id, count, cursor) {
254
346
  return __awaiter(this, void 0, void 0, function () {
255
- var data;
347
+ var resource, response, data;
256
348
  return __generator(this, function (_a) {
257
349
  switch (_a.label) {
258
- case 0: return [4 /*yield*/, this.fetch(rettiwt_core_1.EResourceType.USER_LIKES, {
259
- id: userId,
260
- count: count,
261
- cursor: cursor,
262
- })];
350
+ case 0:
351
+ resource = Resource_1.EResourceType.USER_LIKES;
352
+ return [4 /*yield*/, this.request(resource, {
353
+ id: id,
354
+ count: count,
355
+ cursor: cursor,
356
+ })];
263
357
  case 1:
264
- data = _a.sent();
358
+ response = _a.sent();
359
+ data = this.extract(response, resource);
265
360
  return [2 /*return*/, data];
266
361
  }
267
362
  });
268
363
  });
269
364
  };
270
365
  /**
271
- * Get the timeline of the given user.
366
+ * Get the media timeline of a user
272
367
  *
273
- * @param userId - The rest id of the target user.
274
- * @param count - The number of timeline items to fetch, must be \<= 20.
275
- * @param cursor - The cursor to the batch of timeline items to fetch.
276
- * @returns The timeline of the target user.
368
+ * @param id - The id of the target user.
369
+ * @param count - The number of media to fetch, must be \<= 100.
370
+ * @param cursor - The cursor to the batch of media to fetch
371
+ *
372
+ * @returns The media timeline of the target user.
277
373
  *
278
374
  * @example
279
375
  * ```
@@ -282,8 +378,8 @@ var UserService = /** @class */ (function (_super) {
282
378
  * // Creating a new Rettiwt instance using the given 'API_KEY'
283
379
  * const rettiwt = new Rettiwt({ apiKey: API_KEY });
284
380
  *
285
- * // Fetching the first 20 timeline tweets of the User with id '12345678'
286
- * rettiwt.user.timeline('12345678')
381
+ * // Fetching the first 100 timeline media tweets of the User with id '1234567890'
382
+ * rettiwt.user.timeline('1234567890')
287
383
  * .then(res => {
288
384
  * console.log(res);
289
385
  * })
@@ -291,36 +387,34 @@ var UserService = /** @class */ (function (_super) {
291
387
  * console.log(err);
292
388
  * });
293
389
  * ```
294
- *
295
- * @remarks
296
- * - If the target user has a pinned tweet, the returned timeline has one item extra and this is always the pinned tweet.
297
- * - If timeline is fetched without authenticating, then the most popular tweets of the target user are returned instead.
298
- *
299
- * @public
300
390
  */
301
- UserService.prototype.timeline = function (userId, count, cursor) {
391
+ UserService.prototype.media = function (id, count, cursor) {
302
392
  return __awaiter(this, void 0, void 0, function () {
303
- var data;
393
+ var resource, response, data;
304
394
  return __generator(this, function (_a) {
305
395
  switch (_a.label) {
306
- case 0: return [4 /*yield*/, this.fetch(rettiwt_core_1.EResourceType.USER_TWEETS, {
307
- id: userId,
308
- count: count,
309
- cursor: cursor,
310
- })];
396
+ case 0:
397
+ resource = Resource_1.EResourceType.USER_MEDIA;
398
+ return [4 /*yield*/, this.request(resource, {
399
+ id: id,
400
+ count: count,
401
+ cursor: cursor,
402
+ })];
311
403
  case 1:
312
- data = _a.sent();
404
+ response = _a.sent();
405
+ data = this.extract(response, resource);
313
406
  return [2 /*return*/, data];
314
407
  }
315
408
  });
316
409
  });
317
410
  };
318
411
  /**
319
- * Get the reply timeline of the given user.
412
+ * Get the reply timeline of a user.
320
413
  *
321
- * @param userId - The rest id of the target user.
414
+ * @param id - The id of the target user.
322
415
  * @param count - The number of replies to fetch, must be \<= 20.
323
416
  * @param cursor - The cursor to the batch of replies to fetch.
417
+ *
324
418
  * @returns The reply timeline of the target user.
325
419
  *
326
420
  * @example
@@ -330,8 +424,8 @@ var UserService = /** @class */ (function (_super) {
330
424
  * // Creating a new Rettiwt instance using the given 'API_KEY'
331
425
  * const rettiwt = new Rettiwt({ apiKey: API_KEY });
332
426
  *
333
- * // Fetching the first 100 timeline replies of the User with id '12345678'
334
- * rettiwt.user.replies('12345678')
427
+ * // Fetching the first 100 timeline replies of the User with id '1234567890'
428
+ * rettiwt.user.replies('1234567890')
335
429
  * .then(res => {
336
430
  * console.log(res);
337
431
  * })
@@ -341,23 +435,159 @@ var UserService = /** @class */ (function (_super) {
341
435
  * ```
342
436
  *
343
437
  * @remarks If the target user has a pinned tweet, the returned reply timeline has one item extra and this is always the pinned tweet.
438
+ */
439
+ UserService.prototype.replies = function (id, count, cursor) {
440
+ return __awaiter(this, void 0, void 0, function () {
441
+ var resource, response, data;
442
+ return __generator(this, function (_a) {
443
+ switch (_a.label) {
444
+ case 0:
445
+ resource = Resource_1.EResourceType.USER_TIMELINE_AND_REPLIES;
446
+ return [4 /*yield*/, this.request(resource, {
447
+ id: id,
448
+ count: count,
449
+ cursor: cursor,
450
+ })];
451
+ case 1:
452
+ response = _a.sent();
453
+ data = this.extract(response, resource);
454
+ return [2 /*return*/, data];
455
+ }
456
+ });
457
+ });
458
+ };
459
+ /**
460
+ * Get the list of subscriptions of a user.
461
+ *
462
+ * @param id - The id of the target user.
463
+ * @param count - The number of subscriptions to fetch, must be \<= 100.
464
+ * @param cursor - The cursor to the batch of subscriptions to fetch.
465
+ *
466
+ * @returns The list of subscriptions by the target user.
467
+ *
468
+ * @example
469
+ * ```
470
+ * import { Rettiwt } from 'rettiwt-api';
471
+ *
472
+ * // Creating a new Rettiwt instance using the given 'API_KEY'
473
+ * const rettiwt = new Rettiwt({ apiKey: API_KEY });
474
+ *
475
+ * // Fetching the first 100 subscriptions of the User with id '1234567890'
476
+ * rettiwt.user.subscriptions('1234567890')
477
+ * .then(res => {
478
+ * console.log(res);
479
+ * })
480
+ * .catch(err => {
481
+ * console.log(err);
482
+ * });
483
+ * ```
484
+ */
485
+ UserService.prototype.subscriptions = function (id, count, cursor) {
486
+ return __awaiter(this, void 0, void 0, function () {
487
+ var resource, response, data;
488
+ return __generator(this, function (_a) {
489
+ switch (_a.label) {
490
+ case 0:
491
+ resource = Resource_1.EResourceType.USER_SUBSCRIPTIONS;
492
+ return [4 /*yield*/, this.request(resource, {
493
+ id: id,
494
+ count: count,
495
+ cursor: cursor,
496
+ })];
497
+ case 1:
498
+ response = _a.sent();
499
+ data = this.extract(response, resource);
500
+ return [2 /*return*/, data];
501
+ }
502
+ });
503
+ });
504
+ };
505
+ /**
506
+ * Get the tweet timeline of a user.
507
+ *
508
+ * @param id - The id of the target user.
509
+ * @param count - The number of timeline items to fetch, must be \<= 20.
510
+ * @param cursor - The cursor to the batch of timeline items to fetch.
511
+ *
512
+ * @returns The timeline of the target user.
513
+ *
514
+ * @example
515
+ * ```
516
+ * import { Rettiwt } from 'rettiwt-api';
517
+ *
518
+ * // Creating a new Rettiwt instance using the given 'API_KEY'
519
+ * const rettiwt = new Rettiwt({ apiKey: API_KEY });
520
+ *
521
+ * // Fetching the first 20 timeline tweets of the User with id '1234567890'
522
+ * rettiwt.user.timeline('1234567890')
523
+ * .then(res => {
524
+ * console.log(res);
525
+ * })
526
+ * .catch(err => {
527
+ * console.log(err);
528
+ * });
529
+ * ```
344
530
  *
345
- * @public
531
+ * @remarks
532
+ * - If the target user has a pinned tweet, the returned timeline has one item extra and this is always the pinned tweet.
533
+ * - If timeline is fetched without authenticating, then the most popular tweets of the target user are returned instead.
346
534
  */
347
- UserService.prototype.replies = function (userId, count, cursor) {
535
+ UserService.prototype.timeline = function (id, count, cursor) {
348
536
  return __awaiter(this, void 0, void 0, function () {
349
- var data;
537
+ var resource, response, data;
350
538
  return __generator(this, function (_a) {
351
539
  switch (_a.label) {
352
- case 0: return [4 /*yield*/, this.fetch(rettiwt_core_1.EResourceType.USER_TWEETS_AND_REPLIES, {
353
- id: userId,
354
- count: count,
355
- cursor: cursor,
356
- })];
540
+ case 0:
541
+ resource = Resource_1.EResourceType.USER_TIMELINE;
542
+ return [4 /*yield*/, this.request(resource, {
543
+ id: id,
544
+ count: count,
545
+ cursor: cursor,
546
+ })];
547
+ case 1:
548
+ response = _a.sent();
549
+ data = this.extract(response, resource);
550
+ return [2 /*return*/, data];
551
+ }
552
+ });
553
+ });
554
+ };
555
+ /**
556
+ * Unfollow a user.
557
+ *
558
+ * @param id - The id the user to be unfollowed.
559
+ *
560
+ * @returns Whether unfollowing was successful or not.
561
+ *
562
+ * @throws Code 34 if given user id is invalid.
563
+ *
564
+ * @example
565
+ * ```
566
+ * import { Rettiwt } from 'rettiwt-api';
567
+ *
568
+ * // Creating a new Rettiwt instance using the given 'API_KEY'
569
+ * const rettiwt = new Rettiwt({ apiKey: API_KEY });
570
+ *
571
+ * // Unfollowing the User with id '12345678'
572
+ * rettiwt.user.unfollow('12345678')
573
+ * .then(res => {
574
+ * console.log(res);
575
+ * })
576
+ * .catch(err => {
577
+ * console.log(err);
578
+ * });
579
+ * ```
580
+ */
581
+ UserService.prototype.unfollow = function (id) {
582
+ var _a;
583
+ return __awaiter(this, void 0, void 0, function () {
584
+ var response, data;
585
+ return __generator(this, function (_b) {
586
+ switch (_b.label) {
587
+ case 0: return [4 /*yield*/, this.request(Resource_1.EResourceType.USER_UNFOLLOW, { id: id })];
357
588
  case 1:
358
- data = _a.sent();
359
- // Filtering out other tweets made by other users in the same threads
360
- data.list = data.list.filter(function (tweet) { return tweet.tweetBy.id == userId; });
589
+ response = _b.sent();
590
+ data = (_a = this.extract(response, Resource_1.EResourceType.USER_UNFOLLOW)) !== null && _a !== void 0 ? _a : false;
361
591
  return [2 /*return*/, data];
362
592
  }
363
593
  });
@@ -1 +1 @@
1
- {"version":3,"file":"UserService.js","sourceRoot":"","sources":["../../../src/services/public/UserService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,WAAW;AACX,6CAA6C;AAE7C,WAAW;AACX,6DAA4D;AAY5D;;;;GAIG;AACH;IAAiC,+BAAc;IAC9C;;;;OAIG;IACH,qBAAmB,MAAuB;eACzC,kBAAM,MAAM,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyCG;IACU,6BAAO,GAApB,UAAqB,EAAU;;;;;;6BAI1B,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,EAAjB,wBAAiB;wBAEb,qBAAM,IAAI,CAAC,KAAK,CAAO,4BAAa,CAAC,YAAY,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAA;;wBADrE,8BAA8B;wBAC9B,IAAI,GAAG,SAA8D,CAAC;;4BAK/D,qBAAM,IAAI,CAAC,KAAK,CAAO,4BAAa,CAAC,kBAAkB,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAA;;wBAD3E,8BAA8B;wBAC9B,IAAI,GAAG,SAAoE,CAAC;;4BAG7E,sBAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAC;;;;KACpB;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACU,+BAAS,GAAtB,UAAuB,MAAc,EAAE,KAAc,EAAE,MAAe;;;;;4BAExD,qBAAM,IAAI,CAAC,KAAK,CAAO,4BAAa,CAAC,cAAc,EAAE;4BACjE,EAAE,EAAE,MAAM;4BACV,KAAK,EAAE,KAAK;4BACZ,MAAM,EAAE,MAAM;yBACd,CAAC,EAAA;;wBAJI,IAAI,GAAG,SAIX;wBAEF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;wBAJI,QAAQ,GAAG,SAIf;wBAGI,IAAI,GAAG,IAAI,CAAC,OAAO,CAAsB,QAAQ,EAAE,QAAQ,CAAE,CAAC;wBAEpE,sBAAO,IAAI,EAAC;;;;KACZ;IAED;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACU,8BAAQ,GAArB,UAAsB,EAAU;;;;;;4BAEd,qBAAM,IAAI,CAAC,OAAO,CAAwB,wBAAa,CAAC,aAAa,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAA;;wBAA7F,QAAQ,GAAG,SAAkF;wBAG7F,IAAI,GAAG,MAAA,IAAI,CAAC,OAAO,CAAU,QAAQ,EAAE,wBAAa,CAAC,aAAa,CAAC,mCAAI,KAAK,CAAC;wBAEnF,sBAAO,IAAI,EAAC;;;;KACZ;IACF,kBAAC;AAAD,CAAC,AAzeD,CAAiC,+BAAc,GAye9C;AAzeY,kCAAW"}
@@ -0,0 +1,21 @@
1
+ import { CursoredData } from '../models/data/CursoredData';
2
+ import { Tweet } from '../models/data/Tweet';
3
+ import { User } from '../models/data/User';
4
+ /**
5
+ * Collection of all return types.
6
+ *
7
+ * @internal
8
+ */
9
+ export type AllReturnTypes = boolean | CursoredData<Tweet> | CursoredData<User> | string | Tweet | User;
10
+ /**
11
+ * Return type of fetch requests.
12
+ *
13
+ * @internal
14
+ */
15
+ export type FetchReturnType = boolean | CursoredData<Tweet> | CursoredData<User> | Tweet | User;
16
+ /**
17
+ * Return type of post requests.
18
+ *
19
+ * @internal
20
+ */
21
+ export type PostReturnType = boolean;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ReturnTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReturnTypes.js","sourceRoot":"","sources":["../../src/types/ReturnTypes.ts"],"names":[],"mappings":""}