rettiwt-api 1.2.0 → 1.3.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/dist/enums/Errors.d.ts +2 -1
- package/dist/enums/Errors.js +1 -0
- package/dist/enums/Errors.js.map +1 -1
- package/dist/graphql/queries/RootQuery.js.map +1 -1
- package/dist/graphql/resolvers/TweetResolver.d.ts +5 -5
- package/dist/graphql/resolvers/TweetResolver.js +4 -4
- package/dist/graphql/resolvers/TweetResolver.js.map +1 -1
- package/dist/graphql/types/UserTypes.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/models/args/TweetListArgs.js +2 -2
- package/dist/models/args/TweetListArgs.js.map +1 -1
- package/dist/models/args/UserListArgs.js +2 -2
- package/dist/models/args/UserListArgs.js.map +1 -1
- package/dist/models/data/Tweet.d.ts +3 -3
- package/dist/models/data/Tweet.js.map +1 -1
- package/dist/models/data/User.d.ts +2 -2
- package/dist/models/data/User.js.map +1 -1
- package/dist/services/data/TweetService.d.ts +2 -2
- package/dist/services/data/TweetService.js +8 -9
- package/dist/services/data/TweetService.js.map +1 -1
- package/dist/services/data/UserService.js +12 -22
- package/dist/services/data/UserService.js.map +1 -1
- package/dist/services/helper/Headers.js +34 -34
- package/dist/services/helper/Headers.js.map +1 -1
- package/dist/services/helper/extractors/Tweets.d.ts +5 -14
- package/dist/services/helper/extractors/Tweets.js +25 -89
- package/dist/services/helper/extractors/Tweets.js.map +1 -1
- package/dist/services/helper/extractors/Users.d.ts +4 -13
- package/dist/services/helper/extractors/Users.js +1 -53
- package/dist/services/helper/extractors/Users.js.map +1 -1
- package/dist/services/util/FetcherService.d.ts +3 -3
- package/dist/services/util/FetcherService.js +10 -22
- package/dist/services/util/FetcherService.js.map +1 -1
- package/dist/types/Args.d.ts +0 -27
- package/dist/types/Args.js +0 -1
- package/dist/types/Args.js.map +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/AccountService.html +17 -17
- package/docs/classes/AuthCookie.html +7 -7
- package/docs/classes/AuthService.html +7 -7
- package/docs/classes/CacheService.html +7 -7
- package/docs/classes/Cursor.html +3 -3
- package/docs/classes/CursoredData.html +4 -4
- package/docs/classes/DataValidationError.html +24 -23
- package/docs/classes/FetcherService.html +15 -15
- package/docs/classes/Tweet.html +16 -16
- package/docs/classes/TweetEntities.html +8 -8
- package/docs/classes/TweetFilter.html +58 -56
- package/docs/classes/TweetListArgs.html +4 -4
- package/docs/classes/TweetService.html +15 -15
- package/docs/classes/User.html +18 -18
- package/docs/classes/UserListArgs.html +4 -4
- package/docs/classes/UserService.html +15 -15
- package/docs/enums/HttpMethods.html +3 -3
- package/docs/functions/Rettiwt.html +5 -4
- package/docs/index.html +4 -3
- package/docs/interfaces/IAuthCookie.html +5 -5
- package/docs/interfaces/ICursor.html +2 -2
- package/docs/interfaces/ICursoredData.html +3 -3
- package/docs/interfaces/IDataContext.html +4 -4
- package/docs/interfaces/IDataValidationError.html +109 -0
- package/docs/interfaces/IListArgs.html +3 -3
- package/docs/interfaces/ITweet.html +13 -13
- package/docs/interfaces/ITweetEntities.html +5 -5
- package/docs/interfaces/ITweetFilter.html +42 -42
- package/docs/interfaces/IUser.html +15 -15
- package/docs/modules.html +8 -6
- package/package.json +3 -2
- package/src/enums/Errors.ts +2 -1
- package/src/graphql/queries/RootQuery.ts +1 -1
- package/src/graphql/resolvers/TweetResolver.ts +12 -59
- package/src/graphql/types/UserTypes.ts +1 -1
- package/src/index.ts +5 -3
- package/src/models/args/TweetListArgs.ts +2 -2
- package/src/models/args/UserListArgs.ts +1 -1
- package/src/models/data/Tweet.ts +3 -3
- package/src/models/data/User.ts +2 -2
- package/src/services/data/TweetService.ts +25 -22
- package/src/services/data/UserService.ts +38 -42
- package/src/services/helper/Headers.ts +34 -34
- package/src/services/helper/Parser.ts +2 -2
- package/src/services/helper/extractors/Tweets.ts +35 -97
- package/src/services/helper/extractors/Users.ts +11 -62
- package/src/services/util/FetcherService.ts +13 -20
- package/src/types/Args.ts +0 -37
- package/Dockerfile +0 -9
- package/dist/models/args/TweetFilter.d.ts +0 -65
- package/dist/models/args/TweetFilter.js +0 -121
- package/dist/models/args/TweetFilter.js.map +0 -1
- package/dist/models/errors/DataValidationError.d.ts +0 -20
- package/dist/models/errors/DataValidationError.js +0 -23
- package/dist/models/errors/DataValidationError.js.map +0 -1
- package/dist/twitter/Url.d.ts +0 -22
- package/dist/twitter/Url.js +0 -32
- package/dist/twitter/Url.js.map +0 -1
- package/dist/twitter/enums/Resources.d.ts +0 -15
- package/dist/twitter/enums/Resources.js +0 -21
- package/dist/twitter/enums/Resources.js.map +0 -1
- package/dist/twitter/params/Query.d.ts +0 -67
- package/dist/twitter/params/Query.js +0 -64
- package/dist/twitter/params/Query.js.map +0 -1
- package/dist/twitter/payloads/Args.d.ts +0 -16
- package/dist/twitter/payloads/Args.js +0 -16
- package/dist/twitter/payloads/Args.js.map +0 -1
- package/dist/twitter/payloads/Features.d.ts +0 -28
- package/dist/twitter/payloads/Features.js +0 -37
- package/dist/twitter/payloads/Features.js.map +0 -1
- package/dist/twitter/payloads/Variables.d.ts +0 -41
- package/dist/twitter/payloads/Variables.js +0 -64
- package/dist/twitter/payloads/Variables.js.map +0 -1
- package/dist/twitter/types/request/Query.d.ts +0 -86
- package/dist/twitter/types/request/Query.js +0 -4
- package/dist/twitter/types/request/Query.js.map +0 -1
- package/dist/twitter/types/tweet/Favouriters.d.ts +0 -164
- package/dist/twitter/types/tweet/Favouriters.js +0 -3
- package/dist/twitter/types/tweet/Favouriters.js.map +0 -1
- package/dist/twitter/types/tweet/Retweeters.d.ts +0 -171
- package/dist/twitter/types/tweet/Retweeters.js +0 -3
- package/dist/twitter/types/tweet/Retweeters.js.map +0 -1
- package/dist/twitter/types/tweet/Tweet.d.ts +0 -746
- package/dist/twitter/types/tweet/Tweet.js +0 -3
- package/dist/twitter/types/tweet/Tweet.js.map +0 -1
- package/dist/twitter/types/tweet/Tweets.d.ts +0 -386
- package/dist/twitter/types/tweet/Tweets.js +0 -3
- package/dist/twitter/types/tweet/Tweets.js.map +0 -1
- package/dist/twitter/types/user/Followers.d.ts +0 -176
- package/dist/twitter/types/user/Followers.js +0 -3
- package/dist/twitter/types/user/Followers.js.map +0 -1
- package/dist/twitter/types/user/Following.d.ts +0 -176
- package/dist/twitter/types/user/Following.js +0 -3
- package/dist/twitter/types/user/Following.js.map +0 -1
- package/dist/twitter/types/user/Likes.d.ts +0 -1059
- package/dist/twitter/types/user/Likes.js +0 -3
- package/dist/twitter/types/user/Likes.js.map +0 -1
- package/dist/twitter/types/user/Tweets.d.ts +0 -1512
- package/dist/twitter/types/user/Tweets.js +0 -3
- package/dist/twitter/types/user/Tweets.js.map +0 -1
- package/dist/twitter/types/user/User.d.ts +0 -117
- package/dist/twitter/types/user/User.js +0 -3
- package/dist/twitter/types/user/User.js.map +0 -1
- package/src/models/args/TweetFilter.ts +0 -140
- package/src/models/errors/DataValidationError.ts +0 -29
- package/src/twitter/Url.ts +0 -37
- package/src/twitter/enums/Resources.ts +0 -15
- package/src/twitter/params/Query.ts +0 -100
- package/src/twitter/payloads/Args.ts +0 -21
- package/src/twitter/payloads/Features.ts +0 -33
- package/src/twitter/payloads/Variables.ts +0 -73
- package/src/twitter/types/request/Query.ts +0 -91
- package/src/twitter/types/tweet/Favouriters.ts +0 -193
- package/src/twitter/types/tweet/Retweeters.ts +0 -201
- package/src/twitter/types/tweet/Tweet.ts +0 -882
- package/src/twitter/types/tweet/Tweets.ts +0 -444
- package/src/twitter/types/user/Followers.ts +0 -208
- package/src/twitter/types/user/Following.ts +0 -208
- package/src/twitter/types/user/Likes.ts +0 -1247
- package/src/twitter/types/user/Tweets.ts +0 -1747
- package/src/twitter/types/user/User.ts +0 -135
|
@@ -1,24 +1,27 @@
|
|
|
1
|
+
// PACKAGES
|
|
2
|
+
import {
|
|
3
|
+
Url,
|
|
4
|
+
EResourceType,
|
|
5
|
+
ITweetSearchResponse,
|
|
6
|
+
ITweetDetailsResponse,
|
|
7
|
+
ITweetFavoritersResponse,
|
|
8
|
+
ITweetRetweetersResponse,
|
|
9
|
+
ITweet as IRawTweet,
|
|
10
|
+
IUser as IRawUser,
|
|
11
|
+
TweetFilter
|
|
12
|
+
} from 'rettiwt-core';
|
|
13
|
+
|
|
1
14
|
// SERVICES
|
|
2
15
|
import { FetcherService } from "../util/FetcherService";
|
|
3
16
|
import { AuthService } from "../auth/AuthService";
|
|
4
17
|
|
|
5
18
|
// MODELS
|
|
6
|
-
import { Url } from '../../twitter/Url';
|
|
7
19
|
import { Tweet } from "../../models/data/Tweet";
|
|
8
20
|
import { User } from "../../models/data/User";
|
|
9
21
|
import { TweetListArgs } from "../../models/args/TweetListArgs";
|
|
10
|
-
import { TweetFilter } from "../../models/args/TweetFilter";
|
|
11
22
|
import { CursoredData } from '../../models/data/CursoredData';
|
|
12
23
|
|
|
13
|
-
// TYPES
|
|
14
|
-
import RawTweet, { Result as TweetData } from '../../twitter/types/tweet/Tweet';
|
|
15
|
-
import { Result as UserData } from "../../twitter/types/user/User";
|
|
16
|
-
import RawTweets from '../../twitter/types/tweet/Tweets';
|
|
17
|
-
import RawLikers from '../../twitter/types/tweet/Favouriters';
|
|
18
|
-
import RawRetweeters from '../../twitter/types/tweet/Retweeters';
|
|
19
|
-
|
|
20
24
|
// ENUMS
|
|
21
|
-
import { ResourceType } from '../../twitter/enums/Resources';
|
|
22
25
|
import { AuthenticationErrors } from '../../enums/Errors';
|
|
23
26
|
|
|
24
27
|
// EXTRACTORS
|
|
@@ -38,7 +41,7 @@ export class TweetService extends FetcherService {
|
|
|
38
41
|
|
|
39
42
|
/**
|
|
40
43
|
* @param filter The filter be used for searching the tweets.
|
|
41
|
-
* @param count The number of tweets to fetch, must be >= 10 and <= 20
|
|
44
|
+
* @param count The number of tweets to fetch, must be >= 10 (when no cursor is provided) and <= 20
|
|
42
45
|
* @param cursor The cursor to the next batch of tweets. If blank, first batch is fetched.
|
|
43
46
|
*
|
|
44
47
|
* @returns The list of tweets that match the given filter.
|
|
@@ -57,10 +60,10 @@ export class TweetService extends FetcherService {
|
|
|
57
60
|
let args: TweetListArgs = new TweetListArgs(count, cursor);
|
|
58
61
|
|
|
59
62
|
// Preparing the URL
|
|
60
|
-
const url: string = new Url(
|
|
63
|
+
const url: string = new Url(EResourceType.TWEET_SEARCH, { filter: filter.toString(), count: args.count, cursor: args.cursor }).toString();
|
|
61
64
|
|
|
62
65
|
// Getting the raw data
|
|
63
|
-
let res = await this.request<
|
|
66
|
+
let res = await this.request<ITweetSearchResponse>(url).then(res => res.data);
|
|
64
67
|
|
|
65
68
|
// Extracting data
|
|
66
69
|
let data = TweetExtractors.extractTweets(res);
|
|
@@ -69,7 +72,7 @@ export class TweetService extends FetcherService {
|
|
|
69
72
|
this.cacheData(data);
|
|
70
73
|
|
|
71
74
|
// Parsing data
|
|
72
|
-
let tweets = data.required.map((item:
|
|
75
|
+
let tweets = data.required.map((item: IRawTweet) => new Tweet(item));
|
|
73
76
|
|
|
74
77
|
// Sorting the tweets by date, from recent to oldest
|
|
75
78
|
tweets.sort((a, b) => new Date(b.createdAt).valueOf() - new Date(a.createdAt).valueOf());
|
|
@@ -100,10 +103,10 @@ export class TweetService extends FetcherService {
|
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
// Preparing the URL
|
|
103
|
-
const url: string = new Url(
|
|
106
|
+
const url: string = new Url(EResourceType.TWEET_DETAILS, { id: id }).toString();
|
|
104
107
|
|
|
105
108
|
// Fetching the raw data
|
|
106
|
-
let res = await this.request<
|
|
109
|
+
let res = await this.request<ITweetDetailsResponse>(url).then(res => res.data);
|
|
107
110
|
|
|
108
111
|
// Extracting data
|
|
109
112
|
let data = TweetExtractors.extractTweet(res, id);
|
|
@@ -138,10 +141,10 @@ export class TweetService extends FetcherService {
|
|
|
138
141
|
let args: TweetListArgs = new TweetListArgs(count, cursor);
|
|
139
142
|
|
|
140
143
|
// Preparing the URL
|
|
141
|
-
const url: string = new Url(
|
|
144
|
+
const url: string = new Url(EResourceType.TWEET_FAVORITERS, { id: tweetId, count: args.count, cursor: args.cursor }).toString();
|
|
142
145
|
|
|
143
146
|
// Fetching the raw data
|
|
144
|
-
let res = await this.request<
|
|
147
|
+
let res = await this.request<ITweetFavoritersResponse>(url).then(res => res.data);
|
|
145
148
|
|
|
146
149
|
// Extracting data
|
|
147
150
|
let data = TweetExtractors.extractTweetLikers(res);
|
|
@@ -150,7 +153,7 @@ export class TweetService extends FetcherService {
|
|
|
150
153
|
this.cacheData(data);
|
|
151
154
|
|
|
152
155
|
// Parsing data
|
|
153
|
-
let users = data.required.map((item:
|
|
156
|
+
let users = data.required.map((item: IRawUser) => new User(item));
|
|
154
157
|
|
|
155
158
|
return new CursoredData<User>(users, data.cursor);
|
|
156
159
|
}
|
|
@@ -176,10 +179,10 @@ export class TweetService extends FetcherService {
|
|
|
176
179
|
let args: TweetListArgs = new TweetListArgs(count, cursor);
|
|
177
180
|
|
|
178
181
|
// Preparing the URL
|
|
179
|
-
const url: string = new Url(
|
|
182
|
+
const url: string = new Url(EResourceType.TWEET_RETWEETERS, { id: tweetId, count: args.count, cursor: args.cursor }).toString();
|
|
180
183
|
|
|
181
184
|
// Fetching the raw data
|
|
182
|
-
let res = await this.request<
|
|
185
|
+
let res = await this.request<ITweetRetweetersResponse>(url).then(res => res.data);
|
|
183
186
|
|
|
184
187
|
// Extracting data
|
|
185
188
|
let data = TweetExtractors.extractTweetRetweeters(res);
|
|
@@ -188,7 +191,7 @@ export class TweetService extends FetcherService {
|
|
|
188
191
|
this.cacheData(data);
|
|
189
192
|
|
|
190
193
|
// Parsing data
|
|
191
|
-
let users = data.required.map((item:
|
|
194
|
+
let users = data.required.map((item: IRawUser) => new User(item));
|
|
192
195
|
|
|
193
196
|
return new CursoredData<User>(users, data.cursor);
|
|
194
197
|
}
|
|
@@ -1,23 +1,28 @@
|
|
|
1
|
+
// PACKAGES
|
|
2
|
+
import {
|
|
3
|
+
Url,
|
|
4
|
+
EResourceType,
|
|
5
|
+
IUserDetailsResponse,
|
|
6
|
+
IUserFollowersResponse,
|
|
7
|
+
IUserFollowingResponse,
|
|
8
|
+
IUserLikesResponse,
|
|
9
|
+
ITweet as IRawTweet,
|
|
10
|
+
IUser as IRawUser
|
|
11
|
+
} from 'rettiwt-core';
|
|
12
|
+
|
|
1
13
|
// SERVICES
|
|
2
14
|
import { FetcherService } from '../util/FetcherService';
|
|
3
15
|
import { AuthService } from '../auth/AuthService';
|
|
4
16
|
|
|
5
17
|
// MODELS
|
|
6
|
-
import { Url } from '../../twitter/Url';
|
|
7
18
|
import { User } from '../../models/data/User';
|
|
8
19
|
import { UserListArgs } from '../../models/args/UserListArgs';
|
|
9
20
|
import { Tweet } from '../../models/data/Tweet';
|
|
10
21
|
|
|
11
22
|
// TYPES
|
|
12
23
|
import { CursoredData } from '../../models/data/CursoredData';
|
|
13
|
-
import { Result as TweetData } from '../../twitter/types/tweet/Tweet';
|
|
14
|
-
import RawUser, { Result as UserData } from '../../twitter/types/user/User';
|
|
15
|
-
import RawUserFollowers from '../../twitter/types/user/Followers';
|
|
16
|
-
import RawUserFollowing from '../../twitter/types/user/Following';
|
|
17
|
-
import RawUserLikes from '../../twitter/types/user/Likes';
|
|
18
24
|
|
|
19
25
|
// ENUMS
|
|
20
|
-
import { ResourceType } from '../../twitter/enums/Resources';
|
|
21
26
|
import { AuthenticationErrors } from '../../enums/Errors';
|
|
22
27
|
|
|
23
28
|
// EXTRACTORS
|
|
@@ -49,43 +54,34 @@ export class UserService extends FetcherService {
|
|
|
49
54
|
throw new Error(AuthenticationErrors.NotAuthenticated);
|
|
50
55
|
}
|
|
51
56
|
|
|
52
|
-
let res:
|
|
57
|
+
let res: IUserDetailsResponse;
|
|
53
58
|
|
|
54
|
-
//
|
|
55
|
-
|
|
56
|
-
// Preparing the URL
|
|
57
|
-
const url: string = new Url(ResourceType.USER_DETAILS, { id: id }).toString();
|
|
59
|
+
// Getting data from cache
|
|
60
|
+
let cachedData = await this.readData(id);
|
|
58
61
|
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
// If data exists in cache
|
|
63
|
+
if (cachedData) {
|
|
64
|
+
return cachedData;
|
|
61
65
|
}
|
|
62
|
-
//
|
|
66
|
+
// Else, fetch the data from Twitter instead
|
|
63
67
|
else {
|
|
64
|
-
// Getting data from cache
|
|
65
|
-
let cachedData = await this.readData(id);
|
|
66
|
-
|
|
67
|
-
// If data exists in cache
|
|
68
|
-
if (cachedData) {
|
|
69
|
-
return cachedData;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
68
|
// Preparing the URL
|
|
73
|
-
const url: string = new Url(
|
|
69
|
+
const url: string = new Url(EResourceType.USER_DETAILS, { id: id }).toString();
|
|
74
70
|
|
|
75
71
|
// Fetching the raw data
|
|
76
|
-
res = await this.request<
|
|
77
|
-
}
|
|
72
|
+
res = await this.request<IUserDetailsResponse>(url).then(res => res.data);
|
|
78
73
|
|
|
79
|
-
|
|
80
|
-
|
|
74
|
+
// Extracting data
|
|
75
|
+
let data = UserExtractors.extractUserDetails(res);
|
|
81
76
|
|
|
82
|
-
|
|
83
|
-
|
|
77
|
+
// Caching data
|
|
78
|
+
this.cacheData(data);
|
|
84
79
|
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
// Parsing data
|
|
81
|
+
let user = new User(data.required[0]);
|
|
87
82
|
|
|
88
|
-
|
|
83
|
+
return user;
|
|
84
|
+
}
|
|
89
85
|
}
|
|
90
86
|
|
|
91
87
|
/**
|
|
@@ -132,10 +128,10 @@ export class UserService extends FetcherService {
|
|
|
132
128
|
let args: UserListArgs = new UserListArgs(count, cursor);
|
|
133
129
|
|
|
134
130
|
// Preparing the URL
|
|
135
|
-
const url: string = new Url(
|
|
131
|
+
const url: string = new Url(EResourceType.USER_FOLLOWING, { id: userId, count: args.count, cursor: args.cursor }).toString();
|
|
136
132
|
|
|
137
133
|
// Fetchin the raw data
|
|
138
|
-
let res = await this.request<
|
|
134
|
+
let res = await this.request<IUserFollowingResponse>(url).then(res => res.data);
|
|
139
135
|
|
|
140
136
|
// Extracting data
|
|
141
137
|
let data = UserExtractors.extractUserFollow(res);
|
|
@@ -144,7 +140,7 @@ export class UserService extends FetcherService {
|
|
|
144
140
|
this.cacheData(data);
|
|
145
141
|
|
|
146
142
|
// Parsing data
|
|
147
|
-
let users = data.required.map((item:
|
|
143
|
+
let users = data.required.map((item: IRawUser) => new User(item));
|
|
148
144
|
|
|
149
145
|
return new CursoredData<User>(users, data.cursor);
|
|
150
146
|
}
|
|
@@ -170,10 +166,10 @@ export class UserService extends FetcherService {
|
|
|
170
166
|
let args: UserListArgs = new UserListArgs(count, cursor);
|
|
171
167
|
|
|
172
168
|
// Preparing the URL
|
|
173
|
-
const url: string = new Url(
|
|
169
|
+
const url: string = new Url(EResourceType.USER_FOLLOWERS, { id: userId, count: args.count, cursor: args.cursor }).toString();
|
|
174
170
|
|
|
175
171
|
// Fetching the raw data
|
|
176
|
-
let res = await this.request<
|
|
172
|
+
let res = await this.request<IUserFollowersResponse>(url).then(res => res.data);
|
|
177
173
|
|
|
178
174
|
// Extracting data
|
|
179
175
|
let data = UserExtractors.extractUserFollow(res);
|
|
@@ -182,7 +178,7 @@ export class UserService extends FetcherService {
|
|
|
182
178
|
this.cacheData(data);
|
|
183
179
|
|
|
184
180
|
// Parsing data
|
|
185
|
-
let users = data.required.map((item:
|
|
181
|
+
let users = data.required.map((item: IRawUser) => new User(item));
|
|
186
182
|
|
|
187
183
|
return new CursoredData<User>(users, data.cursor);
|
|
188
184
|
}
|
|
@@ -206,10 +202,10 @@ export class UserService extends FetcherService {
|
|
|
206
202
|
let args: UserListArgs = new UserListArgs(count, cursor);
|
|
207
203
|
|
|
208
204
|
// Preparing the URL
|
|
209
|
-
const url: string = new Url(
|
|
205
|
+
const url: string = new Url(EResourceType.USER_LIKES, { id: userId, count: args.count, cursor: args.cursor }).toString();
|
|
210
206
|
|
|
211
207
|
// Fetching the raw data
|
|
212
|
-
let res = await this.request<
|
|
208
|
+
let res = await this.request<IUserLikesResponse>(url).then(res => res.data);
|
|
213
209
|
|
|
214
210
|
// Extracting data
|
|
215
211
|
let data = UserExtractors.extractUserLikes(res);
|
|
@@ -218,7 +214,7 @@ export class UserService extends FetcherService {
|
|
|
218
214
|
this.cacheData(data);
|
|
219
215
|
|
|
220
216
|
// Parsing data
|
|
221
|
-
let tweets = data.required.map((item:
|
|
217
|
+
let tweets = data.required.map((item: IRawTweet) => new Tweet(item));
|
|
222
218
|
|
|
223
219
|
return new CursoredData<Tweet>(tweets, data.cursor);
|
|
224
220
|
}
|
|
@@ -8,20 +8,20 @@ import { IGuestCredentials, IAuthCredentials } from '../../types/Authentication'
|
|
|
8
8
|
* @returns The header required for making authorized HTTP requests
|
|
9
9
|
*/
|
|
10
10
|
export function authorizedHeader(authCred: IAuthCredentials): any {
|
|
11
|
-
return
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
return {
|
|
12
|
+
'sec-ch-ua': '"Not_A Brand";v="99", "Microsoft Edge";v="109", "Chromium";v="109"',
|
|
13
|
+
'x-twitter-client-language': 'en',
|
|
14
|
+
'x-csrf-token': authCred.csrfToken,
|
|
15
|
+
'sec-ch-ua-mobile': '?0',
|
|
16
|
+
'authorization': authCred.authToken,
|
|
17
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.61',
|
|
18
|
+
'x-twitter-auth-type': 'OAuth2Session',
|
|
19
|
+
'x-twitter-active-user': 'yes',
|
|
20
|
+
'sec-ch-ua-platform': '"Windows"',
|
|
21
|
+
'Accept': '*/*',
|
|
22
|
+
'host': 'twitter.com',
|
|
23
|
+
'Cookie': authCred.cookie
|
|
24
|
+
};
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -29,12 +29,12 @@ export function authorizedHeader(authCred: IAuthCredentials): any {
|
|
|
29
29
|
* @returns The header requred for making guest HTTP requests
|
|
30
30
|
*/
|
|
31
31
|
export function guestHeader(guestCred: IGuestCredentials): any {
|
|
32
|
-
return
|
|
33
|
-
'Accept: */*',
|
|
34
|
-
|
|
35
|
-
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.70',
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
return {
|
|
33
|
+
'Accept': '*/*',
|
|
34
|
+
'authorization': guestCred.authToken,
|
|
35
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.70',
|
|
36
|
+
'x-guest-token': guestCred.guestToken
|
|
37
|
+
};
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
@@ -43,18 +43,18 @@ export function guestHeader(guestCred: IGuestCredentials): any {
|
|
|
43
43
|
* @returns The header for making HTTP request for logging in
|
|
44
44
|
*/
|
|
45
45
|
export function loginHeader(guestCred: IGuestCredentials, cookie: string): any {
|
|
46
|
-
return
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
46
|
+
return {
|
|
47
|
+
'sec-ch-ua': '"Not_A Brand";v="99", "Microsoft Edge";v="109", "Chromium";v="109"',
|
|
48
|
+
'x-twitter-client-language': 'en',
|
|
49
|
+
'sec-ch-ua-mobile': '?0',
|
|
50
|
+
'authorization': guestCred.authToken,
|
|
51
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.78',
|
|
52
|
+
'content-type': 'application/json',
|
|
53
|
+
'x-guest-token': guestCred.guestToken,
|
|
54
|
+
'x-twitter-active-user': 'yes',
|
|
55
|
+
'sec-ch-ua-platform': '"Windows"',
|
|
56
|
+
'Accept': '*/*',
|
|
57
|
+
'host': 'twitter.com',
|
|
58
|
+
'Cookie': cookie
|
|
59
|
+
};
|
|
60
60
|
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
// PACKAGE
|
|
2
|
+
import {
|
|
3
|
+
ITweetSearchResponse,
|
|
4
|
+
ITweetDetailsResponse,
|
|
5
|
+
ITweetFavoritersResponse,
|
|
6
|
+
ITweetRetweetersResponse,
|
|
7
|
+
} from 'rettiwt-core';
|
|
8
|
+
|
|
9
|
+
|
|
1
10
|
// TYPES
|
|
2
11
|
import { IDataExtract } from '../../../types/Resolvers';
|
|
3
12
|
import { DataErrors } from '../../../enums/Errors';
|
|
4
|
-
import RawTweet from '../../../twitter/types/tweet/Tweet';
|
|
5
|
-
import RawTweets from '../../../twitter/types/tweet/Tweets';
|
|
6
|
-
import RawRetweeters from '../../../twitter/types/tweet/Retweeters';
|
|
7
|
-
import RawLikers from '../../../twitter/types/tweet/Favouriters';
|
|
8
13
|
|
|
9
14
|
// PARSERS
|
|
10
15
|
import * as Parsers from '../Parser';
|
|
@@ -13,39 +18,35 @@ import * as Parsers from '../Parser';
|
|
|
13
18
|
* @returns The raw tweets data formatted and sorted into required and additional data
|
|
14
19
|
* @param res The raw response received from TwitterAPI
|
|
15
20
|
*/
|
|
16
|
-
export function extractTweets(res:
|
|
21
|
+
export function extractTweets(res: ITweetSearchResponse): IDataExtract {
|
|
17
22
|
let required: any[] = []; // To store the reqruied raw data
|
|
18
23
|
let cursor: string = ''; // To store the cursor to next batch
|
|
19
24
|
let users: any[] = []; // To store additional user data
|
|
20
25
|
let tweets: any[] = []; // To store additional tweet data
|
|
21
26
|
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
let dataUsers = res.globalObjects.users;
|
|
27
|
-
|
|
28
|
-
// If tweets found
|
|
29
|
-
if (!Parsers.isJSONEmpty(dataTweets)) {
|
|
30
|
-
// Destructuring the list of tweets
|
|
31
|
-
for (let key of Object.keys(dataTweets)) {
|
|
32
|
-
required.push({ rest_id: dataTweets[key].id_str, legacy: dataTweets[key] });
|
|
33
|
-
tweets.push({ rest_id: dataTweets[key].id_str, legacy: dataTweets[key] });
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Destructuring the list of users
|
|
37
|
-
for (let key of Object.keys(dataUsers)) {
|
|
38
|
-
users.push({ rest_id: dataUsers[key].id_str, legacy: dataUsers[key] });
|
|
39
|
-
}
|
|
27
|
+
// If tweet does not exist
|
|
28
|
+
if (Parsers.isJSONEmpty(res.data.search_by_raw_query)) {
|
|
29
|
+
throw new Error(DataErrors.NoMatchingTweetsFound);
|
|
30
|
+
}
|
|
40
31
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
32
|
+
// If tweets
|
|
33
|
+
if (res.data.search_by_raw_query.search_timeline.timeline.instructions.length) {
|
|
34
|
+
// Destructuring raw list of tweets
|
|
35
|
+
res.data.search_by_raw_query.search_timeline.timeline.instructions.filter(item => item.type === 'TimelineAddEntries')[0].entries?.forEach(entry => {
|
|
36
|
+
// If entry is of type tweet and tweet exists
|
|
37
|
+
if (entry.entryId.includes('tweet') && entry.content.itemContent?.tweet_results.result.__typename === 'Tweet') {
|
|
38
|
+
required.push(entry.content.itemContent.tweet_results.result);
|
|
39
|
+
users.push(entry.content.itemContent.tweet_results.result.core?.user_results.result);
|
|
40
|
+
tweets.push(entry.content.itemContent.tweet_results.result);
|
|
41
|
+
}
|
|
42
|
+
// If entry is of type cursor and cursor exists
|
|
43
|
+
else if (entry.entryId.includes('cursor-bottom')) {
|
|
44
|
+
cursor = entry.content.value ?? '';
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
// If cursor not found in 'TimelineAddEntries', getting cursor from 'TimlineReplaceEntry'
|
|
48
|
+
if (!cursor) {
|
|
49
|
+
cursor = res.data.search_by_raw_query.search_timeline.timeline.instructions.filter(item => item.entry_id_to_replace?.includes('cursor-bottom'))[0].entry?.content.value ?? '';
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
|
|
@@ -63,7 +64,7 @@ export function extractTweets(res: RawTweets): IDataExtract {
|
|
|
63
64
|
* @param res The raw response received from TwitterAPI
|
|
64
65
|
* @param tweetId The rest id of the tweet to fetch
|
|
65
66
|
*/
|
|
66
|
-
export function extractTweet(res:
|
|
67
|
+
export function extractTweet(res: ITweetDetailsResponse, tweetId: string): IDataExtract {
|
|
67
68
|
let required: any[] = []; // To store the reqruied raw data
|
|
68
69
|
let cursor: string = ''; // To store the cursor to next batch
|
|
69
70
|
let users: any[] = []; // To store additional user data
|
|
@@ -112,7 +113,7 @@ export function extractTweet(res: RawTweet, tweetId: string): IDataExtract {
|
|
|
112
113
|
* @returns The raw tweet likers data formatted and sorted into required and additional data
|
|
113
114
|
* @param res The raw response received from TwitterAPI
|
|
114
115
|
*/
|
|
115
|
-
export function extractTweetLikers(res:
|
|
116
|
+
export function extractTweetLikers(res: ITweetFavoritersResponse): IDataExtract {
|
|
116
117
|
let required: any[] = []; // To store the reqruied raw data
|
|
117
118
|
let cursor: string = ''; // To store the cursor to next batch
|
|
118
119
|
let users: any[] = []; // To store additional user data
|
|
@@ -152,7 +153,7 @@ export function extractTweetLikers(res: RawLikers): IDataExtract {
|
|
|
152
153
|
* @returns The raw tweet retweeters data formatted and sorted into required and additional data
|
|
153
154
|
* @param res The raw response received from TwitterAPI
|
|
154
155
|
*/
|
|
155
|
-
export function extractTweetRetweeters(res:
|
|
156
|
+
export function extractTweetRetweeters(res: ITweetRetweetersResponse): IDataExtract {
|
|
156
157
|
let required: any[] = []; // To store the reqruied raw data
|
|
157
158
|
let cursor: string = ''; // To store the cursor to next batch
|
|
158
159
|
let users: any[] = []; // To store additional user data
|
|
@@ -179,69 +180,6 @@ export function extractTweetRetweeters(res: RawRetweeters): IDataExtract {
|
|
|
179
180
|
});
|
|
180
181
|
}
|
|
181
182
|
|
|
182
|
-
// Returning the data
|
|
183
|
-
return {
|
|
184
|
-
required: required,
|
|
185
|
-
cursor: cursor,
|
|
186
|
-
users: users,
|
|
187
|
-
tweets: tweets
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* @returns The raw tweet replies data formatted and sorted into required and additional data
|
|
193
|
-
* @param res The raw response received from TwitterAPI
|
|
194
|
-
* @param tweetId The id of the tweet whose replies must be extracted
|
|
195
|
-
*/
|
|
196
|
-
export function extractTweetReplies(res: RawTweet, tweetId: string): IDataExtract {
|
|
197
|
-
let required: any[] = []; // To store the reqruied raw data
|
|
198
|
-
let cursor: string = ''; // To store the cursor to next batch
|
|
199
|
-
let users: any[] = []; // To store additional user data
|
|
200
|
-
let tweets: any[] = []; // To store additional tweet data
|
|
201
|
-
|
|
202
|
-
// If tweet does not exist
|
|
203
|
-
if (Parsers.isJSONEmpty(res.data)) {
|
|
204
|
-
throw new Error(DataErrors.TweetNotFound);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Destructuring the received raw data
|
|
208
|
-
res.data.threaded_conversation_with_injections_v2.instructions.filter(item => item.type === 'TimelineAddEntries')[0].entries?.map(entry => {
|
|
209
|
-
// If entry is of type tweet
|
|
210
|
-
if (entry.entryId.indexOf('tweet') != -1) {
|
|
211
|
-
// If tweet exists
|
|
212
|
-
if (entry.content.itemContent?.tweet_results?.result.__typename === 'Tweet') {
|
|
213
|
-
tweets.push(entry.content.itemContent.tweet_results.result);
|
|
214
|
-
users.push(entry.content.itemContent.tweet_results.result.core.user_results.result);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
// If entry if of type conversation/reply
|
|
218
|
-
else if (entry.entryId.indexOf('conversationthread') != -1) {
|
|
219
|
-
// If tweet exists
|
|
220
|
-
if (entry.content.items?.at(0)?.item.itemContent.tweet_results?.result.__typename === 'Tweet') {
|
|
221
|
-
// Adding the 1st entry, which is a reply, to required list
|
|
222
|
-
required.push(entry.content.items[0].item.itemContent.tweet_results?.result);
|
|
223
|
-
tweets.push(entry.content.items[0].item.itemContent.tweet_results?.result);
|
|
224
|
-
users.push(entry.content.items[0].item.itemContent.tweet_results?.result.core.user_results.result);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// Iterating over the rest of the conversation
|
|
228
|
-
entry.content.items?.forEach(item => {
|
|
229
|
-
// If item is of type tweet
|
|
230
|
-
if (item.entryId.indexOf('tweet') != -1) {
|
|
231
|
-
// If tweet exists
|
|
232
|
-
if (item.item.itemContent.tweet_results?.result.__typename === 'Tweet') {
|
|
233
|
-
tweets.push(item.item.itemContent.tweet_results.result);
|
|
234
|
-
users.push(item.item.itemContent.tweet_results.result.core.user_results.result);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
// If entry is of type bottom cursor
|
|
240
|
-
else if (entry.entryId.indexOf('cursor-bottom') != -1) {
|
|
241
|
-
cursor = entry.content.itemContent?.value ?? '';
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
|
|
245
183
|
// Returning the data
|
|
246
184
|
return {
|
|
247
185
|
required: required,
|