rettiwt-api 2.7.1 → 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
|
@@ -75,13 +75,11 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
|
|
|
75
75
|
};
|
|
76
76
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
77
77
|
exports.TweetService = void 0;
|
|
78
|
-
|
|
79
|
-
var
|
|
80
|
-
|
|
81
|
-
var FetcherService_1 = require("../internal/FetcherService");
|
|
82
|
-
var TweetArgs_1 = require("../../models/args/TweetArgs");
|
|
78
|
+
var fs_1 = require("fs");
|
|
79
|
+
var Resource_1 = require("../../enums/Resource");
|
|
80
|
+
var FetcherService_1 = require("./FetcherService");
|
|
83
81
|
/**
|
|
84
|
-
* Handles
|
|
82
|
+
* Handles interacting with resources related to tweets.
|
|
85
83
|
*
|
|
86
84
|
* @public
|
|
87
85
|
*/
|
|
@@ -99,7 +97,10 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
99
97
|
* Get the details of a tweet.
|
|
100
98
|
*
|
|
101
99
|
* @param id - The id of the target tweet.
|
|
102
|
-
*
|
|
100
|
+
*
|
|
101
|
+
* @returns
|
|
102
|
+
* The details of the tweet with the given id.
|
|
103
|
+
* If no tweet matches the given id, returns `undefined`.
|
|
103
104
|
*
|
|
104
105
|
* @example
|
|
105
106
|
* ```
|
|
@@ -108,8 +109,8 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
108
109
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
109
110
|
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
110
111
|
*
|
|
111
|
-
* // Fetching the details of the tweet with the id '
|
|
112
|
-
* rettiwt.tweet.details('
|
|
112
|
+
* // Fetching the details of the tweet with the id '1234567890'
|
|
113
|
+
* rettiwt.tweet.details('1234567890')
|
|
113
114
|
* .then(res => {
|
|
114
115
|
* console.log(res);
|
|
115
116
|
* })
|
|
@@ -117,29 +118,29 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
117
118
|
* console.log(err);
|
|
118
119
|
* });
|
|
119
120
|
* ```
|
|
120
|
-
*
|
|
121
|
-
* @public
|
|
122
121
|
*/
|
|
123
122
|
TweetService.prototype.details = function (id) {
|
|
124
123
|
return __awaiter(this, void 0, void 0, function () {
|
|
125
|
-
var data;
|
|
124
|
+
var resource, response, data;
|
|
126
125
|
return __generator(this, function (_a) {
|
|
127
126
|
switch (_a.label) {
|
|
128
|
-
case 0:
|
|
127
|
+
case 0:
|
|
128
|
+
resource = Resource_1.EResourceType.TWEET_DETAILS;
|
|
129
|
+
return [4 /*yield*/, this.request(resource, { id: id })];
|
|
129
130
|
case 1:
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
response = _a.sent();
|
|
132
|
+
data = this.extract(response, resource);
|
|
133
|
+
return [2 /*return*/, data];
|
|
132
134
|
}
|
|
133
135
|
});
|
|
134
136
|
});
|
|
135
137
|
};
|
|
136
138
|
/**
|
|
137
|
-
*
|
|
139
|
+
* Like a tweet.
|
|
138
140
|
*
|
|
139
|
-
* @param
|
|
140
|
-
*
|
|
141
|
-
* @
|
|
142
|
-
* @returns The list of tweets that match the given filter.
|
|
141
|
+
* @param id - The id of the tweet to be liked.
|
|
142
|
+
*
|
|
143
|
+
* @returns Whether liking was successful or not.
|
|
143
144
|
*
|
|
144
145
|
* @example
|
|
145
146
|
* ```
|
|
@@ -148,8 +149,8 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
148
149
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
149
150
|
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
150
151
|
*
|
|
151
|
-
* //
|
|
152
|
-
* rettiwt.tweet.
|
|
152
|
+
* // Liking the Tweet with id '1234567890'
|
|
153
|
+
* rettiwt.tweet.like('1234567890')
|
|
153
154
|
* .then(res => {
|
|
154
155
|
* console.log(res);
|
|
155
156
|
* })
|
|
@@ -157,36 +158,32 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
157
158
|
* console.log(err);
|
|
158
159
|
* });
|
|
159
160
|
* ```
|
|
160
|
-
*
|
|
161
|
-
* @remarks For details about available filters, refer to {@link TweetFilter}
|
|
162
|
-
*
|
|
163
|
-
* @public
|
|
164
161
|
*/
|
|
165
|
-
TweetService.prototype.
|
|
162
|
+
TweetService.prototype.like = function (id) {
|
|
163
|
+
var _a;
|
|
166
164
|
return __awaiter(this, void 0, void 0, function () {
|
|
167
|
-
var data;
|
|
168
|
-
return __generator(this, function (
|
|
169
|
-
switch (
|
|
170
|
-
case 0: return [4 /*yield*/, this.
|
|
171
|
-
|
|
172
|
-
count: count,
|
|
173
|
-
cursor: cursor,
|
|
165
|
+
var response, data;
|
|
166
|
+
return __generator(this, function (_b) {
|
|
167
|
+
switch (_b.label) {
|
|
168
|
+
case 0: return [4 /*yield*/, this.request(Resource_1.EResourceType.TWEET_LIKE, {
|
|
169
|
+
id: id,
|
|
174
170
|
})];
|
|
175
171
|
case 1:
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
data.list.sort(function (a, b) { return new Date(b.createdAt).valueOf() - new Date(a.createdAt).valueOf(); });
|
|
172
|
+
response = _b.sent();
|
|
173
|
+
data = (_a = this.extract(response, Resource_1.EResourceType.TWEET_LIKE)) !== null && _a !== void 0 ? _a : false;
|
|
179
174
|
return [2 /*return*/, data];
|
|
180
175
|
}
|
|
181
176
|
});
|
|
182
177
|
});
|
|
183
178
|
};
|
|
184
179
|
/**
|
|
185
|
-
*
|
|
180
|
+
* Get the list of users who liked a tweet.
|
|
186
181
|
*
|
|
187
|
-
* @param
|
|
188
|
-
* @param
|
|
189
|
-
* @
|
|
182
|
+
* @param id - The id of the target tweet.
|
|
183
|
+
* @param count - The number of likers to fetch, must be \<= 100.
|
|
184
|
+
* @param cursor - The cursor to the batch of likers to fetch.
|
|
185
|
+
*
|
|
186
|
+
* @returns The list of users who liked the given tweet.
|
|
190
187
|
*
|
|
191
188
|
* @example
|
|
192
189
|
* ```
|
|
@@ -195,83 +192,44 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
195
192
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
196
193
|
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
197
194
|
*
|
|
198
|
-
* //
|
|
199
|
-
* (
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
* console.log(err);
|
|
207
|
-
* }
|
|
208
|
-
* })();
|
|
195
|
+
* // Fetching the most recent 100 likers of the Tweet with id '1234567890'
|
|
196
|
+
* rettiwt.tweet.likers('1234567890')
|
|
197
|
+
* .then(res => {
|
|
198
|
+
* console.log(res);
|
|
199
|
+
* })
|
|
200
|
+
* .catch(err => {
|
|
201
|
+
* console.log(err);
|
|
202
|
+
* });
|
|
209
203
|
* ```
|
|
210
|
-
*
|
|
211
|
-
* @public
|
|
212
204
|
*/
|
|
213
|
-
TweetService.prototype.
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
switch (_b.label) {
|
|
205
|
+
TweetService.prototype.likers = function (id, count, cursor) {
|
|
206
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
207
|
+
var resource, response, data;
|
|
208
|
+
return __generator(this, function (_a) {
|
|
209
|
+
switch (_a.label) {
|
|
219
210
|
case 0:
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
211
|
+
resource = Resource_1.EResourceType.TWEET_LIKERS;
|
|
212
|
+
return [4 /*yield*/, this.request(resource, {
|
|
213
|
+
id: id,
|
|
214
|
+
count: count,
|
|
215
|
+
cursor: cursor,
|
|
216
|
+
})];
|
|
225
217
|
case 1:
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
return [
|
|
229
|
-
case 2:
|
|
230
|
-
// Pause execution for the specified polling interval before proceeding to the next iteration
|
|
231
|
-
_b.sent();
|
|
232
|
-
return [4 /*yield*/, __await(this.search(__assign(__assign({}, filter), { startDate: startDate, sinceId: sinceId }), undefined, cursor))];
|
|
233
|
-
case 3:
|
|
234
|
-
tweets = _b.sent();
|
|
235
|
-
_i = 0, _a = tweets.list;
|
|
236
|
-
_b.label = 4;
|
|
237
|
-
case 4:
|
|
238
|
-
if (!(_i < _a.length)) return [3 /*break*/, 8];
|
|
239
|
-
tweet = _a[_i];
|
|
240
|
-
return [4 /*yield*/, __await(tweet)];
|
|
241
|
-
case 5: return [4 /*yield*/, _b.sent()];
|
|
242
|
-
case 6:
|
|
243
|
-
_b.sent();
|
|
244
|
-
_b.label = 7;
|
|
245
|
-
case 7:
|
|
246
|
-
_i++;
|
|
247
|
-
return [3 /*break*/, 4];
|
|
248
|
-
case 8:
|
|
249
|
-
// Store the most recent tweet ID from this batch
|
|
250
|
-
if (tweets.list.length > 0 && cursor === undefined) {
|
|
251
|
-
nextSinceId = tweets.list[0].id;
|
|
252
|
-
}
|
|
253
|
-
// If there are more tweets to fetch, adjust the cursor value
|
|
254
|
-
if (tweets.list.length > 0 && tweets.next) {
|
|
255
|
-
cursor = tweets.next.value;
|
|
256
|
-
}
|
|
257
|
-
// Else, start the next iteration from this batch's most recent tweet
|
|
258
|
-
else {
|
|
259
|
-
sinceId = nextSinceId;
|
|
260
|
-
cursor = undefined;
|
|
261
|
-
}
|
|
262
|
-
return [3 /*break*/, 1];
|
|
263
|
-
case 9: return [2 /*return*/];
|
|
218
|
+
response = _a.sent();
|
|
219
|
+
data = this.extract(response, resource);
|
|
220
|
+
return [2 /*return*/, data];
|
|
264
221
|
}
|
|
265
222
|
});
|
|
266
223
|
});
|
|
267
224
|
};
|
|
268
225
|
/**
|
|
269
|
-
* Get the tweets from
|
|
226
|
+
* Get the list of tweets from a tweet list.
|
|
270
227
|
*
|
|
271
|
-
* @param
|
|
228
|
+
* @param id - The id of target list.
|
|
272
229
|
* @param count - The number of tweets to fetch, must be \<= 100.
|
|
273
230
|
* @param cursor - The cursor to the batch of tweets to fetch.
|
|
274
|
-
*
|
|
231
|
+
*
|
|
232
|
+
* @returns The list tweets in the given list.
|
|
275
233
|
*
|
|
276
234
|
* @example
|
|
277
235
|
* ```
|
|
@@ -280,8 +238,8 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
280
238
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
281
239
|
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
282
240
|
*
|
|
283
|
-
* // Fetching the most recent 100 tweets of the Twitter list with id '
|
|
284
|
-
* rettiwt.tweet.list('
|
|
241
|
+
* // Fetching the most recent 100 tweets of the Twitter list with id '1234567890'
|
|
242
|
+
* rettiwt.tweet.list('1234567890')
|
|
285
243
|
* .then(res => {
|
|
286
244
|
* console.log(res);
|
|
287
245
|
* })
|
|
@@ -292,18 +250,21 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
292
250
|
*
|
|
293
251
|
* @remarks Due a bug in Twitter API, the count is ignored when no cursor is provided and defaults to 100.
|
|
294
252
|
*/
|
|
295
|
-
TweetService.prototype.list = function (
|
|
253
|
+
TweetService.prototype.list = function (id, count, cursor) {
|
|
296
254
|
return __awaiter(this, void 0, void 0, function () {
|
|
297
|
-
var data;
|
|
255
|
+
var resource, response, data;
|
|
298
256
|
return __generator(this, function (_a) {
|
|
299
257
|
switch (_a.label) {
|
|
300
|
-
case 0:
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
258
|
+
case 0:
|
|
259
|
+
resource = Resource_1.EResourceType.LIST_TWEETS;
|
|
260
|
+
return [4 /*yield*/, this.request(resource, {
|
|
261
|
+
id: id,
|
|
262
|
+
count: count,
|
|
263
|
+
cursor: cursor,
|
|
264
|
+
})];
|
|
305
265
|
case 1:
|
|
306
|
-
|
|
266
|
+
response = _a.sent();
|
|
267
|
+
data = this.extract(response, resource);
|
|
307
268
|
// Sorting the tweets by date, from recent to oldest
|
|
308
269
|
data.list.sort(function (a, b) { return new Date(b.createdAt).valueOf() - new Date(a.createdAt).valueOf(); });
|
|
309
270
|
return [2 /*return*/, data];
|
|
@@ -312,22 +273,58 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
312
273
|
});
|
|
313
274
|
};
|
|
314
275
|
/**
|
|
315
|
-
*
|
|
276
|
+
* Post a tweet.
|
|
316
277
|
*
|
|
317
|
-
* @param
|
|
318
|
-
*
|
|
319
|
-
* @
|
|
320
|
-
*
|
|
278
|
+
* @param options - The options describing the tweet to be posted. Check {@link TweetArgs} for available options.
|
|
279
|
+
*
|
|
280
|
+
* @returns Whether posting was successful or not.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* Posting a simple text
|
|
284
|
+
* ```
|
|
285
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
286
|
+
*
|
|
287
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
288
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
289
|
+
*
|
|
290
|
+
* // Posting a tweet to twitter
|
|
291
|
+
* rettiwt.tweet.post({ text: 'Hello World!' })
|
|
292
|
+
* .then(res => {
|
|
293
|
+
* console.log(res);
|
|
294
|
+
* })
|
|
295
|
+
* .catch(err => {
|
|
296
|
+
* console.log(err);
|
|
297
|
+
* });
|
|
298
|
+
* ```
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* Posting a tweet with an image that has been already uploaded
|
|
302
|
+
* ```
|
|
303
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
304
|
+
*
|
|
305
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
306
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
307
|
+
*
|
|
308
|
+
* // Posting a tweet, containing an image called 'mountains.jpg', to twitter
|
|
309
|
+
* rettiwt.tweet.post({ text: 'What a nice view!', media: [{ id: '1234567890' }] })
|
|
310
|
+
* .then(res => {
|
|
311
|
+
* console.log(res);
|
|
312
|
+
* })
|
|
313
|
+
* .catch(err => {
|
|
314
|
+
* console.log(err);
|
|
315
|
+
* });
|
|
316
|
+
* ```
|
|
321
317
|
*
|
|
322
318
|
* @example
|
|
319
|
+
* Posting a reply to a tweet
|
|
323
320
|
* ```
|
|
324
321
|
* import { Rettiwt } from 'rettiwt-api';
|
|
325
322
|
*
|
|
326
323
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
327
324
|
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
328
325
|
*
|
|
329
|
-
* //
|
|
330
|
-
* rettiwt.tweet.
|
|
326
|
+
* // Posting a simple text reply, to a tweet with id "1234567890"
|
|
327
|
+
* rettiwt.tweet.post({ text: 'Hello!', replyTo: "1234567890" })
|
|
331
328
|
* .then(res => {
|
|
332
329
|
* console.log(res);
|
|
333
330
|
* })
|
|
@@ -336,20 +333,76 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
336
333
|
* });
|
|
337
334
|
* ```
|
|
338
335
|
*
|
|
339
|
-
* @
|
|
336
|
+
* * @example
|
|
337
|
+
* Posting a tweet that quotes another tweet
|
|
338
|
+
* ```
|
|
339
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
340
|
+
*
|
|
341
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
342
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
343
|
+
*
|
|
344
|
+
* // Posting a simple text tweet, quoting a tweet with id "1234567890"
|
|
345
|
+
* rettiwt.tweet.post({ text: 'Hello!', quote: "1234567890" })
|
|
346
|
+
* .then(res => {
|
|
347
|
+
* console.log(res);
|
|
348
|
+
* })
|
|
349
|
+
* .catch(err => {
|
|
350
|
+
* console.log(err);
|
|
351
|
+
* });
|
|
352
|
+
* ```
|
|
340
353
|
*/
|
|
341
|
-
TweetService.prototype.
|
|
354
|
+
TweetService.prototype.post = function (options) {
|
|
342
355
|
return __awaiter(this, void 0, void 0, function () {
|
|
343
|
-
var data;
|
|
356
|
+
var resource, response, data;
|
|
344
357
|
return __generator(this, function (_a) {
|
|
345
358
|
switch (_a.label) {
|
|
346
|
-
case 0:
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
cursor: cursor,
|
|
350
|
-
})];
|
|
359
|
+
case 0:
|
|
360
|
+
resource = Resource_1.EResourceType.TWEET_POST;
|
|
361
|
+
return [4 /*yield*/, this.request(resource, { tweet: options })];
|
|
351
362
|
case 1:
|
|
352
|
-
|
|
363
|
+
response = _a.sent();
|
|
364
|
+
data = this.extract(response, resource);
|
|
365
|
+
return [2 /*return*/, data];
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
};
|
|
370
|
+
/**
|
|
371
|
+
* Retweet a tweet.
|
|
372
|
+
*
|
|
373
|
+
* @param id - The id of the target tweet.
|
|
374
|
+
*
|
|
375
|
+
* @returns Whether retweeting was successful or not.
|
|
376
|
+
*
|
|
377
|
+
* @example
|
|
378
|
+
* ```
|
|
379
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
380
|
+
*
|
|
381
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
382
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
383
|
+
*
|
|
384
|
+
* // Retweeting the Tweet with id '1234567890'
|
|
385
|
+
* rettiwt.tweet.retweet('1234567890')
|
|
386
|
+
* .then(res => {
|
|
387
|
+
* console.log(res);
|
|
388
|
+
* })
|
|
389
|
+
* .catch(err => {
|
|
390
|
+
* console.log(err);
|
|
391
|
+
* });
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
TweetService.prototype.retweet = function (id) {
|
|
395
|
+
var _a;
|
|
396
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
397
|
+
var resource, response, data;
|
|
398
|
+
return __generator(this, function (_b) {
|
|
399
|
+
switch (_b.label) {
|
|
400
|
+
case 0:
|
|
401
|
+
resource = Resource_1.EResourceType.TWEET_RETWEET;
|
|
402
|
+
return [4 /*yield*/, this.request(resource, { id: id })];
|
|
403
|
+
case 1:
|
|
404
|
+
response = _b.sent();
|
|
405
|
+
data = (_a = this.extract(response, resource)) !== null && _a !== void 0 ? _a : false;
|
|
353
406
|
return [2 /*return*/, data];
|
|
354
407
|
}
|
|
355
408
|
});
|
|
@@ -358,9 +411,10 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
358
411
|
/**
|
|
359
412
|
* Get the list of users who retweeted a tweet.
|
|
360
413
|
*
|
|
361
|
-
* @param
|
|
414
|
+
* @param id - The id of the target tweet.
|
|
362
415
|
* @param count - The number of retweeters to fetch, must be \<= 100.
|
|
363
416
|
* @param cursor - The cursor to the batch of retweeters to fetch.
|
|
417
|
+
*
|
|
364
418
|
* @returns The list of users who retweeted the given tweet.
|
|
365
419
|
*
|
|
366
420
|
* @example
|
|
@@ -370,8 +424,8 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
370
424
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
371
425
|
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
372
426
|
*
|
|
373
|
-
* // Fetching the most recent 100 retweeters of the Tweet with id '
|
|
374
|
-
* rettiwt.tweet.retweeters('
|
|
427
|
+
* // Fetching the most recent 100 retweeters of the Tweet with id '1234567890'
|
|
428
|
+
* rettiwt.tweet.retweeters('1234567890')
|
|
375
429
|
* .then(res => {
|
|
376
430
|
* console.log(res);
|
|
377
431
|
* })
|
|
@@ -379,43 +433,45 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
379
433
|
* console.log(err);
|
|
380
434
|
* });
|
|
381
435
|
* ```
|
|
382
|
-
*
|
|
383
|
-
* @public
|
|
384
436
|
*/
|
|
385
|
-
TweetService.prototype.retweeters = function (
|
|
437
|
+
TweetService.prototype.retweeters = function (id, count, cursor) {
|
|
386
438
|
return __awaiter(this, void 0, void 0, function () {
|
|
387
|
-
var data;
|
|
439
|
+
var resource, response, data;
|
|
388
440
|
return __generator(this, function (_a) {
|
|
389
441
|
switch (_a.label) {
|
|
390
|
-
case 0:
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
442
|
+
case 0:
|
|
443
|
+
resource = Resource_1.EResourceType.TWEET_RETWEETERS;
|
|
444
|
+
return [4 /*yield*/, this.request(resource, {
|
|
445
|
+
id: id,
|
|
446
|
+
count: count,
|
|
447
|
+
cursor: cursor,
|
|
448
|
+
})];
|
|
395
449
|
case 1:
|
|
396
|
-
|
|
450
|
+
response = _a.sent();
|
|
451
|
+
data = this.extract(response, resource);
|
|
397
452
|
return [2 /*return*/, data];
|
|
398
453
|
}
|
|
399
454
|
});
|
|
400
455
|
});
|
|
401
456
|
};
|
|
402
457
|
/**
|
|
403
|
-
*
|
|
458
|
+
* Search for tweets using a filter.
|
|
404
459
|
*
|
|
405
|
-
* @param
|
|
406
|
-
* @param
|
|
407
|
-
* @param
|
|
408
|
-
*
|
|
460
|
+
* @param filter - The filter to be used for searching the tweets.
|
|
461
|
+
* @param count - The number of tweets to fetch, must be \<= 20.
|
|
462
|
+
* @param cursor - The cursor to the batch of tweets to fetch.
|
|
463
|
+
*
|
|
464
|
+
* @returns The list of tweets that match the given filter.
|
|
409
465
|
*
|
|
410
|
-
* @example
|
|
466
|
+
* @example
|
|
411
467
|
* ```
|
|
412
468
|
* import { Rettiwt } from 'rettiwt-api';
|
|
413
469
|
*
|
|
414
470
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
415
471
|
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
416
472
|
*
|
|
417
|
-
* //
|
|
418
|
-
* rettiwt.tweet.
|
|
473
|
+
* // Fetching the most recent 5 tweets from user 'user1'
|
|
474
|
+
* rettiwt.tweet.search({ fromUsers: ['user1'] }, 5)
|
|
419
475
|
* .then(res => {
|
|
420
476
|
* console.log(res);
|
|
421
477
|
* })
|
|
@@ -424,15 +480,129 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
424
480
|
* });
|
|
425
481
|
* ```
|
|
426
482
|
*
|
|
427
|
-
* @
|
|
483
|
+
* @remarks For details about available filters, refer to {@link TweetFilter}
|
|
484
|
+
*/
|
|
485
|
+
TweetService.prototype.search = function (filter, 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.TWEET_SEARCH;
|
|
492
|
+
return [4 /*yield*/, this.request(resource, {
|
|
493
|
+
filter: filter,
|
|
494
|
+
count: count,
|
|
495
|
+
cursor: cursor,
|
|
496
|
+
})];
|
|
497
|
+
case 1:
|
|
498
|
+
response = _a.sent();
|
|
499
|
+
data = this.extract(response, resource);
|
|
500
|
+
// Sorting the tweets by date, from recent to oldest
|
|
501
|
+
data.list.sort(function (a, b) { return new Date(b.createdAt).valueOf() - new Date(a.createdAt).valueOf(); });
|
|
502
|
+
return [2 /*return*/, data];
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
};
|
|
507
|
+
/**
|
|
508
|
+
* Stream tweets in pseudo real-time using a filter.
|
|
509
|
+
*
|
|
510
|
+
* @param filter - The filter to be used for searching the tweets.
|
|
511
|
+
* @param pollingInterval - The interval in milliseconds to poll for new tweets. Default interval is 60000 ms.
|
|
512
|
+
*
|
|
513
|
+
* @returns An async generator that yields matching tweets as they are found.
|
|
514
|
+
*
|
|
515
|
+
* @example
|
|
428
516
|
* ```
|
|
429
517
|
* import { Rettiwt } from 'rettiwt-api';
|
|
430
518
|
*
|
|
431
519
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
432
520
|
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
433
521
|
*
|
|
434
|
-
* //
|
|
435
|
-
*
|
|
522
|
+
* // Streaming all upcoming tweets from user 'user1'
|
|
523
|
+
* (async () => {
|
|
524
|
+
* try {
|
|
525
|
+
* for await (const tweet of rettiwt.tweet.stream({ fromUsers: ['user1'] }, 1000)) {
|
|
526
|
+
* console.log(tweet.fullText);
|
|
527
|
+
* }
|
|
528
|
+
* }
|
|
529
|
+
* catch (err) {
|
|
530
|
+
* console.log(err);
|
|
531
|
+
* }
|
|
532
|
+
* })();
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
TweetService.prototype.stream = function (filter, pollingInterval) {
|
|
536
|
+
if (pollingInterval === void 0) { pollingInterval = 60000; }
|
|
537
|
+
return __asyncGenerator(this, arguments, function stream_1() {
|
|
538
|
+
var startDate, cursor, sinceId, nextSinceId, tweets, _i, _a, tweet;
|
|
539
|
+
return __generator(this, function (_b) {
|
|
540
|
+
switch (_b.label) {
|
|
541
|
+
case 0:
|
|
542
|
+
startDate = new Date();
|
|
543
|
+
cursor = undefined;
|
|
544
|
+
sinceId = undefined;
|
|
545
|
+
nextSinceId = undefined;
|
|
546
|
+
_b.label = 1;
|
|
547
|
+
case 1:
|
|
548
|
+
if (!true) return [3 /*break*/, 9];
|
|
549
|
+
// Pause execution for the specified polling interval before proceeding to the next iteration
|
|
550
|
+
return [4 /*yield*/, __await(new Promise(function (resolve) { return setTimeout(resolve, pollingInterval); }))];
|
|
551
|
+
case 2:
|
|
552
|
+
// Pause execution for the specified polling interval before proceeding to the next iteration
|
|
553
|
+
_b.sent();
|
|
554
|
+
return [4 /*yield*/, __await(this.search(__assign(__assign({}, filter), { startDate: startDate, sinceId: sinceId }), undefined, cursor))];
|
|
555
|
+
case 3:
|
|
556
|
+
tweets = _b.sent();
|
|
557
|
+
_i = 0, _a = tweets.list;
|
|
558
|
+
_b.label = 4;
|
|
559
|
+
case 4:
|
|
560
|
+
if (!(_i < _a.length)) return [3 /*break*/, 8];
|
|
561
|
+
tweet = _a[_i];
|
|
562
|
+
return [4 /*yield*/, __await(tweet)];
|
|
563
|
+
case 5: return [4 /*yield*/, _b.sent()];
|
|
564
|
+
case 6:
|
|
565
|
+
_b.sent();
|
|
566
|
+
_b.label = 7;
|
|
567
|
+
case 7:
|
|
568
|
+
_i++;
|
|
569
|
+
return [3 /*break*/, 4];
|
|
570
|
+
case 8:
|
|
571
|
+
// Store the most recent tweet ID from this batch
|
|
572
|
+
if (tweets.list.length > 0 && cursor === undefined) {
|
|
573
|
+
nextSinceId = tweets.list[0].id;
|
|
574
|
+
}
|
|
575
|
+
// If there are more tweets to fetch, adjust the cursor value
|
|
576
|
+
if (tweets.list.length > 0 && tweets.next) {
|
|
577
|
+
cursor = tweets.next.value;
|
|
578
|
+
}
|
|
579
|
+
// Else, start the next iteration from this batch's most recent tweet
|
|
580
|
+
else {
|
|
581
|
+
sinceId = nextSinceId;
|
|
582
|
+
cursor = undefined;
|
|
583
|
+
}
|
|
584
|
+
return [3 /*break*/, 1];
|
|
585
|
+
case 9: return [2 /*return*/];
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
});
|
|
589
|
+
};
|
|
590
|
+
/**
|
|
591
|
+
* Unlike a tweet.
|
|
592
|
+
*
|
|
593
|
+
* @param id - The id of the target tweet.
|
|
594
|
+
*
|
|
595
|
+
* @returns Whether unliking was successful or not.
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
* ```
|
|
599
|
+
* import { Rettiwt } from 'rettiwt-api';
|
|
600
|
+
*
|
|
601
|
+
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
602
|
+
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
603
|
+
*
|
|
604
|
+
* // Unliking the Tweet with id '1234567890'
|
|
605
|
+
* rettiwt.tweet.unlike('1234567890')
|
|
436
606
|
* .then(res => {
|
|
437
607
|
* console.log(res);
|
|
438
608
|
* })
|
|
@@ -440,16 +610,40 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
440
610
|
* console.log(err);
|
|
441
611
|
* });
|
|
442
612
|
* ```
|
|
613
|
+
*/
|
|
614
|
+
TweetService.prototype.unlike = function (id) {
|
|
615
|
+
var _a;
|
|
616
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
617
|
+
var resource, response, data;
|
|
618
|
+
return __generator(this, function (_b) {
|
|
619
|
+
switch (_b.label) {
|
|
620
|
+
case 0:
|
|
621
|
+
resource = Resource_1.EResourceType.TWEET_UNLIKE;
|
|
622
|
+
return [4 /*yield*/, this.request(resource, { id: id })];
|
|
623
|
+
case 1:
|
|
624
|
+
response = _b.sent();
|
|
625
|
+
data = (_a = this.extract(response, resource)) !== null && _a !== void 0 ? _a : false;
|
|
626
|
+
return [2 /*return*/, data];
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
});
|
|
630
|
+
};
|
|
631
|
+
/**
|
|
632
|
+
* Unpost a tweet.
|
|
443
633
|
*
|
|
444
|
-
* @
|
|
634
|
+
* @param id - The id of the target tweet.
|
|
635
|
+
*
|
|
636
|
+
* @returns Whether unposting was successful or not.
|
|
637
|
+
*
|
|
638
|
+
* @example
|
|
445
639
|
* ```
|
|
446
640
|
* import { Rettiwt } from 'rettiwt-api';
|
|
447
641
|
*
|
|
448
642
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
449
643
|
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
450
644
|
*
|
|
451
|
-
* //
|
|
452
|
-
* rettiwt.tweet.
|
|
645
|
+
* // Unposting the Tweet with id '1234567890'
|
|
646
|
+
* rettiwt.tweet.unpost('1234567890')
|
|
453
647
|
* .then(res => {
|
|
454
648
|
* console.log(res);
|
|
455
649
|
* })
|
|
@@ -457,47 +651,30 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
457
651
|
* console.log(err);
|
|
458
652
|
* });
|
|
459
653
|
* ```
|
|
460
|
-
*
|
|
461
|
-
* @public
|
|
462
654
|
*/
|
|
463
|
-
TweetService.prototype.
|
|
655
|
+
TweetService.prototype.unpost = function (id) {
|
|
656
|
+
var _a;
|
|
464
657
|
return __awaiter(this, void 0, void 0, function () {
|
|
465
|
-
var
|
|
658
|
+
var resource, response, data;
|
|
466
659
|
return __generator(this, function (_b) {
|
|
467
660
|
switch (_b.label) {
|
|
468
661
|
case 0:
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
if (!tweet.media) return [3 /*break*/, 4];
|
|
472
|
-
_i = 0, _a = tweet.media;
|
|
473
|
-
_b.label = 1;
|
|
662
|
+
resource = Resource_1.EResourceType.TWEET_UNPOST;
|
|
663
|
+
return [4 /*yield*/, this.request(resource, { id: id })];
|
|
474
664
|
case 1:
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
return [4 /*yield*/, this.upload(item.path)];
|
|
478
|
-
case 2:
|
|
479
|
-
id = _b.sent();
|
|
480
|
-
// Storing the uploaded media item
|
|
481
|
-
uploadedMedia.push(new rettiwt_core_1.MediaArgs({ id: id, tags: item.tags }));
|
|
482
|
-
_b.label = 3;
|
|
483
|
-
case 3:
|
|
484
|
-
_i++;
|
|
485
|
-
return [3 /*break*/, 1];
|
|
486
|
-
case 4: return [4 /*yield*/, this.post(rettiwt_core_1.EResourceType.CREATE_TWEET, {
|
|
487
|
-
tweet: { text: text, media: uploadedMedia, replyTo: replyTo },
|
|
488
|
-
})];
|
|
489
|
-
case 5:
|
|
490
|
-
data = _b.sent();
|
|
665
|
+
response = _b.sent();
|
|
666
|
+
data = (_a = this.extract(response, resource)) !== null && _a !== void 0 ? _a : false;
|
|
491
667
|
return [2 /*return*/, data];
|
|
492
668
|
}
|
|
493
669
|
});
|
|
494
670
|
});
|
|
495
671
|
};
|
|
496
672
|
/**
|
|
497
|
-
*
|
|
673
|
+
* Unretweet a tweet.
|
|
674
|
+
*
|
|
675
|
+
* @param id - The id of the target tweet.
|
|
498
676
|
*
|
|
499
|
-
* @
|
|
500
|
-
* @returns Whether favoriting was successful or not.
|
|
677
|
+
* @returns Whether unretweeting was successful or not.
|
|
501
678
|
*
|
|
502
679
|
* @example
|
|
503
680
|
* ```
|
|
@@ -506,8 +683,8 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
506
683
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
507
684
|
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
508
685
|
*
|
|
509
|
-
* //
|
|
510
|
-
* rettiwt.tweet.
|
|
686
|
+
* // Unretweeting the Tweet with id '1234567890'
|
|
687
|
+
* rettiwt.tweet.unretweet('1234567890')
|
|
511
688
|
* .then(res => {
|
|
512
689
|
* console.log(res);
|
|
513
690
|
* })
|
|
@@ -515,27 +692,30 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
515
692
|
* console.log(err);
|
|
516
693
|
* });
|
|
517
694
|
* ```
|
|
518
|
-
*
|
|
519
|
-
* @public
|
|
520
695
|
*/
|
|
521
|
-
TweetService.prototype.
|
|
696
|
+
TweetService.prototype.unretweet = function (id) {
|
|
697
|
+
var _a;
|
|
522
698
|
return __awaiter(this, void 0, void 0, function () {
|
|
523
|
-
var data;
|
|
524
|
-
return __generator(this, function (
|
|
525
|
-
switch (
|
|
526
|
-
case 0:
|
|
699
|
+
var resource, response, data;
|
|
700
|
+
return __generator(this, function (_b) {
|
|
701
|
+
switch (_b.label) {
|
|
702
|
+
case 0:
|
|
703
|
+
resource = Resource_1.EResourceType.TWEET_UNRETWEET;
|
|
704
|
+
return [4 /*yield*/, this.request(resource, { id: id })];
|
|
527
705
|
case 1:
|
|
528
|
-
|
|
706
|
+
response = _b.sent();
|
|
707
|
+
data = (_a = this.extract(response, resource)) !== null && _a !== void 0 ? _a : false;
|
|
529
708
|
return [2 /*return*/, data];
|
|
530
709
|
}
|
|
531
710
|
});
|
|
532
711
|
});
|
|
533
712
|
};
|
|
534
713
|
/**
|
|
535
|
-
*
|
|
714
|
+
* Upload a media file to Twitter.
|
|
536
715
|
*
|
|
537
|
-
* @param
|
|
538
|
-
*
|
|
716
|
+
* @param media - The path or ArrayBuffer to the media file to upload.
|
|
717
|
+
*
|
|
718
|
+
* @returns The id of the uploaded media.
|
|
539
719
|
*
|
|
540
720
|
* @example
|
|
541
721
|
* ```
|
|
@@ -544,8 +724,8 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
544
724
|
* // Creating a new Rettiwt instance using the given 'API_KEY'
|
|
545
725
|
* const rettiwt = new Rettiwt({ apiKey: API_KEY });
|
|
546
726
|
*
|
|
547
|
-
* //
|
|
548
|
-
* rettiwt.tweet.
|
|
727
|
+
* // Uploading a file called mountains.jpg
|
|
728
|
+
* rettiwt.tweet.upload('mountains.jpg')
|
|
549
729
|
* .then(res => {
|
|
550
730
|
* console.log(res);
|
|
551
731
|
* })
|
|
@@ -554,17 +734,34 @@ var TweetService = /** @class */ (function (_super) {
|
|
|
554
734
|
* });
|
|
555
735
|
* ```
|
|
556
736
|
*
|
|
557
|
-
* @
|
|
737
|
+
* @remarks
|
|
738
|
+
* - The uploaded media exists for 24 hrs within which it can be included in a tweet to be posted.
|
|
739
|
+
* If not posted in a tweet within this period, the uploaded media is removed.
|
|
740
|
+
* - Instead of a path to the media, an ArrayBuffer containing the media can also be uploaded.
|
|
558
741
|
*/
|
|
559
|
-
TweetService.prototype.
|
|
742
|
+
TweetService.prototype.upload = function (media) {
|
|
560
743
|
return __awaiter(this, void 0, void 0, function () {
|
|
561
|
-
var
|
|
744
|
+
var size, id;
|
|
562
745
|
return __generator(this, function (_a) {
|
|
563
746
|
switch (_a.label) {
|
|
564
|
-
case 0:
|
|
747
|
+
case 0:
|
|
748
|
+
size = typeof media == 'string' ? (0, fs_1.statSync)(media).size : media.byteLength;
|
|
749
|
+
return [4 /*yield*/, this.request(Resource_1.EResourceType.MEDIA_UPLOAD_INITIALIZE, {
|
|
750
|
+
upload: { size: size },
|
|
751
|
+
})];
|
|
565
752
|
case 1:
|
|
566
|
-
|
|
567
|
-
|
|
753
|
+
id = (_a.sent()).media_id_string;
|
|
754
|
+
// APPEND
|
|
755
|
+
return [4 /*yield*/, this.request(Resource_1.EResourceType.MEDIA_UPLOAD_APPEND, { upload: { id: id, media: media } })];
|
|
756
|
+
case 2:
|
|
757
|
+
// APPEND
|
|
758
|
+
_a.sent();
|
|
759
|
+
// FINALIZE
|
|
760
|
+
return [4 /*yield*/, this.request(Resource_1.EResourceType.MEDIA_UPLOAD_FINALIZE, { upload: { id: id } })];
|
|
761
|
+
case 3:
|
|
762
|
+
// FINALIZE
|
|
763
|
+
_a.sent();
|
|
764
|
+
return [2 /*return*/, id];
|
|
568
765
|
}
|
|
569
766
|
});
|
|
570
767
|
});
|