rettiwt-api 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/dist/{queries → graphql/queries}/RootQuery.d.ts +0 -0
  2. package/dist/{queries → graphql/queries}/RootQuery.js +4 -3
  3. package/dist/graphql/queries/RootQuery.js.map +1 -0
  4. package/dist/{resolvers → graphql/resolvers}/AccountResolver.d.ts +1 -1
  5. package/dist/{resolvers → graphql/resolvers}/AccountResolver.js +0 -0
  6. package/dist/graphql/resolvers/AccountResolver.js.map +1 -0
  7. package/dist/{resolvers → graphql/resolvers}/ResolverBase.d.ts +1 -1
  8. package/dist/{resolvers → graphql/resolvers}/ResolverBase.js +0 -0
  9. package/dist/graphql/resolvers/ResolverBase.js.map +1 -0
  10. package/dist/{resolvers → graphql/resolvers}/TweetResolver.d.ts +10 -18
  11. package/dist/{resolvers → graphql/resolvers}/TweetResolver.js +51 -83
  12. package/dist/graphql/resolvers/TweetResolver.js.map +1 -0
  13. package/dist/{resolvers → graphql/resolvers}/UserResolver.d.ts +5 -4
  14. package/dist/{resolvers → graphql/resolvers}/UserResolver.js +51 -35
  15. package/dist/graphql/resolvers/UserResolver.js.map +1 -0
  16. package/dist/{models/graphql → graphql/types}/Global.d.ts +0 -0
  17. package/dist/{models/graphql → graphql/types}/Global.js +0 -0
  18. package/dist/graphql/types/Global.js.map +1 -0
  19. package/dist/graphql/types/TweetTypes.d.ts +4 -0
  20. package/dist/{models/graphql → graphql/types}/TweetTypes.js +17 -13
  21. package/dist/graphql/types/TweetTypes.js.map +1 -0
  22. package/dist/graphql/types/UserTypes.d.ts +3 -0
  23. package/dist/{models/graphql → graphql/types}/UserTypes.js +9 -11
  24. package/dist/graphql/types/UserTypes.js.map +1 -0
  25. package/dist/index.d.ts +2 -2
  26. package/dist/index.js +2 -2
  27. package/dist/index.js.map +1 -1
  28. package/dist/server.js +3 -3
  29. package/dist/server.js.map +1 -1
  30. package/dist/services/AuthService.js +2 -2
  31. package/dist/services/AuthService.js.map +1 -1
  32. package/dist/services/CacheService.d.ts +3 -3
  33. package/dist/services/CacheService.js +22 -75
  34. package/dist/services/CacheService.js.map +1 -1
  35. package/dist/services/FetcherService.d.ts +3 -2
  36. package/dist/services/FetcherService.js +11 -29
  37. package/dist/services/FetcherService.js.map +1 -1
  38. package/dist/services/data/TweetService.d.ts +15 -16
  39. package/dist/services/data/TweetService.js +71 -50
  40. package/dist/services/data/TweetService.js.map +1 -1
  41. package/dist/services/data/UserAccountService.d.ts +3 -3
  42. package/dist/services/data/UserAccountService.js +22 -8
  43. package/dist/services/data/UserAccountService.js.map +1 -1
  44. package/dist/services/data/UserService.d.ts +42 -0
  45. package/dist/services/data/UserService.js +255 -0
  46. package/dist/services/data/UserService.js.map +1 -0
  47. package/dist/services/helper/Extractors.js +1 -1
  48. package/dist/services/helper/Extractors.js.map +1 -1
  49. package/dist/services/helper/Parser.d.ts +1 -1
  50. package/dist/services/helper/Parser.js +4 -3
  51. package/dist/services/helper/Parser.js.map +1 -1
  52. package/dist/services/helper/Urls.d.ts +2 -2
  53. package/dist/services/helper/Urls.js +19 -3
  54. package/dist/services/helper/Urls.js.map +1 -1
  55. package/dist/services/helper/deserializers/Tweets.d.ts +12 -0
  56. package/dist/services/helper/deserializers/Tweets.js +92 -0
  57. package/dist/services/helper/deserializers/Tweets.js.map +1 -0
  58. package/dist/services/{accounting/Flows.d.ts → helper/deserializers/User.d.ts} +0 -0
  59. package/dist/services/helper/deserializers/User.js +2 -0
  60. package/dist/services/helper/deserializers/User.js.map +1 -0
  61. package/dist/services/helper/deserializers/Users.d.ts +7 -0
  62. package/dist/services/helper/deserializers/Users.js +27 -0
  63. package/dist/services/helper/deserializers/Users.js.map +1 -0
  64. package/dist/services/helper/extractors/TweetExtractors.d.ts +0 -0
  65. package/dist/services/helper/extractors/TweetExtractors.js +2 -0
  66. package/dist/services/helper/extractors/TweetExtractors.js.map +1 -0
  67. package/dist/services/helper/extractors/Tweets.d.ts +34 -0
  68. package/dist/services/helper/extractors/Tweets.js +266 -0
  69. package/dist/services/helper/extractors/Tweets.js.map +1 -0
  70. package/dist/services/helper/extractors/UserExtractors.d.ts +45 -0
  71. package/dist/services/helper/extractors/UserExtractors.js +176 -0
  72. package/dist/services/helper/extractors/UserExtractors.js.map +1 -0
  73. package/dist/services/helper/extractors/Users.d.ts +23 -0
  74. package/dist/services/helper/extractors/Users.js +154 -0
  75. package/dist/services/helper/extractors/Users.js.map +1 -0
  76. package/dist/services/helper/urls/Authentication.d.ts +4 -0
  77. package/dist/services/helper/urls/Authentication.js +11 -0
  78. package/dist/services/helper/urls/Authentication.js.map +1 -0
  79. package/dist/services/helper/urls/Tweets.d.ts +32 -0
  80. package/dist/services/helper/urls/Tweets.js +51 -0
  81. package/dist/services/helper/urls/Tweets.js.map +1 -0
  82. package/dist/services/helper/urls/Urls.d.ts +4 -0
  83. package/dist/services/helper/urls/Urls.js +11 -0
  84. package/dist/services/helper/urls/Urls.js.map +1 -0
  85. package/dist/services/helper/urls/Users.d.ts +31 -0
  86. package/dist/services/helper/urls/Users.js +66 -0
  87. package/dist/services/helper/urls/Users.js.map +1 -0
  88. package/dist/types/{graphql/Errors.d.ts → Errors.d.ts} +0 -0
  89. package/dist/types/{graphql/Errors.js → Errors.js} +0 -0
  90. package/dist/types/Errors.js.map +1 -0
  91. package/dist/types/Resolvers.d.ts +9 -0
  92. package/dist/types/Resolvers.js +3 -0
  93. package/dist/types/Resolvers.js.map +1 -0
  94. package/dist/types/Tweet.d.ts +1 -0
  95. package/dist/types/Tweet.js.map +1 -1
  96. package/dist/types/User.d.ts +19 -0
  97. package/dist/types/User.js +4 -0
  98. package/dist/types/User.js.map +1 -0
  99. package/dist/types/data/Errors.d.ts +27 -0
  100. package/dist/types/data/Errors.js +35 -0
  101. package/dist/types/data/Errors.js.map +1 -0
  102. package/dist/types/data/Service.d.ts +29 -0
  103. package/dist/types/data/Service.js +19 -0
  104. package/dist/types/data/Service.js.map +1 -0
  105. package/dist/types/data/Tweet.d.ts +41 -0
  106. package/dist/types/data/Tweet.js +5 -0
  107. package/dist/types/data/Tweet.js.map +1 -0
  108. package/dist/types/data/User.d.ts +19 -0
  109. package/dist/types/data/User.js +4 -0
  110. package/dist/types/data/User.js.map +1 -0
  111. package/dist/types/raw/http/Error.d.ts +34 -0
  112. package/dist/types/raw/{user/Users.js → http/Error.js} +1 -1
  113. package/dist/types/raw/http/Error.js.map +1 -0
  114. package/dist/types/raw/http/Response.d.ts +34 -0
  115. package/dist/types/raw/http/Response.js +3 -0
  116. package/dist/types/raw/http/Response.js.map +1 -0
  117. package/package.json +1 -1
  118. package/src/{queries → graphql/queries}/RootQuery.ts +5 -4
  119. package/src/{resolvers → graphql/resolvers}/AccountResolver.ts +21 -21
  120. package/src/{resolvers → graphql/resolvers}/ResolverBase.ts +1 -1
  121. package/src/{resolvers → graphql/resolvers}/TweetResolver.ts +48 -30
  122. package/src/{resolvers → graphql/resolvers}/UserResolver.ts +41 -27
  123. package/src/{models/graphql → graphql/types}/Global.ts +0 -0
  124. package/src/{models/graphql → graphql/types}/TweetTypes.ts +16 -12
  125. package/src/{models/graphql → graphql/types}/UserTypes.ts +13 -15
  126. package/src/index.ts +2 -2
  127. package/src/server.ts +3 -3
  128. package/src/services/AuthService.ts +1 -1
  129. package/src/services/CacheService.ts +6 -8
  130. package/src/services/FetcherService.ts +11 -14
  131. package/src/services/data/TweetService.ts +58 -37
  132. package/src/services/data/UserService.ts +187 -0
  133. package/src/services/helper/Parser.ts +6 -4
  134. package/src/services/helper/{Deserializers.ts → deserializers/Tweets.ts} +3 -28
  135. package/src/services/helper/deserializers/Users.ts +26 -0
  136. package/src/services/helper/extractors/Tweets.ts +252 -0
  137. package/src/services/helper/extractors/Users.ts +137 -0
  138. package/src/services/helper/urls/Authentication.ts +6 -0
  139. package/src/services/helper/urls/Tweets.ts +46 -0
  140. package/src/services/helper/urls/Users.ts +62 -0
  141. package/src/types/Resolvers.ts +9 -0
  142. package/src/types/data/Errors.ts +28 -0
  143. package/src/types/{Service.ts → data/Service.ts} +4 -5
  144. package/src/types/{Tweet.ts → data/Tweet.ts} +1 -0
  145. package/src/types/{UserAccount.ts → data/User.ts} +0 -0
  146. package/tsconfig.json +2 -2
  147. package/dist/models/graphql/Global.js.map +0 -1
  148. package/dist/models/graphql/TweetTypes.d.ts +0 -6
  149. package/dist/models/graphql/TweetTypes.js.map +0 -1
  150. package/dist/models/graphql/UserTypes.d.ts +0 -3
  151. package/dist/models/graphql/UserTypes.js.map +0 -1
  152. package/dist/queries/RootQuery.js.map +0 -1
  153. package/dist/resolvers/AccountResolver.js.map +0 -1
  154. package/dist/resolvers/ResolverBase.js.map +0 -1
  155. package/dist/resolvers/TweetResolver.js.map +0 -1
  156. package/dist/resolvers/UserResolver.js.map +0 -1
  157. package/dist/services/AccountsService.d.ts +0 -17
  158. package/dist/services/AccountsService.js +0 -171
  159. package/dist/services/AccountsService.js.map +0 -1
  160. package/dist/services/accounting/AccountsService.d.ts +0 -20
  161. package/dist/services/accounting/AccountsService.js +0 -147
  162. package/dist/services/accounting/AccountsService.js.map +0 -1
  163. package/dist/services/accounting/Flows.js +0 -2
  164. package/dist/services/accounting/Flows.js.map +0 -1
  165. package/dist/services/accounting/LoginFlows.d.ts +0 -20
  166. package/dist/services/accounting/LoginFlows.js +0 -70
  167. package/dist/services/accounting/LoginFlows.js.map +0 -1
  168. package/dist/test/Test.js +0 -2
  169. package/dist/test/Test.js.map +0 -1
  170. package/dist/types/graphql/Errors.js.map +0 -1
  171. package/dist/types/raw/user/Users.d.ts +0 -120
  172. package/dist/types/raw/user/Users.js.map +0 -1
  173. package/src/services/data/UserAccountService.ts +0 -176
  174. package/src/services/helper/Extractors.ts +0 -455
  175. package/src/services/helper/Urls.ts +0 -109
  176. package/src/types/graphql/Errors.ts +0 -16
  177. package/src/types/raw/user/Tweets.ts +0 -2847
