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