rettiwt-api 2.1.0 → 2.2.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.
@@ -1 +1 @@
1
- {"version":3,"file":"TweetService.js","sourceRoot":"","sources":["../../src/services/TweetService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,WAAW;AACX,6CAA0D;AAG1D,WAAW;AACX,mDAAkD;AAOlD;;;;GAIG;AACH;IAAkC,gCAAc;IAC/C;;;;OAIG;IACH,sBAAY,IAAoB;eAC/B,kBAAM,IAAI,CAAC;IACZ,CAAC;IAED;;;;;;;OAOG;IACG,8BAAO,GAAb,UAAc,EAAU;;;;;4BAEV,qBAAM,IAAI,CAAC,KAAK,CAAQ,4BAAa,CAAC,aAAa,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAA;;wBAAvE,IAAI,GAAG,SAAgE;wBAE7E,sBAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAC;;;;KACpB;IAED;;;;;;;;;OASG;IACG,6BAAM,GAAZ,UAAa,KAAkB,EAAE,KAAc,EAAE,MAAe;;;;;4BAElD,qBAAM,IAAI,CAAC,KAAK,CAAQ,4BAAa,CAAC,YAAY,EAAE;4BAChE,MAAM,EAAE,KAAK;4BACb,KAAK,EAAE,KAAK;4BACZ,MAAM,EAAE,MAAM;yBACd,CAAC,EAAA;;wBAJI,IAAI,GAAG,SAIX;wBAEF,oDAAoD;wBACpD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAjE,CAAiE,CAAC,CAAC;wBAE5F,sBAAO,IAAI,EAAC;;;;KACZ;IAED;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@@ -1,4 +1,3 @@
1
- import { AuthCredential } from 'rettiwt-auth';
2
1
  import { FetcherService } from './FetcherService';
3
2
  import { User } from '../models/User';
4
3
  import { Tweet } from '../models/Tweet';
@@ -10,11 +9,12 @@ import { CursoredData } from '../models/CursoredData';
10
9
  */
11
10
  export declare class UserService extends FetcherService {
12
11
  /**
13
- * @param cred - The credentials to use for authenticating against Twitter API.
12
+ * @param apiKey - The apiKey (cookie) to use for authenticating Rettiwt against Twitter API.
13
+ * @param proxyUrl - Optional URL with proxy configuration to use for requests to Twitter API.
14
14
  *
15
15
  * @internal
16
16
  */
17
- constructor(cred: AuthCredential);
17
+ constructor(apiKey: string, proxyUrl?: URL);
18
18
  /**
19
19
  * Get the details of a user.
20
20
  *
@@ -57,4 +57,17 @@ export declare class UserService extends FetcherService {
57
57
  * @public
58
58
  */
59
59
  likes(userId: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>>;
60
+ /**
61
+ * Get the timeline of the given user.
62
+ *
63
+ * @param userId - The rest id of the target user.
64
+ * @param count - The number of timeline items to fetch, must be \<= 20.
65
+ * @param cursor - The cursor to the batch of timeline items to fetch.
66
+ * @returns The timeline of the target user.
67
+ *
68
+ * @remarks If the target user has a pinned tweet, the returned timeline has one item extra and this is always the pinned tweet.
69
+ *
70
+ * @public
71
+ */
72
+ timeline(userId: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>>;
60
73
  }
@@ -64,12 +64,13 @@ var FetcherService_1 = require("./FetcherService");
64
64
  var UserService = /** @class */ (function (_super) {
65
65
  __extends(UserService, _super);
66
66
  /**
67
- * @param cred - The credentials to use for authenticating against Twitter API.
67
+ * @param apiKey - The apiKey (cookie) to use for authenticating Rettiwt against Twitter API.
68
+ * @param proxyUrl - Optional URL with proxy configuration to use for requests to Twitter API.
68
69
  *
69
70
  * @internal
70
71
  */
71
- function UserService(cred) {
72
- return _super.call(this, cred) || this;
72
+ function UserService(apiKey, proxyUrl) {
73
+ return _super.call(this, apiKey, proxyUrl) || this;
73
74
  }
74
75
  /**
75
76
  * Get the details of a user.
@@ -182,6 +183,35 @@ var UserService = /** @class */ (function (_super) {
182
183
  });
183
184
  });
184
185
  };
186
+ /**
187
+ * Get the timeline of the given user.
188
+ *
189
+ * @param userId - The rest id of the target user.
190
+ * @param count - The number of timeline items to fetch, must be \<= 20.
191
+ * @param cursor - The cursor to the batch of timeline items to fetch.
192
+ * @returns The timeline of the target user.
193
+ *
194
+ * @remarks If the target user has a pinned tweet, the returned timeline has one item extra and this is always the pinned tweet.
195
+ *
196
+ * @public
197
+ */
198
+ UserService.prototype.timeline = function (userId, count, cursor) {
199
+ return __awaiter(this, void 0, void 0, function () {
200
+ var data;
201
+ return __generator(this, function (_a) {
202
+ switch (_a.label) {
203
+ case 0: return [4 /*yield*/, this.fetch(rettiwt_core_1.EResourceType.USER_TWEETS, {
204
+ id: userId,
205
+ count: count,
206
+ cursor: cursor,
207
+ })];
208
+ case 1:
209
+ data = _a.sent();
210
+ return [2 /*return*/, data];
211
+ }
212
+ });
213
+ });
214
+ };
185
215
  return UserService;
186
216
  }(FetcherService_1.FetcherService));
187
217
  exports.UserService = UserService;
@@ -1 +1 @@
1
- {"version":3,"file":"UserService.js","sourceRoot":"","sources":["../../src/services/UserService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,WAAW;AACX,6CAA6C;AAG7C,WAAW;AACX,mDAAkD;AASlD;;;;GAIG;AACH;IAAiC,+BAAc;IAC9C;;;;OAIG;IACH,qBAAY,IAAoB;eAC/B,kBAAM,IAAI,CAAC;IACZ,CAAC;IAED;;;;;;;OAOG;IACG,6BAAO,GAAb,UAAc,EAAU;;;;;;6BAInB,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,EAArB,wBAAqB;wBAEjB,qBAAM,IAAI,CAAC,KAAK,CAAO,4BAAa,CAAC,YAAY,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,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BAEjD,qBAAM,IAAI,CAAC,KAAK,CAAO,4BAAa,CAAC,cAAc,EAAE;4BACjE,EAAE,EAAE,MAAM;4BACV,KAAK,EAAE,KAAK;4BACZ,MAAM,EAAE,MAAM;yBACd,CAAC,EAAA;;wBAJI,IAAI,GAAG,SAIX;wBAEF,sBAAO,IAAI,EAAC;;;;KACZ;IAED;;;;;;;;;OASG;IACG,2BAAK,GAAX,UAAY,MAAc,EAAE,KAAc,EAAE,MAAe;;;;;4BAE7C,qBAAM,IAAI,CAAC,KAAK,CAAQ,4BAAa,CAAC,UAAU,EAAE;4BAC9D,EAAE,EAAE,MAAM;4BACV,KAAK,EAAE,KAAK;4BACZ,MAAM,EAAE,MAAM;yBACd,CAAC,EAAA;;wBAJI,IAAI,GAAG,SAIX;wBAEF,sBAAO,IAAI,EAAC;;;;KACZ;IAED;;;;;;;;;;;OAWG;IACG,8BAAQ,GAAd,UAAe,MAAc,EAAE,KAAc,EAAE,MAAe;;;;;4BAEhD,qBAAM,IAAI,CAAC,KAAK,CAAQ,4BAAa,CAAC,WAAW,EAAE;4BAC/D,EAAE,EAAE,MAAM;4BACV,KAAK,EAAE,KAAK;4BACZ,MAAM,EAAE,MAAM;yBACd,CAAC,EAAA;;wBAJI,IAAI,GAAG,SAIX;wBAEF,sBAAO,IAAI,EAAC;;;;KACZ;IACF,kBAAC;AAAD,CAAC,AAzHD,CAAiC,+BAAc,GAyH9C;AAzHY,kCAAW"}
@@ -1,12 +1,3 @@
1
- /**
2
- * The cursor to the batch of data to be fetched.
3
- *
4
- * @public
5
- */
6
- export interface ICursor {
7
- /** The cursor string. */
8
- value: string;
9
- }
10
1
  /**
11
2
  * The data that us fetched batch-wise along with a cursor.
12
3
  *
@@ -20,3 +11,12 @@ export interface ICursoredData<T> {
20
11
  /** The cursor to the next batch of data. */
21
12
  next: ICursor;
22
13
  }
14
+ /**
15
+ * The cursor to the batch of data to be fetched.
16
+ *
17
+ * @public
18
+ */
19
+ export interface ICursor {
20
+ /** The cursor string. */
21
+ value: string;
22
+ }
@@ -1,19 +1,5 @@
1
+ import { EMediaType } from 'rettiwt-core';
1
2
  import { IUser } from './User';
2
- /**
3
- * The different types parsed entities like urls, media, mentions, hashtags, etc.
4
- *
5
- * @public
6
- */
7
- export interface ITweetEntities {
8
- /** The list of hashtags mentioned in the tweet. */
9
- hashtags: string[];
10
- /** The list of urls mentioned in the tweet. */
11
- urls: string[];
12
- /** The list of IDs of users mentioned in the tweet. */
13
- mentionedUsers: string[];
14
- /** The list of urls to various media mentioned in the tweet. */
15
- media: string[];
16
- }
17
3
  /**
18
4
  * The details of a single Tweet.
19
5
  *
@@ -28,6 +14,8 @@ export interface ITweet {
28
14
  createdAt: string;
29
15
  /** Additional tweet entities like urls, mentions, etc. */
30
16
  entities: ITweetEntities;
17
+ /** The urls of the media contents of the tweet (if any). */
18
+ media: ITweetMedia[];
31
19
  /** The rest id of the tweet which is quoted in the tweet. */
32
20
  quoted: string;
33
21
  /** The full text content of the tweet. */
@@ -49,3 +37,27 @@ export interface ITweet {
49
37
  /** The number of bookmarks of a tweet. */
50
38
  bookmarkCount: number;
51
39
  }
40
+ /**
41
+ * The different types parsed entities like urls, media, mentions, hashtags, etc.
42
+ *
43
+ * @public
44
+ */
45
+ export interface ITweetEntities {
46
+ /** The list of hashtags mentioned in the tweet. */
47
+ hashtags: string[];
48
+ /** The list of urls mentioned in the tweet. */
49
+ urls: string[];
50
+ /** The list of IDs of users mentioned in the tweet. */
51
+ mentionedUsers: string[];
52
+ }
53
+ /**
54
+ * A single media content.
55
+ *
56
+ * @public
57
+ */
58
+ export interface ITweetMedia {
59
+ /** The type of media. */
60
+ type: EMediaType;
61
+ /** The direct URL to the media. */
62
+ url: string;
63
+ }
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "rettiwt-api",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "An API for fetching data from TwitterAPI, without any rate limits!",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
+ "prepare": "tsc",
9
10
  "format": "prettier --write .",
10
11
  "lint": "eslint --max-warnings 0 .",
11
12
  "docs": "typedoc src/index.ts",
@@ -26,8 +27,9 @@
26
27
  "homepage": "https://rishikant181.github.io/Rettiwt-API/",
27
28
  "dependencies": {
28
29
  "axios": "1.3.2",
30
+ "https-proxy-agent": "^7.0.2",
29
31
  "rettiwt-auth": "1.2.0",
30
- "rettiwt-core": "3.1.2"
32
+ "rettiwt-core": "3.2.0-alpha.3"
31
33
  },
32
34
  "devDependencies": {
33
35
  "@types/node": "20.4.1",
package/src/Rettiwt.ts CHANGED
@@ -1,6 +1,3 @@
1
- // PACKAGE
2
- import { AuthCredential } from 'rettiwt-auth';
3
-
4
1
  // SERVICES
5
2
  import { TweetService } from './services/TweetService';
6
3
  import { UserService } from './services/UserService';
@@ -20,14 +17,11 @@ export class Rettiwt {
20
17
  /**
21
18
  * Initializes a new Rettiwt instance using the given api key.
22
19
  *
23
- * @param apiKey - The apiKey (cookie) to be used for authenticating Rettiwt against Twitter.
20
+ * @param apiKey - The apiKey (cookie) to use for authenticating Rettiwt against Twitter API.
21
+ * @param proxyUrl - Optional URL with proxy configuration to use for requests to Twitter API.
24
22
  */
25
- constructor(apiKey: string) {
26
- // Preparing auth credentials
27
- const cred: AuthCredential = new AuthCredential(apiKey.split(';'));
28
-
29
- // Initalizing service instances
30
- this.tweet = new TweetService(cred);
31
- this.user = new UserService(cred);
23
+ constructor(apiKey: string, proxyUrl?: URL) {
24
+ this.tweet = new TweetService(apiKey, proxyUrl);
25
+ this.user = new UserService(apiKey, proxyUrl);
32
26
  }
33
27
  }
@@ -8,25 +8,6 @@ import { User } from './User';
8
8
  // TYPES
9
9
  import { ICursor, ICursoredData } from '../types/CursoredData';
10
10
 
11
- /**
12
- * The cursor to the batch of data to be fetched.
13
- *
14
- * @public
15
- */
16
- export class Cursor implements ICursor {
17
- /** The cursor string. */
18
- value: string;
19
-
20
- /**
21
- * Initializes a new cursor from the given cursor string.
22
- *
23
- * @param cursorStr - The string representation of the cursor.
24
- */
25
- constructor(cursorStr: string) {
26
- this.value = cursorStr;
27
- }
28
- }
29
-
30
11
  /**
31
12
  * The data that us fetched batch-wise along with a cursor.
32
13
  *
@@ -62,3 +43,22 @@ export class CursoredData<T extends Tweet | User> implements ICursoredData<T> {
62
43
  this.next = new Cursor(next);
63
44
  }
64
45
  }
46
+
47
+ /**
48
+ * The cursor to the batch of data to be fetched.
49
+ *
50
+ * @public
51
+ */
52
+ export class Cursor implements ICursor {
53
+ /** The cursor string. */
54
+ value: string;
55
+
56
+ /**
57
+ * Initializes a new cursor from the given cursor string.
58
+ *
59
+ * @param cursorStr - The string representation of the cursor.
60
+ */
61
+ constructor(cursorStr: string) {
62
+ this.value = cursorStr;
63
+ }
64
+ }
@@ -1,6 +1,13 @@
1
+ // PACKAGES
2
+ import {
3
+ ITweet as IRawTweet,
4
+ IEntities as IRawTweetEntities,
5
+ IExtendedMedia as IRawExtendedMedia,
6
+ EMediaType,
7
+ } from 'rettiwt-core';
8
+
1
9
  // TYPES
2
10
  import { ITweet, ITweetEntities } from '../types/Tweet';
3
- import { ITweet as IRawTweet, IEntities as IRawTweetEntities } from 'rettiwt-core';
4
11
 
5
12
  // MODELS
6
13
  import { User } from './User';
@@ -8,55 +15,6 @@ import { User } from './User';
8
15
  // PARSERS
9
16
  import { normalizeText } from '../helper/JsonUtils';
10
17
 
11
- /**
12
- * The different types parsed entities like urls, media, mentions, hashtags, etc.
13
- *
14
- * @public
15
- */
16
- export class TweetEntities implements ITweetEntities {
17
- /** The list of hashtags mentioned in the tweet. */
18
- hashtags: string[] = [];
19
-
20
- /** The list of urls mentioned in the tweet. */
21
- urls: string[] = [];
22
-
23
- /** The list of IDs of users mentioned in the tweet. */
24
- mentionedUsers: string[] = [];
25
-
26
- /** The list of urls to various media mentioned in the tweet. */
27
- media: string[] = [];
28
-
29
- constructor(entities: IRawTweetEntities) {
30
- // Extracting user mentions
31
- if (entities.user_mentions) {
32
- for (const user of entities.user_mentions) {
33
- this.mentionedUsers.push(user.screen_name);
34
- }
35
- }
36
-
37
- // Extracting urls
38
- if (entities.urls) {
39
- for (const url of entities.urls) {
40
- this.urls.push(url.expanded_url);
41
- }
42
- }
43
-
44
- // Extracting hashtags
45
- if (entities.hashtags) {
46
- for (const hashtag of entities.hashtags) {
47
- this.hashtags.push(hashtag.text);
48
- }
49
- }
50
-
51
- // Extracting media urls (if any)
52
- if (entities.media) {
53
- for (const media of entities.media) {
54
- this.media.push(media.media_url_https);
55
- }
56
- }
57
- }
58
- }
59
-
60
18
  /**
61
19
  * The details of a single Tweet.
62
20
  *
@@ -75,6 +33,9 @@ export class Tweet implements ITweet {
75
33
  /** Additional tweet entities like urls, mentions, etc. */
76
34
  entities: TweetEntities;
77
35
 
36
+ /** The urls of the media contents of the tweet (if any). */
37
+ media: TweetMedia[];
38
+
78
39
  /** The rest id of the tweet which is quoted in the tweet. */
79
40
  quoted: string;
80
41
 
@@ -115,6 +76,7 @@ export class Tweet implements ITweet {
115
76
  this.createdAt = tweet.legacy.created_at;
116
77
  this.tweetBy = new User(tweet.core.user_results.result);
117
78
  this.entities = new TweetEntities(tweet.legacy.entities);
79
+ this.media = tweet.legacy.extended_entities?.media?.map((media) => new TweetMedia(media));
118
80
  this.quoted = tweet.legacy.quoted_status_id_str;
119
81
  this.fullText = normalizeText(tweet.legacy.full_text);
120
82
  this.replyTo = tweet.legacy.in_reply_to_status_id_str;
@@ -127,3 +89,93 @@ export class Tweet implements ITweet {
127
89
  this.bookmarkCount = tweet.legacy.bookmark_count;
128
90
  }
129
91
  }
92
+
93
+ /**
94
+ * The different types parsed entities like urls, media, mentions, hashtags, etc.
95
+ *
96
+ * @public
97
+ */
98
+ export class TweetEntities implements ITweetEntities {
99
+ /** The list of hashtags mentioned in the tweet. */
100
+ hashtags: string[] = [];
101
+
102
+ /** The list of urls mentioned in the tweet. */
103
+ urls: string[] = [];
104
+
105
+ /** The list of IDs of users mentioned in the tweet. */
106
+ mentionedUsers: string[] = [];
107
+
108
+ /**
109
+ * Initializes the TweetEntities from the raw tweet entities.
110
+ *
111
+ * @param entities - The raw tweet entities.
112
+ */
113
+ constructor(entities: IRawTweetEntities) {
114
+ // Extracting user mentions
115
+ if (entities.user_mentions) {
116
+ for (const user of entities.user_mentions) {
117
+ this.mentionedUsers.push(user.screen_name);
118
+ }
119
+ }
120
+
121
+ // Extracting urls
122
+ if (entities.urls) {
123
+ for (const url of entities.urls) {
124
+ this.urls.push(url.expanded_url);
125
+ }
126
+ }
127
+
128
+ // Extracting hashtags
129
+ if (entities.hashtags) {
130
+ for (const hashtag of entities.hashtags) {
131
+ this.hashtags.push(hashtag.text);
132
+ }
133
+ }
134
+ }
135
+ }
136
+
137
+ /**
138
+ * A single media content.
139
+ *
140
+ * @public
141
+ */
142
+ export class TweetMedia {
143
+ /** The type of media. */
144
+ type: EMediaType;
145
+
146
+ /** The direct URL to the media. */
147
+ url: string = '';
148
+
149
+ /**
150
+ * Initializes the TweetMedia from the raw tweet media.
151
+ *
152
+ * @param media - The raw tweet media.
153
+ */
154
+ constructor(media: IRawExtendedMedia) {
155
+ this.type = media.type;
156
+
157
+ // If the media is a photo
158
+ if (media.type == EMediaType.PHOTO) {
159
+ this.url = media.media_url_https;
160
+ }
161
+ // If the media is a gif
162
+ else if (media.type == EMediaType.GIF) {
163
+ this.url = media.video_info?.variants[0].url as string;
164
+ }
165
+ // If the media is a video
166
+ else {
167
+ /** The highest bitrate of all variants. */
168
+ let highestRate: number = 0;
169
+
170
+ /**
171
+ * Selecting the URL of the video variant with the highest bitrate.
172
+ */
173
+ media.video_info?.variants.forEach((variant) => {
174
+ if (variant.bitrate > highestRate) {
175
+ highestRate = variant.bitrate;
176
+ this.url = variant.url;
177
+ }
178
+ });
179
+ }
180
+ }
181
+ }
@@ -1,6 +1,8 @@
1
+ // PACKAGES
2
+ import { IUser as IRawUser } from 'rettiwt-core';
3
+
1
4
  // TYPES
2
5
  import { IUser } from '../types/User';
3
- import { IUser as IRawUser } from 'rettiwt-core';
4
6
 
5
7
  /**
6
8
  * The details of a single user.
@@ -12,7 +12,9 @@ import {
12
12
  EErrorCodes,
13
13
  } from 'rettiwt-core';
14
14
  import axios, { AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from 'axios';
15
+ import https, { Agent } from 'https';
15
16
  import { AuthCredential } from 'rettiwt-auth';
17
+ import { HttpsProxyAgent } from 'https-proxy-agent';
16
18
 
17
19
  // ENUMS
18
20
  import { EHttpStatus } from '../enums/HTTP';
@@ -35,11 +37,40 @@ export class FetcherService {
35
37
  /** The credential to use for authenticating against Twitter API. */
36
38
  private cred: AuthCredential;
37
39
 
40
+ /** The HTTPS Agent to use for requests to Twitter API. */
41
+ private readonly httpsAgent: Agent;
42
+
38
43
  /**
39
- * @param cred - The credentials to use for authenticating against Twitter API.
44
+ * @param apiKey - The apiKey (cookie) to use for authenticating Rettiwt against Twitter API.
45
+ * @param proxyUrl - Optional URL with proxy configuration to use for requests to Twitter API.
40
46
  */
41
- constructor(cred: AuthCredential) {
42
- this.cred = cred;
47
+ constructor(apiKey: string, proxyUrl?: URL) {
48
+ this.cred = this.getAuthCredential(apiKey);
49
+ this.httpsAgent = this.getHttpsAgent(proxyUrl);
50
+ }
51
+
52
+ /**
53
+ * Returns an AuthCredential generated using the given API key.
54
+ *
55
+ * @param apiKey - The API key to use for authenticating.
56
+ * @returns The generated AuthCredential.
57
+ */
58
+ private getAuthCredential(apiKey: string): AuthCredential {
59
+ return new AuthCredential(apiKey.split(';'));
60
+ }
61
+
62
+ /**
63
+ * Gets the HttpsAgent based on whether a proxy is used or not.
64
+ *
65
+ * @param proxyUrl - Optional URL with proxy configuration to use for requests to Twitter API.
66
+ * @returns The HttpsAgent to use.
67
+ */
68
+ private getHttpsAgent(proxyUrl?: URL): Agent {
69
+ if (proxyUrl) {
70
+ return new HttpsProxyAgent(proxyUrl);
71
+ }
72
+
73
+ return new https.Agent();
43
74
  }
44
75
 
45
76
  /**
@@ -98,10 +129,11 @@ export class FetcherService {
98
129
  method: config.type,
99
130
  data: config.payload,
100
131
  headers: JSON.parse(JSON.stringify(this.cred.toHeader())) as AxiosRequestHeaders,
132
+ httpsAgent: this.httpsAgent,
101
133
  };
102
134
 
103
135
  /**
104
- * After making the request, the response is then passed to HTTP error handling middlware for HTTP error handling.
136
+ * After making the request, the response is then passed to HTTP error handling middleware for HTTP error handling.
105
137
  */
106
138
  return await axios<IResponse<unknown>>(axiosRequest)
107
139
  .then((res) => this.handleHttpError(res))
@@ -133,7 +165,8 @@ export class FetcherService {
133
165
  } else if (
134
166
  type == EResourceType.TWEET_SEARCH ||
135
167
  type == EResourceType.USER_LIKES ||
136
- type == EResourceType.LIST_TWEETS
168
+ type == EResourceType.LIST_TWEETS ||
169
+ type == EResourceType.USER_TWEETS
137
170
  ) {
138
171
  required = findByFilter<ITimelineTweet>(data, '__typename', 'TimelineTweet').map(
139
172
  (item) => item.tweet_results.result,
@@ -1,6 +1,5 @@
1
1
  // PACKAGES
2
2
  import { EResourceType, TweetFilter } from 'rettiwt-core';
3
- import { AuthCredential } from 'rettiwt-auth';
4
3
 
5
4
  // SERVICES
6
5
  import { FetcherService } from './FetcherService';
@@ -17,12 +16,13 @@ import { CursoredData } from '../models/CursoredData';
17
16
  */
18
17
  export class TweetService extends FetcherService {
19
18
  /**
20
- * @param cred - The credentials to use for authenticating against Twitter API.
19
+ * @param apiKey - The apiKey (cookie) to use for authenticating Rettiwt against Twitter API.
20
+ * @param proxyUrl - Optional URL with proxy configuration to use for requests to Twitter API.
21
21
  *
22
22
  * @internal
23
23
  */
24
- constructor(cred: AuthCredential) {
25
- super(cred);
24
+ constructor(apiKey: string, proxyUrl?: URL) {
25
+ super(apiKey, proxyUrl);
26
26
  }
27
27
 
28
28
  /**
@@ -1,6 +1,5 @@
1
1
  // PACKAGES
2
2
  import { EResourceType } from 'rettiwt-core';
3
- import { AuthCredential } from 'rettiwt-auth';
4
3
 
5
4
  // SERVICES
6
5
  import { FetcherService } from './FetcherService';
@@ -19,12 +18,13 @@ import { CursoredData } from '../models/CursoredData';
19
18
  */
20
19
  export class UserService extends FetcherService {
21
20
  /**
22
- * @param cred - The credentials to use for authenticating against Twitter API.
21
+ * @param apiKey - The apiKey (cookie) to use for authenticating Rettiwt against Twitter API.
22
+ * @param proxyUrl - Optional URL with proxy configuration to use for requests to Twitter API.
23
23
  *
24
24
  * @internal
25
25
  */
26
- constructor(cred: AuthCredential) {
27
- super(cred);
26
+ constructor(apiKey: string, proxyUrl?: URL) {
27
+ super(apiKey, proxyUrl);
28
28
  }
29
29
 
30
30
  /**
@@ -114,4 +114,27 @@ export class UserService extends FetcherService {
114
114
 
115
115
  return data;
116
116
  }
117
+
118
+ /**
119
+ * Get the timeline of the given user.
120
+ *
121
+ * @param userId - The rest id of the target user.
122
+ * @param count - The number of timeline items to fetch, must be \<= 20.
123
+ * @param cursor - The cursor to the batch of timeline items to fetch.
124
+ * @returns The timeline of the target user.
125
+ *
126
+ * @remarks If the target user has a pinned tweet, the returned timeline has one item extra and this is always the pinned tweet.
127
+ *
128
+ * @public
129
+ */
130
+ async timeline(userId: string, count?: number, cursor?: string): Promise<CursoredData<Tweet>> {
131
+ // Fetching the requested data
132
+ const data = await this.fetch<Tweet>(EResourceType.USER_TWEETS, {
133
+ id: userId,
134
+ count: count,
135
+ cursor: cursor,
136
+ });
137
+
138
+ return data;
139
+ }
117
140
  }
@@ -1,13 +1,3 @@
1
- /**
2
- * The cursor to the batch of data to be fetched.
3
- *
4
- * @public
5
- */
6
- export interface ICursor {
7
- /** The cursor string. */
8
- value: string;
9
- }
10
-
11
1
  /**
12
2
  * The data that us fetched batch-wise along with a cursor.
13
3
  *
@@ -22,3 +12,13 @@ export interface ICursoredData<T> {
22
12
  /** The cursor to the next batch of data. */
23
13
  next: ICursor;
24
14
  }
15
+
16
+ /**
17
+ * The cursor to the batch of data to be fetched.
18
+ *
19
+ * @public
20
+ */
21
+ export interface ICursor {
22
+ /** The cursor string. */
23
+ value: string;
24
+ }