rettiwt-api 1.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/.dockerignore +2 -0
- package/.gitattributes +3 -0
- package/Dockerfile +9 -0
- package/README.md +38 -0
- package/dist/config/env.d.ts +5 -0
- package/dist/config/env.js +9 -0
- package/dist/config/env.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/models/graphql/Global.d.ts +4 -0
- package/dist/models/graphql/Global.js +13 -0
- package/dist/models/graphql/Global.js.map +1 -0
- package/dist/models/graphql/TweetTypes.d.ts +6 -0
- package/dist/models/graphql/TweetTypes.js +156 -0
- package/dist/models/graphql/TweetTypes.js.map +1 -0
- package/dist/models/graphql/UserTypes.d.ts +3 -0
- package/dist/models/graphql/UserTypes.js +139 -0
- package/dist/models/graphql/UserTypes.js.map +1 -0
- package/dist/queries/RootQuery.d.ts +4 -0
- package/dist/queries/RootQuery.js +59 -0
- package/dist/queries/RootQuery.js.map +1 -0
- package/dist/resolvers/ResolverBase.d.ts +5 -0
- package/dist/resolvers/ResolverBase.js +11 -0
- package/dist/resolvers/ResolverBase.js.map +1 -0
- package/dist/resolvers/TweetResolver.d.ts +54 -0
- package/dist/resolvers/TweetResolver.js +328 -0
- package/dist/resolvers/TweetResolver.js.map +1 -0
- package/dist/resolvers/UserResolver.d.ts +47 -0
- package/dist/resolvers/UserResolver.js +302 -0
- package/dist/resolvers/UserResolver.js.map +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +75 -0
- package/dist/server.js.map +1 -0
- package/dist/services/AuthService.d.ts +17 -0
- package/dist/services/AuthService.js +103 -0
- package/dist/services/AuthService.js.map +1 -0
- package/dist/services/CacheService.d.ts +25 -0
- package/dist/services/CacheService.js +141 -0
- package/dist/services/CacheService.js.map +1 -0
- package/dist/services/FetcherService.d.ts +30 -0
- package/dist/services/FetcherService.js +171 -0
- package/dist/services/FetcherService.js.map +1 -0
- package/dist/services/data/TweetService.d.ts +43 -0
- package/dist/services/data/TweetService.js +229 -0
- package/dist/services/data/TweetService.js.map +1 -0
- package/dist/services/data/UserAccountService.d.ts +49 -0
- package/dist/services/data/UserAccountService.js +250 -0
- package/dist/services/data/UserAccountService.js.map +1 -0
- package/dist/services/helper/Deserializers.d.ts +19 -0
- package/dist/services/helper/Deserializers.js +115 -0
- package/dist/services/helper/Deserializers.js.map +1 -0
- package/dist/services/helper/Extractors.d.ts +101 -0
- package/dist/services/helper/Extractors.js +409 -0
- package/dist/services/helper/Extractors.js.map +1 -0
- package/dist/services/helper/Headers.d.ts +9 -0
- package/dist/services/helper/Headers.js +47 -0
- package/dist/services/helper/Headers.js.map +1 -0
- package/dist/services/helper/Parser.d.ts +28 -0
- package/dist/services/helper/Parser.js +104 -0
- package/dist/services/helper/Parser.js.map +1 -0
- package/dist/services/helper/Urls.d.ts +74 -0
- package/dist/services/helper/Urls.js +114 -0
- package/dist/services/helper/Urls.js.map +1 -0
- package/dist/test/Test.js +2 -0
- package/dist/test/Test.js.map +1 -0
- package/dist/types/Authentication.d.ts +15 -0
- package/dist/types/Authentication.js +5 -0
- package/dist/types/Authentication.js.map +1 -0
- package/dist/types/HTTP.d.ts +22 -0
- package/dist/types/HTTP.js +30 -0
- package/dist/types/HTTP.js.map +1 -0
- package/dist/types/Service.d.ts +27 -0
- package/dist/types/Service.js +19 -0
- package/dist/types/Service.js.map +1 -0
- package/dist/types/Tweet.d.ts +40 -0
- package/dist/types/Tweet.js +5 -0
- package/dist/types/Tweet.js.map +1 -0
- package/dist/types/UserAccount.d.ts +19 -0
- package/dist/types/UserAccount.js +4 -0
- package/dist/types/UserAccount.js.map +1 -0
- package/dist/types/graphql/Errors.d.ts +15 -0
- package/dist/types/graphql/Errors.js +23 -0
- package/dist/types/graphql/Errors.js.map +1 -0
- package/dist/types/raw/auth/Cookie.d.ts +16 -0
- package/dist/types/raw/auth/Cookie.js +3 -0
- package/dist/types/raw/auth/Cookie.js.map +1 -0
- package/dist/types/raw/tweet/Favouriters.d.ts +164 -0
- package/dist/types/raw/tweet/Favouriters.js +3 -0
- package/dist/types/raw/tweet/Favouriters.js.map +1 -0
- package/dist/types/raw/tweet/Retweeters.d.ts +171 -0
- package/dist/types/raw/tweet/Retweeters.js +3 -0
- package/dist/types/raw/tweet/Retweeters.js.map +1 -0
- package/dist/types/raw/tweet/Tweet.d.ts +746 -0
- package/dist/types/raw/tweet/Tweet.js +3 -0
- package/dist/types/raw/tweet/Tweet.js.map +1 -0
- package/dist/types/raw/tweet/Tweets.d.ts +386 -0
- package/dist/types/raw/tweet/Tweets.js +3 -0
- package/dist/types/raw/tweet/Tweets.js.map +1 -0
- package/dist/types/raw/user/Followers.d.ts +176 -0
- package/dist/types/raw/user/Followers.js +3 -0
- package/dist/types/raw/user/Followers.js.map +1 -0
- package/dist/types/raw/user/Following.d.ts +176 -0
- package/dist/types/raw/user/Following.js +3 -0
- package/dist/types/raw/user/Following.js.map +1 -0
- package/dist/types/raw/user/Likes.d.ts +1059 -0
- package/dist/types/raw/user/Likes.js +3 -0
- package/dist/types/raw/user/Likes.js.map +1 -0
- package/dist/types/raw/user/Tweets.d.ts +2428 -0
- package/dist/types/raw/user/Tweets.js +3 -0
- package/dist/types/raw/user/Tweets.js.map +1 -0
- package/dist/types/raw/user/User.d.ts +117 -0
- package/dist/types/raw/user/User.js +3 -0
- package/dist/types/raw/user/User.js.map +1 -0
- package/dist/types/raw/user/Users.d.ts +120 -0
- package/dist/types/raw/user/Users.js +3 -0
- package/dist/types/raw/user/Users.js.map +1 -0
- package/environment.d.ts +11 -0
- package/package.json +40 -0
- package/src/config/env.ts +5 -0
- package/src/index.ts +19 -0
- package/src/models/graphql/Global.ts +10 -0
- package/src/models/graphql/TweetTypes.ts +154 -0
- package/src/models/graphql/UserTypes.ts +137 -0
- package/src/queries/RootQuery.ts +56 -0
- package/src/resolvers/ResolverBase.ts +12 -0
- package/src/resolvers/TweetResolver.ts +257 -0
- package/src/resolvers/UserResolver.ts +239 -0
- package/src/server.ts +36 -0
- package/src/services/AuthService.ts +58 -0
- package/src/services/CacheService.ts +70 -0
- package/src/services/FetcherService.ts +84 -0
- package/src/services/data/TweetService.ts +163 -0
- package/src/services/data/UserAccountService.ts +187 -0
- package/src/services/helper/Deserializers.ts +95 -0
- package/src/services/helper/Extractors.ts +455 -0
- package/src/services/helper/Headers.ts +45 -0
- package/src/services/helper/Parser.ts +108 -0
- package/src/services/helper/Urls.ts +109 -0
- package/src/types/Authentication.ts +16 -0
- package/src/types/HTTP.ts +23 -0
- package/src/types/Service.ts +36 -0
- package/src/types/Tweet.ts +44 -0
- package/src/types/UserAccount.ts +21 -0
- package/src/types/graphql/Errors.ts +16 -0
- package/src/types/raw/auth/Cookie.ts +16 -0
- package/src/types/raw/tweet/Favouriters.ts +193 -0
- package/src/types/raw/tweet/Retweeters.ts +201 -0
- package/src/types/raw/tweet/Tweet.ts +882 -0
- package/src/types/raw/tweet/Tweets.ts +444 -0
- package/src/types/raw/user/Followers.ts +208 -0
- package/src/types/raw/user/Following.ts +208 -0
- package/src/types/raw/user/Likes.ts +1247 -0
- package/src/types/raw/user/Tweets.ts +2847 -0
- package/src/types/raw/user/User.ts +135 -0
- package/tsconfig.json +95 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (_) try {
|
|
41
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
|
+
};
|
|
64
|
+
exports.__esModule = true;
|
|
65
|
+
exports.CacheService = void 0;
|
|
66
|
+
// PACKAGES
|
|
67
|
+
var node_cache_1 = __importDefault(require("node-cache"));
|
|
68
|
+
// PARSERS
|
|
69
|
+
var Parsers = __importStar(require("./helper/Parser"));
|
|
70
|
+
/**
|
|
71
|
+
* @summary Handles reading and writing of data from and to cache.
|
|
72
|
+
*
|
|
73
|
+
* **Note**: To be able to CacheService, the data to be cached must have a unique "id" field.
|
|
74
|
+
*/
|
|
75
|
+
var CacheService = /** @class */ (function () {
|
|
76
|
+
// MEMBER METHODS
|
|
77
|
+
function CacheService() {
|
|
78
|
+
// Initializing new cache
|
|
79
|
+
this.client = new node_cache_1["default"]();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* @returns The current working instance of CacheService
|
|
83
|
+
*/
|
|
84
|
+
CacheService.getInstance = function () {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
+
return __generator(this, function (_a) {
|
|
87
|
+
// If an instance doesnt exists already
|
|
88
|
+
if (!this.instance) {
|
|
89
|
+
this.instance = new CacheService();
|
|
90
|
+
return [2 /*return*/, this.instance];
|
|
91
|
+
}
|
|
92
|
+
// If an instance already exists, returning it
|
|
93
|
+
else {
|
|
94
|
+
return [2 /*return*/, this.instance];
|
|
95
|
+
}
|
|
96
|
+
return [2 /*return*/];
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* @summary Stores the input data into the cache.
|
|
102
|
+
* @returns Whether writing to cache was successful or not
|
|
103
|
+
* @param data The input data to store
|
|
104
|
+
*/
|
|
105
|
+
CacheService.prototype.write = function (data) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
107
|
+
var _i, data_1, item, cached;
|
|
108
|
+
return __generator(this, function (_a) {
|
|
109
|
+
// Converting the data to a list of data
|
|
110
|
+
data = Parsers.dataToList(data);
|
|
111
|
+
// Iterating over the list of data
|
|
112
|
+
for (_i = 0, data_1 = data; _i < data_1.length; _i++) {
|
|
113
|
+
item = data_1[_i];
|
|
114
|
+
cached = this.client.has(Parsers.findJSONKey(item, 'id'));
|
|
115
|
+
// If data does not already exist in cache
|
|
116
|
+
if (!cached) {
|
|
117
|
+
// Adding data to cache
|
|
118
|
+
this.client.set(Parsers.findJSONKey(item, 'id'), item);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return [2 /*return*/];
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* @returns The data with the given id/rest id from cache
|
|
127
|
+
* @param id The id/rest id of the data to be fetched from cache
|
|
128
|
+
*/
|
|
129
|
+
CacheService.prototype.read = function (id) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
+
var res;
|
|
132
|
+
return __generator(this, function (_a) {
|
|
133
|
+
res = this.client.get(id);
|
|
134
|
+
return [2 /*return*/, res];
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
return CacheService;
|
|
139
|
+
}());
|
|
140
|
+
exports.CacheService = CacheService;
|
|
141
|
+
//# sourceMappingURL=CacheService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CacheService.js","sourceRoot":"","sources":["../../src/services/CacheService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,WAAW;AACX,0DAAmC;AAEnC,UAAU;AACV,uDAA2C;AAE3C;;;;GAIG;AACH;IAKI,iBAAiB;IACjB;QACI,yBAAyB;QACzB,IAAI,CAAC,MAAM,GAAG,IAAI,uBAAS,EAAE,CAAC;IAClC,CAAC;IAED;;OAEG;IACU,wBAAW,GAAxB;;;gBACI,uCAAuC;gBACvC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;oBAChB,IAAI,CAAC,QAAQ,GAAG,IAAI,YAAY,EAAE,CAAC;oBACnC,sBAAO,IAAI,CAAC,QAAQ,EAAC;iBACxB;gBACD,8CAA8C;qBACzC;oBACD,sBAAO,IAAI,CAAC,QAAQ,EAAC;iBACxB;;;;KACJ;IAED;;;;OAIG;IACG,4BAAK,GAAX,UAAY,IAAS;;;;gBACjB,wCAAwC;gBACxC,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;gBAEhC,kCAAkC;gBAClC,WAAqB,EAAJ,aAAI,EAAJ,kBAAI,EAAJ,IAAI,EAAE;oBAAd,IAAI;oBAEL,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;oBAE9D,0CAA0C;oBAC1C,IAAG,CAAC,MAAM,EAAE;wBACR,uBAAuB;wBACvB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;qBAC1D;iBACJ;;;;KACJ;IAED;;;OAGG;IACG,2BAAI,GAAV,UAAW,EAAU;;;;gBAEb,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBAE9B,sBAAO,GAAG,EAAC;;;KACd;IACL,mBAAC;AAAD,CAAC,AA1DD,IA0DC;AA1DY,oCAAY"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CurlyResult } from 'node-libcurl';
|
|
2
|
+
import { AuthService } from './AuthService';
|
|
3
|
+
/**
|
|
4
|
+
* @service The base serivice from which all other data services derive their behaviour
|
|
5
|
+
*/
|
|
6
|
+
export declare class FetcherService {
|
|
7
|
+
private auth;
|
|
8
|
+
constructor(auth: AuthService);
|
|
9
|
+
/**
|
|
10
|
+
* @summary Throws the appropriate http error after evaluation of the status code of reponse
|
|
11
|
+
* @param res The response object received from http communication
|
|
12
|
+
*/
|
|
13
|
+
private handleHTTPError;
|
|
14
|
+
/**
|
|
15
|
+
* @returns The absolute raw json data from give url
|
|
16
|
+
* @param url The url to fetch data from
|
|
17
|
+
* @param authenticated Whether to authenticate requests or not
|
|
18
|
+
*/
|
|
19
|
+
protected request<DataType>(url: string, authenticated?: boolean): Promise<CurlyResult<DataType>>;
|
|
20
|
+
/**
|
|
21
|
+
* @summary Caches the extracted data
|
|
22
|
+
* @param data The extracted data to be cached
|
|
23
|
+
*/
|
|
24
|
+
protected cacheData(data: any): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* @returns The data with the given id (if it exists in cache)
|
|
27
|
+
* @param id The id of the data to be read from cache
|
|
28
|
+
*/
|
|
29
|
+
protected readData(id: string): Promise<any>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (_) try {
|
|
41
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
exports.__esModule = true;
|
|
62
|
+
exports.FetcherService = void 0;
|
|
63
|
+
// PACKAGES
|
|
64
|
+
var node_libcurl_1 = require("node-libcurl");
|
|
65
|
+
var CacheService_1 = require("./CacheService");
|
|
66
|
+
// TYPES
|
|
67
|
+
var HTTP_1 = require("../types/HTTP");
|
|
68
|
+
// HELPERS
|
|
69
|
+
var Headers = __importStar(require("./helper/Headers"));
|
|
70
|
+
var Deserializers = __importStar(require("./helper/Deserializers"));
|
|
71
|
+
/**
|
|
72
|
+
* @service The base serivice from which all other data services derive their behaviour
|
|
73
|
+
*/
|
|
74
|
+
var FetcherService = /** @class */ (function () {
|
|
75
|
+
// MEMBER METHODS
|
|
76
|
+
function FetcherService(auth) {
|
|
77
|
+
this.auth = auth;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* @summary Throws the appropriate http error after evaluation of the status code of reponse
|
|
81
|
+
* @param res The response object received from http communication
|
|
82
|
+
*/
|
|
83
|
+
FetcherService.prototype.handleHTTPError = function (res) {
|
|
84
|
+
if (res.statusCode != 200 && res.statusCode in HTTP_1.HttpStatus) {
|
|
85
|
+
throw new Error(HTTP_1.HttpStatus[res.statusCode]);
|
|
86
|
+
}
|
|
87
|
+
return res;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* @returns The absolute raw json data from give url
|
|
91
|
+
* @param url The url to fetch data from
|
|
92
|
+
* @param authenticated Whether to authenticate requests or not
|
|
93
|
+
*/
|
|
94
|
+
FetcherService.prototype.request = function (url, authenticated) {
|
|
95
|
+
if (authenticated === void 0) { authenticated = false; }
|
|
96
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
97
|
+
var res, _a, _b, _c, _d, _e, _f, _g, _h;
|
|
98
|
+
var _j;
|
|
99
|
+
var _this = this;
|
|
100
|
+
return __generator(this, function (_k) {
|
|
101
|
+
switch (_k.label) {
|
|
102
|
+
case 0:
|
|
103
|
+
_b = (_a = node_libcurl_1.curly).get;
|
|
104
|
+
_c = [url];
|
|
105
|
+
_j = {};
|
|
106
|
+
if (!authenticated) return [3 /*break*/, 2];
|
|
107
|
+
_f = (_e = Headers).authorizedHeader;
|
|
108
|
+
return [4 /*yield*/, this.auth.getAuthCredentials()];
|
|
109
|
+
case 1:
|
|
110
|
+
_d = _f.apply(_e, [_k.sent()]);
|
|
111
|
+
return [3 /*break*/, 4];
|
|
112
|
+
case 2:
|
|
113
|
+
_h = (_g = Headers).guestHeader;
|
|
114
|
+
return [4 /*yield*/, this.auth.getGuestCredentials()];
|
|
115
|
+
case 3:
|
|
116
|
+
_d = _h.apply(_g, [_k.sent()]);
|
|
117
|
+
_k.label = 4;
|
|
118
|
+
case 4: return [4 /*yield*/, _b.apply(_a, _c.concat([(_j.httpHeader = _d,
|
|
119
|
+
_j.sslVerifyPeer = false,
|
|
120
|
+
_j)])).then(function (res) { return _this.handleHTTPError(res); })];
|
|
121
|
+
case 5:
|
|
122
|
+
res = _k.sent();
|
|
123
|
+
return [2 /*return*/, res];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* @summary Caches the extracted data
|
|
130
|
+
* @param data The extracted data to be cached
|
|
131
|
+
*/
|
|
132
|
+
FetcherService.prototype.cacheData = function (data) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
134
|
+
var cache, users, tweets;
|
|
135
|
+
return __generator(this, function (_a) {
|
|
136
|
+
switch (_a.label) {
|
|
137
|
+
case 0: return [4 /*yield*/, CacheService_1.CacheService.getInstance()];
|
|
138
|
+
case 1:
|
|
139
|
+
cache = _a.sent();
|
|
140
|
+
users = data.users.map(function (user) { return Deserializers.toUser(user); });
|
|
141
|
+
tweets = data.tweets.map(function (tweet) { return Deserializers.toTweet(tweet); });
|
|
142
|
+
// Caching the data
|
|
143
|
+
cache.write(users);
|
|
144
|
+
cache.write(tweets);
|
|
145
|
+
return [2 /*return*/];
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* @returns The data with the given id (if it exists in cache)
|
|
152
|
+
* @param id The id of the data to be read from cache
|
|
153
|
+
*/
|
|
154
|
+
FetcherService.prototype.readData = function (id) {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
156
|
+
var cache;
|
|
157
|
+
return __generator(this, function (_a) {
|
|
158
|
+
switch (_a.label) {
|
|
159
|
+
case 0: return [4 /*yield*/, CacheService_1.CacheService.getInstance()];
|
|
160
|
+
case 1:
|
|
161
|
+
cache = _a.sent();
|
|
162
|
+
// Reading data from cache
|
|
163
|
+
return [2 /*return*/, cache.read(id)];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
return FetcherService;
|
|
169
|
+
}());
|
|
170
|
+
exports.FetcherService = FetcherService;
|
|
171
|
+
//# sourceMappingURL=FetcherService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FetcherService.js","sourceRoot":"","sources":["../../src/services/FetcherService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,WAAW;AACX,6CAAkD;AAIlD,+CAA8C;AAE9C,QAAQ;AACR,sCAA2C;AAI3C,UAAU;AACV,wDAA2C;AAC3C,oEAAwD;AAExD;;GAEG;AACH;IAII,iBAAiB;IACjB,wBAAY,IAAiB;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IAED;;;MAGE;IACM,wCAAe,GAAvB,UAAwB,GAAgB;QACpC,IAAI,GAAG,CAAC,UAAU,IAAI,GAAG,IAAI,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AAC,UAAC,KAAe,IAAK,OAAA,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,EAA5B,CAA4B,CAAC,CAAC;wBAEhF,mBAAmB;wBACnB,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;wBACnB,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;;;;;KACvB;IAED;;;OAGG;IACa,iCAAQ,GAAxB,UAAyB,EAAU;;;;;4BAEnB,qBAAM,2BAAY,CAAC,WAAW,EAAE,EAAA;;wBAAxC,KAAK,GAAG,SAAgC;wBAE5C,0BAA0B;wBAC1B,sBAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,EAAC;;;;KACzB;IACL,qBAAC;AAAD,CAAC,AAhED,IAgEC;AAhEY,wCAAc"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { FetcherService } from "../FetcherService";
|
|
2
|
+
import { AuthService } from "../AuthService";
|
|
3
|
+
import { TweetFilter, Tweet } from "../../types/Tweet";
|
|
4
|
+
import { User } from "../../types/UserAccount";
|
|
5
|
+
import { CursoredData } from '../../types/Service';
|
|
6
|
+
/**
|
|
7
|
+
* A service that deals with fetching of data related to tweets
|
|
8
|
+
*/
|
|
9
|
+
export declare class TweetService extends FetcherService {
|
|
10
|
+
constructor(auth: AuthService);
|
|
11
|
+
/**
|
|
12
|
+
* @returns The list of tweets that match the given filter
|
|
13
|
+
* @param filter The filter be used for searching the tweets
|
|
14
|
+
* @param count The number of tweets to fetch
|
|
15
|
+
* @param cursor The cursor to the next batch of tweets. If blank, first batch is fetched
|
|
16
|
+
*/
|
|
17
|
+
getTweets(filter: TweetFilter, count: number, cursor: string): Promise<CursoredData<Tweet>>;
|
|
18
|
+
/**
|
|
19
|
+
* @returns The details of a single tweet with the given tweet id
|
|
20
|
+
* @param tweetId The rest id of the target tweet
|
|
21
|
+
*/
|
|
22
|
+
getTweetById(tweetId: string): Promise<Tweet>;
|
|
23
|
+
/**
|
|
24
|
+
* @returns The list of users who liked the given tweet
|
|
25
|
+
* @param tweetId The rest id of the target tweet
|
|
26
|
+
* @param count The batch size of the list
|
|
27
|
+
* @param cursor The cursor to the next batch of users. If blank, first batch is fetched
|
|
28
|
+
*/
|
|
29
|
+
getTweetLikers(tweetId: string, count: number, cursor: string): Promise<CursoredData<User>>;
|
|
30
|
+
/**
|
|
31
|
+
* @returns The list of users who retweeted the given tweet
|
|
32
|
+
* @param tweetId The rest id of the target tweet
|
|
33
|
+
* @param count The batch size of the list
|
|
34
|
+
* @param cursor The cursor to the next batch of users. If blank, first batch is fetched
|
|
35
|
+
*/
|
|
36
|
+
getTweetRetweeters(tweetId: string, count: number, cursor: string): Promise<CursoredData<User>>;
|
|
37
|
+
/**
|
|
38
|
+
* @returns The list of replies to the given tweet
|
|
39
|
+
* @param tweetId The rest id of the target tweet
|
|
40
|
+
* @param cursor The cursor to the next batch of replies. If blank, first batch is fetched
|
|
41
|
+
*/
|
|
42
|
+
getTweetReplies(tweetId: string, cursor: string): Promise<CursoredData<Tweet>>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
41
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
42
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
43
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
44
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
45
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
46
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
50
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
51
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
52
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
53
|
+
function step(op) {
|
|
54
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
55
|
+
while (_) try {
|
|
56
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
57
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
58
|
+
switch (op[0]) {
|
|
59
|
+
case 0: case 1: t = op; break;
|
|
60
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
61
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
62
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
63
|
+
default:
|
|
64
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
65
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
66
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
67
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
68
|
+
if (t[2]) _.ops.pop();
|
|
69
|
+
_.trys.pop(); continue;
|
|
70
|
+
}
|
|
71
|
+
op = body.call(thisArg, _);
|
|
72
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
73
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
exports.__esModule = true;
|
|
77
|
+
exports.TweetService = void 0;
|
|
78
|
+
// SERVICES
|
|
79
|
+
var FetcherService_1 = require("../FetcherService");
|
|
80
|
+
// URLS
|
|
81
|
+
var Urls = __importStar(require("../helper/Urls"));
|
|
82
|
+
// EXTRACTORS
|
|
83
|
+
var Extractors = __importStar(require("../helper/Extractors"));
|
|
84
|
+
// DESERIALIZERS
|
|
85
|
+
var Deserializers = __importStar(require("../helper/Deserializers"));
|
|
86
|
+
// PARSERS
|
|
87
|
+
var Parser_1 = require("../helper/Parser");
|
|
88
|
+
/**
|
|
89
|
+
* A service that deals with fetching of data related to tweets
|
|
90
|
+
*/
|
|
91
|
+
var TweetService = /** @class */ (function (_super) {
|
|
92
|
+
__extends(TweetService, _super);
|
|
93
|
+
// MEMBER METHODS
|
|
94
|
+
function TweetService(auth) {
|
|
95
|
+
return _super.call(this, auth) || this;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* @returns The list of tweets that match the given filter
|
|
99
|
+
* @param filter The filter be used for searching the tweets
|
|
100
|
+
* @param count The number of tweets to fetch
|
|
101
|
+
* @param cursor The cursor to the next batch of tweets. If blank, first batch is fetched
|
|
102
|
+
*/
|
|
103
|
+
TweetService.prototype.getTweets = function (filter, count, cursor) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
105
|
+
var res, data, tweets;
|
|
106
|
+
return __generator(this, function (_a) {
|
|
107
|
+
switch (_a.label) {
|
|
108
|
+
case 0: return [4 /*yield*/, this.request(Urls.tweetsUrl((0, Parser_1.toQueryString)(filter), count, cursor), false).then(function (res) { return res.data; })];
|
|
109
|
+
case 1:
|
|
110
|
+
res = _a.sent();
|
|
111
|
+
data = Extractors.extractTweets(res);
|
|
112
|
+
// Caching data
|
|
113
|
+
this.cacheData(data);
|
|
114
|
+
tweets = data.required.map(function (item) { return Deserializers.toTweet(item); });
|
|
115
|
+
return [2 /*return*/, {
|
|
116
|
+
list: tweets,
|
|
117
|
+
next: { value: data.cursor }
|
|
118
|
+
}];
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* @returns The details of a single tweet with the given tweet id
|
|
125
|
+
* @param tweetId The rest id of the target tweet
|
|
126
|
+
*/
|
|
127
|
+
TweetService.prototype.getTweetById = function (tweetId) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
129
|
+
var cachedData, res, data, tweet;
|
|
130
|
+
return __generator(this, function (_a) {
|
|
131
|
+
switch (_a.label) {
|
|
132
|
+
case 0: return [4 /*yield*/, this.readData(tweetId)];
|
|
133
|
+
case 1:
|
|
134
|
+
cachedData = _a.sent();
|
|
135
|
+
if (!cachedData) return [3 /*break*/, 2];
|
|
136
|
+
return [2 /*return*/, cachedData];
|
|
137
|
+
case 2: return [4 /*yield*/, this.request(Urls.tweetDetailsUrl(tweetId)).then(function (res) { return res.data; })];
|
|
138
|
+
case 3:
|
|
139
|
+
res = _a.sent();
|
|
140
|
+
data = Extractors.extractTweet(res, tweetId);
|
|
141
|
+
// Caching data
|
|
142
|
+
this.cacheData(data);
|
|
143
|
+
tweet = Deserializers.toTweet(data.required[0]);
|
|
144
|
+
return [2 /*return*/, tweet];
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* @returns The list of users who liked the given tweet
|
|
151
|
+
* @param tweetId The rest id of the target tweet
|
|
152
|
+
* @param count The batch size of the list
|
|
153
|
+
* @param cursor The cursor to the next batch of users. If blank, first batch is fetched
|
|
154
|
+
*/
|
|
155
|
+
TweetService.prototype.getTweetLikers = function (tweetId, count, cursor) {
|
|
156
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
157
|
+
var res, data, users;
|
|
158
|
+
return __generator(this, function (_a) {
|
|
159
|
+
switch (_a.label) {
|
|
160
|
+
case 0: return [4 /*yield*/, this.request(Urls.tweetLikesUrl(tweetId, count, cursor)).then(function (res) { return res.data; })];
|
|
161
|
+
case 1:
|
|
162
|
+
res = _a.sent();
|
|
163
|
+
data = Extractors.extractTweetLikers(res);
|
|
164
|
+
// Caching data
|
|
165
|
+
this.cacheData(data);
|
|
166
|
+
users = data.required.map(function (item) { return Deserializers.toUser(item); });
|
|
167
|
+
return [2 /*return*/, {
|
|
168
|
+
list: users,
|
|
169
|
+
next: { value: data.cursor }
|
|
170
|
+
}];
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* @returns The list of users who retweeted the given tweet
|
|
177
|
+
* @param tweetId The rest id of the target tweet
|
|
178
|
+
* @param count The batch size of the list
|
|
179
|
+
* @param cursor The cursor to the next batch of users. If blank, first batch is fetched
|
|
180
|
+
*/
|
|
181
|
+
TweetService.prototype.getTweetRetweeters = function (tweetId, count, cursor) {
|
|
182
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
183
|
+
var res, data, users;
|
|
184
|
+
return __generator(this, function (_a) {
|
|
185
|
+
switch (_a.label) {
|
|
186
|
+
case 0: return [4 /*yield*/, this.request(Urls.tweetRetweetUrl(tweetId, count, cursor)).then(function (res) { return res.data; })];
|
|
187
|
+
case 1:
|
|
188
|
+
res = _a.sent();
|
|
189
|
+
data = Extractors.extractTweetRetweeters(res);
|
|
190
|
+
// Caching data
|
|
191
|
+
this.cacheData(data);
|
|
192
|
+
users = data.required.map(function (item) { return Deserializers.toUser(item); });
|
|
193
|
+
return [2 /*return*/, {
|
|
194
|
+
list: users,
|
|
195
|
+
next: { value: data.cursor }
|
|
196
|
+
}];
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* @returns The list of replies to the given tweet
|
|
203
|
+
* @param tweetId The rest id of the target tweet
|
|
204
|
+
* @param cursor The cursor to the next batch of replies. If blank, first batch is fetched
|
|
205
|
+
*/
|
|
206
|
+
TweetService.prototype.getTweetReplies = function (tweetId, cursor) {
|
|
207
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
208
|
+
var res, data, tweets;
|
|
209
|
+
return __generator(this, function (_a) {
|
|
210
|
+
switch (_a.label) {
|
|
211
|
+
case 0: return [4 /*yield*/, this.request(Urls.tweetRepliesUrl(tweetId, cursor)).then(function (res) { return res.data; })];
|
|
212
|
+
case 1:
|
|
213
|
+
res = _a.sent();
|
|
214
|
+
data = Extractors.extractTweetReplies(res, tweetId);
|
|
215
|
+
// Caching data
|
|
216
|
+
this.cacheData(data);
|
|
217
|
+
tweets = data.required.map(function (item) { return Deserializers.toTweet(item); });
|
|
218
|
+
return [2 /*return*/, {
|
|
219
|
+
list: tweets,
|
|
220
|
+
next: { value: data.cursor }
|
|
221
|
+
}];
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
return TweetService;
|
|
227
|
+
}(FetcherService_1.FetcherService));
|
|
228
|
+
exports.TweetService = TweetService;
|
|
229
|
+
//# sourceMappingURL=TweetService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TweetService.js","sourceRoot":"","sources":["../../../src/services/data/TweetService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,WAAW;AACX,oDAAmD;AAYnD,OAAO;AACP,mDAAuC;AAEvC,aAAa;AACb,+DAAmD;AAEnD,gBAAgB;AAChB,qEAAyD;AAEzD,UAAU;AACV,2CAAiD;AAEjD;;GAEG;AACH;IAAkC,gCAAc;IAC5C,iBAAiB;IACjB,sBAAY,IAAiB;eACzB,kBAAM,IAAI,CAAC;IACf,CAAC;IAED;;;;;OAKG;IACG,gCAAS,GAAf,UAAgB,MAAmB,EAAE,KAAa,EAAE,MAAc;;;;;4BAEpD,qBAAM,IAAI,CAAC,OAAO,CAAY,IAAI,CAAC,SAAS,CAAC,IAAA,sBAAa,EAAC,MAAM,CAAC,E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