@@ -3,22 +3,25 @@ import { FetcherService } from "../FetcherService";
3
3
  import { AuthService } from "../AuthService";
4
4
 
5
5
  // TYPES
6
- import { TweetFilter, Tweet } from "../../types/Tweet";
7
- import { User } from "../../types/UserAccount";
8
- import { CursoredData } from '../../types/Service';
9
- import RawTweet from '../../types/raw/tweet/Tweet';
6
+ import { TweetFilter, Tweet } from "../../types/data/Tweet";
7
+ import { User } from "../../types/data/User";
8
+ import { CursoredData } from '../../types/data/Service';
9
+ import RawTweet, { Result as TweetData } from '../../types/raw/tweet/Tweet';
10
+ import { Result as UserData } from "../../types/raw/user/User";
10
11
  import RawTweets from '../../types/raw/tweet/Tweets';
11
12
  import RawLikers from '../../types/raw/tweet/Favouriters';
12
13
  import RawRetweeters from '../../types/raw/tweet/Retweeters';
14
+ import * as Errors from '../../types/data/Errors';
13
15
 
14
16
  // URLS
15
- import * as Urls from '../helper/Urls';
17
+ import * as TweetUrls from '../helper/urls/Tweets';
16
18
 
17
19
  // EXTRACTORS
18
- import * as Extractors from "../helper/Extractors";
20
+ import * as TweetExtractors from "../helper/extractors/Tweets";
19
21
 
20
22
  // DESERIALIZERS
21
- import * as Deserializers from '../helper/Deserializers';
23
+ import * as UserDeserializers from '../helper/deserializers/Users';
24
+ import * as TweetDeserializers from '../helper/deserializers/Tweets';
22
25
 
23
26
  // PARSERS
24
27
  import { toQueryString } from '../helper/Parser';
@@ -35,21 +38,26 @@ export class TweetService extends FetcherService {
35
38
  /**
36
39
  * @returns The list of tweets that match the given filter
37
40
  * @param filter The filter be used for searching the tweets
38
- * @param count The number of tweets to fetch
41
+ * @param count The number of tweets to fetch, must be >= 1 and <= 100
39
42
  * @param cursor The cursor to the next batch of tweets. If blank, first batch is fetched
40
43
  */
41
44
  async getTweets(filter: TweetFilter, count: number, cursor: string): Promise<CursoredData<Tweet>> {
45
+ // If invalid count provided
46
+ if (count < 1 && !cursor) {
47
+ throw new Error(Errors.ValidationErrors.InvalidCount);
48
+ }
49
+
42
50
  // Getting the raw data
43
- let res = await this.request<RawTweets>(Urls.tweetsUrl(toQueryString(filter), count, cursor), false).then(res => res.data);
51
+ let res = await this.request<RawTweets>(TweetUrls.tweetsUrl(toQueryString(filter), count, cursor), false).then(res => res.data);
44
52
 
45
53
  // Extracting data
46
- let data = Extractors.extractTweets(res);
54
+ let data = TweetExtractors.extractTweets(res);
47
55
 
48
56
  // Caching data
49
57
  this.cacheData(data);
50
58
 
51
59
  // Parsing data
52
- let tweets = data.required.map(item => Deserializers.toTweet(item));
60
+ let tweets = data.required.map((item: TweetData) => TweetDeserializers.toTweet(item));
53
61
 
54
62
  return {
55
63
  list: tweets,
@@ -69,47 +77,50 @@ export class TweetService extends FetcherService {
69
77
  if (cachedData) {
70
78
  return cachedData;
71
79
  }
72
- // If data does not exist in cache
73
- else {
74
- // Fetching the raw data
75
- let res = await this.request<RawTweet>(Urls.tweetDetailsUrl(tweetId), false).then(res => res.data);
80
+
81
+ // Fetching the raw data
82
+ let res = await this.request<RawTweet>(TweetUrls.tweetDetailsUrl(tweetId), false).then(res => res.data);
76
83
 
77
- // Extracting data
78
- let data = Extractors.extractTweet(res, tweetId);
84
+ // Extracting data
85
+ let data = TweetExtractors.extractTweet(res, tweetId);
79
86
 
80
- // Caching data
81
- this.cacheData(data);
87
+ // Caching data
88
+ this.cacheData(data);
82
89
 
83
- // Parsing data
84
- let tweet = Deserializers.toTweet(data.required[0]);
90
+ // Parsing data
91
+ let tweet = TweetDeserializers.toTweet(data.required[0]);
85
92
 
86
- return tweet;
87
- }
93
+ return tweet;
88
94
  }
89
95
 
90
96
  /**
91
97
  * @returns The list of users who liked the given tweet
92
98
  * @param tweetId The rest id of the target tweet
93
- * @param count The batch size of the list
99
+ * @param count The batch size of the list, must be >= 10 (when no cursor is provided) and <= 100
94
100
  * @param cursor The cursor to the next batch of users. If blank, first batch is fetched
95
101
  */
96
102
  async getTweetLikers(tweetId: string, count: number, cursor: string): Promise<CursoredData<User>> {
97
103
  // If user is not authenticated, abort
98
104
  if(!this.isAuthenticated) {
99
- return { error: new Error('Cannot fetch tweet likes without authentication!') };
105
+ throw new Error(Errors.AuthenticationErrors.NotAuthenticated);
106
+ }
107
+
108
+ // If invalid count provided
109
+ if (count < 10 && !cursor) {
110
+ throw new Error(Errors.ValidationErrors.InvalidCount);
100
111
  }
101
112
 
102
113
  // Fetching the raw data
103
- let res = await this.request<RawLikers>(Urls.tweetLikesUrl(tweetId, count, cursor)).then(res => res.data);
114
+ let res = await this.request<RawLikers>(TweetUrls.tweetLikesUrl(tweetId, count, cursor)).then(res => res.data);
104
115
 
105
116
  // Extracting data
106
- let data = Extractors.extractTweetLikers(res);
117
+ let data = TweetExtractors.extractTweetLikers(res);
107
118
 
108
119
  // Caching data
109
120
  this.cacheData(data);
110
121
 
111
122
  // Parsing data
112
- let users = data.required.map(item => Deserializers.toUser(item));
123
+ let users = data.required.map((item: UserData) => UserDeserializers.toUser(item));
113
124
 
114
125
  return {
115
126
  list: users,
@@ -120,26 +131,31 @@ export class TweetService extends FetcherService {
120
131
  /**
121
132
  * @returns The list of users who retweeted the given tweet
122
133
  * @param tweetId The rest id of the target tweet
123
- * @param count The batch size of the list
134
+ * @param count The batch size of the list, must be >= 10 (when no cursor is provided) and <= 100
124
135
  * @param cursor The cursor to the next batch of users. If blank, first batch is fetched
125
136
  */
126
137
  async getTweetRetweeters(tweetId: string, count: number, cursor: string): Promise<CursoredData<User>> {
127
138
  // If user is not authenticated, abort
128
139
  if(!this.isAuthenticated) {
129
- return { error: new Error('Cannot fetch tweet retweeters without authentication!') };
140
+ throw new Error(Errors.AuthenticationErrors.NotAuthenticated);
141
+ }
142
+
143
+ // If invalid count provided
144
+ if (count < 10 && !cursor) {
145
+ throw new Error(Errors.ValidationErrors.InvalidCount);
130
146
  }
131
147
 
132
148
  // Fetching the raw data
133
- let res = await this.request<RawRetweeters>(Urls.tweetRetweetUrl(tweetId, count, cursor)).then(res => res.data);
149
+ let res = await this.request<RawRetweeters>(TweetUrls.tweetRetweetUrl(tweetId, count, cursor)).then(res => res.data);
134
150
 
135
151
  // Extracting data
136
- let data = Extractors.extractTweetRetweeters(res);
152
+ let data = TweetExtractors.extractTweetRetweeters(res);
137
153
 
138
154
  // Caching data
139
155
  this.cacheData(data);
140
156
 
141
157
  // Parsing data
142
- let users = data.required.map(item => Deserializers.toUser(item));
158
+ let users = data.required.map((item: UserData) => UserDeserializers.toUser(item));
143
159
 
144
160
  return {
145
161
  list: users,
@@ -148,31 +164,36 @@ export class TweetService extends FetcherService {
148
164
  }
149
165
 
150
166
  /**
167
+ * THIS IS DISABLED FOR USE FOR NOW BECAUSE TWITTER DOESN'T HAVE ANY ENDPOINT FOR FETCHING REPLIES.
168
+ * THE DATA THIS RETURNS IS INCONSISTENT!
169
+ *
151
170
  * @returns The list of replies to the given tweet
152
171
  * @param tweetId The rest id of the target tweet
153
172
  * @param cursor The cursor to the next batch of replies. If blank, first batch is fetched
154
173
  */
174
+ /*
155
175
  async getTweetReplies(tweetId: string, cursor: string): Promise<CursoredData<Tweet>> {
156
176
  // If user is not authenticated, abort
157
177
  if(!this.isAuthenticated) {
158
- return { error: new Error('Cannot fetch tweet replies without authentication!') };
178
+ throw new Error(Errors.AuthenticationErrors.NotAuthenticated);
159
179
  }
160
180
 
161
181
  // Fetching the raw data
162
- let res = await this.request<RawTweet>(Urls.tweetRepliesUrl(tweetId, cursor)).then(res => res.data);
182
+ let res = await this.request<RawTweet>(TweetUrls.tweetRepliesUrl(tweetId, cursor)).then(res => res.data);
163
183
 
164
184
  // Extracting data
165
- let data = Extractors.extractTweetReplies(res, tweetId);
185
+ let data = TweetExtractors.extractTweetReplies(res, tweetId);
166
186
 
167
187
  // Caching data
168
188
  this.cacheData(data);
169
189
 
170
190
  // Parsing data
171
- let tweets = data.required.map(item => Deserializers.toTweet(item));
191
+ let tweets = data.required.map((item: TweetData) => TweetDeserializers.toTweet(item));
172
192
 
173
193
  return {
174
194
  list: tweets,
175
195
  next: { value: data.cursor }
176
196
  };
177
197
  }
198
+ */
178
199
  }
@@ -0,0 +1,187 @@
1
+ // SERVICES
2
+ import { FetcherService } from '../FetcherService';
3
+ import { AuthService } from '../AuthService';
4
+
5
+ // TYPES
6
+ import { User } from '../../types/data/User';
7
+ import { Tweet } from '../../types/data/Tweet';
8
+ import { CursoredData } from '../../types/data/Service';
9
+ import { Result as TweetData } from '../../types/raw/tweet/Tweet';
10
+ import RawUser, { Result as UserData } from '../../types/raw/user/User';
11
+ import RawUserFollowers from '../../types/raw/user/Followers';
12
+ import RawUserFollowing from '../../types/raw/user/Following';
13
+ import RawUserLikes from '../../types/raw/user/Likes';
14
+ import * as Errors from '../../types/data/Errors';
15
+
16
+ // URLS
17
+ import * as UserUrls from '../helper/urls/Users';
18
+
19
+ // EXTRACTORS
20
+ import * as UserExtractors from '../helper/extractors/Users';
21
+
22
+ // DESERIALIZERS
23
+ import * as UserDeserializers from '../helper/deserializers/Users';
24
+ import * as TweetDeserializers from '../helper/deserializers/Tweets';
25
+
26
+ /**
27
+ * A service that deals with fetching of data related to user account
28
+ */
29
+ export class UserService extends FetcherService {
30
+ // MEMBER METHODS
31
+ constructor(auth: AuthService) {
32
+ super(auth);
33
+ }
34
+
35
+ /**
36
+ * @returns The details of the given user
37
+ * @param screenName The screen name of the target user.
38
+ */
39
+ async getUserDetails(screenName: string): Promise<User> {
40
+ // Fetching the raw data
41
+ let res: RawUser = await this.request<RawUser>(UserUrls.userDetailsUrl(screenName), false).then(res => res.data);
42
+
43
+ // Extracting data
44
+ let data = UserExtractors.extractUserDetails(res);
45
+
46
+ // Caching data
47
+ this.cacheData(data);
48
+
49
+ // Parsing data
50
+ let user = UserDeserializers.toUser(data.required[0]);
51
+
52
+ return user;
53
+ }
54
+
55
+ /**
56
+ * @returns The details of the user with given rest id
57
+ * @param restId The screen name of the target user.
58
+ */
59
+ async getUserDetailsById(restId: string): Promise<User> {
60
+ // Getting data from cache
61
+ let cachedData = await this.readData(restId);
62
+
63
+ // If data exists in cache
64
+ if(cachedData) {
65
+ return cachedData;
66
+ }
67
+
68
+ // Fetchin the raw data
69
+ let res = await this.request<RawUser>(UserUrls.userDetailsByIdUrl(restId), false).then(res => res.data);
70
+
71
+ // Extracting data
72
+ let data = UserExtractors.extractUserDetails(res);
73
+
74
+ // Caching data
75
+ this.cacheData(data);
76
+
77
+ // Parsing data
78
+ let user = UserDeserializers.toUser(data.required[0]);
79
+
80
+ return user;
81
+ }
82
+
83
+ /**
84
+ * @returns The list of users followed by the target user
85
+ * @param userId The rest id of the target user
86
+ * @param count The number of following to fetch, should be >= 40 (when no cursor is provided) and <=100
87
+ * @param cursor The cursor to next batch. If blank, first batch is fetched
88
+ */
89
+ async getUserFollowing(userId: string, count: number, cursor: string): Promise<CursoredData<User>> {
90
+ // If user is not authenticated, abort
91
+ if(!this.isAuthenticated) {
92
+ throw new Error(Errors.AuthenticationErrors.NotAuthenticated);
93
+ }
94
+
95
+ // If invalid count provided
96
+ if (count < 40 && !cursor) {
97
+ throw new Error(Errors.ValidationErrors.InvalidCount);
98
+ }
99
+
100
+ // Fetchin the raw data
101
+ let res = await this.request<RawUserFollowing>(UserUrls.userFollowingUrl(userId, count, cursor)).then(res => res.data);
102
+
103
+ // Extracting data
104
+ let data = UserExtractors.extractUserFollow(res);
105
+
106
+ // Caching data
107
+ this.cacheData(data);
108
+
109
+ // Parsing data
110
+ let users = data.required.map((item: UserData) => UserDeserializers.toUser(item));
111
+
112
+ return {
113
+ list: users,
114
+ next: { value: data.cursor }
115
+ };
116
+ }
117
+
118
+ /**
119
+ * @returns The list of users following the target user
120
+ * @param userId The rest id of the target user
121
+ * @param count The number of followers to fetch, should be >= 40 (when no cursor is provided) and <=100
122
+ * @param cursor The cursor to next batch. If blank, first batch is fetched
123
+ */
124
+ async getUserFollowers(userId: string, count: number, cursor: string): Promise<CursoredData<User>> {
125
+ // If user is not authenticated, abort
126
+ if (!this.isAuthenticated) {
127
+ throw new Error(Errors.AuthenticationErrors.NotAuthenticated);
128
+ }
129
+
130
+ // If invalid count provided
131
+ if (count < 40 && !cursor) {
132
+ throw new Error(Errors.ValidationErrors.InvalidCount);
133
+ }
134
+
135
+ // Fetching the raw data
136
+ let res = await this.request<RawUserFollowers>(UserUrls.userFollowersUrl(userId, count, cursor)).then(res => res.data);
137
+
138
+ // Extracting data
139
+ let data = UserExtractors.extractUserFollow(res);
140
+
141
+ // Caching data
142
+ this.cacheData(data);
143
+
144
+ // Parsing data
145
+ let users = data.required.map((item: UserData) => UserDeserializers.toUser(item));
146
+
147
+ return {
148
+ list: users,
149
+ next: { value: data.cursor }
150
+ };
151
+ }
152
+
153
+ /**
154
+ * @returns The list of tweets liked by the target user
155
+ * @param userId The rest id of the target user
156
+ * @param count The number of likes to fetch, must be >= 40 (when no cursor is provided) and <= 100
157
+ * @param cursor The cursor to next batch. If blank, first batch is fetched
158
+ */
159
+ async getUserLikes(userId: string, count: number, cursor: string): Promise<CursoredData<Tweet>> {
160
+ // If user is not authenticated, abort
161
+ if (!this.isAuthenticated) {
162
+ throw new Error(Errors.AuthenticationErrors.NotAuthenticated);
163
+ }
164
+
165
+ // If invalid count provided
166
+ if (count < 40 && !cursor) {
167
+ throw new Error(Errors.ValidationErrors.InvalidCount);
168
+ }
169
+
170
+ // Fetching the raw data
171
+ let res = await this.request<RawUserLikes>(UserUrls.userLikesUrl(userId, count, cursor)).then(res => res.data);
172
+
173
+ // Extracting data
174
+ let data = UserExtractors.extractUserLikes(res);
175
+
176
+ // Caching data
177
+ this.cacheData(data);
178
+
179
+ // Parsing data
180
+ let tweets = data.required.map((item: TweetData) => TweetDeserializers.toTweet(item));
181
+
182
+ return {
183
+ list: tweets,
184
+ next: { value: data.cursor }
185
+ };
186
+ }
187
+ };
@@ -1,4 +1,5 @@
1
- import { TweetFilter } from '../../types/Tweet';
1
+ // TYPES
2
+ import { TweetFilter } from '../../types/data/Tweet';
2
3
 
3
4
  /**
4
5
  * @returns Whether the given json object is empty or not
@@ -95,14 +96,15 @@ export function toQueryString(filter: TweetFilter): string {
95
96
  // Concatenating the input filter arguments to a URL query formatted string
96
97
  return [
97
98
  filter.words ? filter.words.join(' ') : '',
98
- filter.hashtags ? `(${filter.hashtags.map(hashtag => '%23' + hashtag).join(' OR ')})` : '',
99
+ filter.hashtags ? `(${filter.hashtags.map(hashtag => '#' + hashtag).join(' OR ')})` : '',
99
100
  filter.fromUsers ? `(${filter.fromUsers.map(user => `from:${user}`).join(' OR ')})` : '',
100
101
  filter.toUsers ? `(${filter.toUsers.map(user => `to:${user}`).join(' OR ')})` : '',
101
- filter.mentions ? `(${filter.mentions.map(mention => '%40' + mention).join(' OR ')})` : '',
102
+ filter.mentions ? `(${filter.mentions.map(mention => '@' + mention).join(' OR ')})` : '',
102
103
  filter.startDate ? `since:${filter.startDate}` : '',
103
104
  filter.endDate ? `until:${filter.endDate}` : '',
105
+ filter.sinceId ? `since_id:${filter.sinceId}` : '',
104
106
  filter.quoted ? `quoted_tweet_id:${filter.quoted}` : ''
105
107
  ]
106
108
  .filter(item => item !== '()' && item !== '')
107
- .join(' ') + (!filter.links ? '%20-filter%3Alinks' : '');
109
+ .join(' ') + (!filter.links ? ' -filter:links' : '');
108
110
  }
@@ -1,34 +1,9 @@
1
1
  // TYPES
2
- import { User } from '../../types/UserAccount';
3
- import { Tweet, TweetEntities } from '../../types/Tweet';
4
- import { Result as RawUser } from '../../types/raw/user/User';
5
- import { Result as RawTweet, Entities2 as RawTweetEntities } from '../../types/raw/tweet/Tweet';
2
+ import { Tweet, TweetEntities } from '../../../types/data/Tweet';
3
+ import { Result as RawTweet, Entities2 as RawTweetEntities } from '../../../types/raw/tweet/Tweet';
6
4
 
7
5
  // PARSERS
8
- import * as Parsers from './Parser';
9
-
10
- /**
11
- * @returns A User object containing the user details
12
- * @param data The raw user data from Twitter API
13
- */
14
- export function toUser(data: RawUser): User {
15
- return {
16
- id: data.rest_id,
17
- userName: data.legacy.screen_name,
18
- fullName: data.legacy.name,
19
- createdAt: data.legacy.created_at,
20
- description: data.legacy.description,
21
- isVerified: data.legacy.verified,
22
- favouritesCount: data.legacy.favourites_count,
23
- followersCount: data.legacy.followers_count,
24
- followingsCount: data.legacy.friends_count,
25
- statusesCount: data.legacy.statuses_count,
26
- location: data.legacy.location,
27
- pinnedTweet: data.legacy.pinned_tweet_ids_str[0],
28
- profileBanner: data.legacy.profile_banner_url,
29
- profileImage: data.legacy.profile_image_url_https
30
- };
31
- }
6
+ import * as Parsers from '../Parser';
32
7
 
33
8
  /**
34
9
  * @returns A TweetEntities object containing the various tweet entities
@@ -0,0 +1,26 @@
1
+ // TYPES
2
+ import { User } from '../../../types/data/User';
3
+ import { Result as RawUser } from '../../../types/raw/user/User';
4
+
5
+ /**
6
+ * @returns A User object containing the user details
7
+ * @param data The raw user data from Twitter API
8
+ */
9
+ export function toUser(data: RawUser): User {
10
+ return {
11
+ id: data.rest_id,
12
+ userName: data.legacy.screen_name,
13
+ fullName: data.legacy.name,
14
+ createdAt: data.legacy.created_at,
15
+ description: data.legacy.description,
16
+ isVerified: data.legacy.verified,
17
+ favouritesCount: data.legacy.favourites_count,
18
+ followersCount: data.legacy.followers_count,
19
+ followingsCount: data.legacy.friends_count,
20
+ statusesCount: data.legacy.statuses_count,
21
+ location: data.legacy.location,
22
+ pinnedTweet: data.legacy.pinned_tweet_ids_str[0],
23
+ profileBanner: data.legacy.profile_banner_url,
24
+ profileImage: data.legacy.profile_image_url_https
25
+ };
26
+ }