-
Notifications
You must be signed in to change notification settings - Fork 93
/
Client.ts
1825 lines (1679 loc) · 57.2 KB
/
Client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2021 Twitter, Inc.
// SPDX-License-Identifier: Apache-2.0
/*
This file is auto-generated
Do not make direct changes to this file
*/
import { rest, stream, paginate, RequestOptions } from "../request";
import {
AuthClient,
TwitterResponse,
TwitterBody,
TwitterParams,
TwitterPaginatedResponse,
} from "../types";
import { OAuth2Bearer } from "../auth";
import {
listBatchComplianceJobs,
createBatchComplianceJob,
getBatchComplianceJob,
listIdCreate,
listIdDelete,
listIdGet,
listIdUpdate,
listGetFollowers,
listGetMembers,
listAddMember,
listRemoveMember,
listsIdTweets,
getOpenApiSpec,
findSpacesByIds,
findSpacesByCreatorIds,
searchSpaces,
findSpaceById,
spaceBuyers,
spaceTweets,
findTweetsById,
createTweet,
getTweetsComplianceStream,
tweetCountsFullArchiveSearch,
tweetCountsRecentSearch,
getTweetsFirehoseStream,
getTweetsLabelStream,
sampleStream,
getTweetsSample10Stream,
tweetsFullarchiveSearch,
tweetsRecentSearch,
searchStream,
getRules,
addOrDeleteRules,
deleteTweetById,
findTweetById,
tweetsIdLikingUsers,
findTweetsThatQuoteATweet,
tweetsIdRetweetingUsers,
hideReplyById,
findUsersById,
findUsersByUsername,
findUserByUsername,
getUsersComplianceStream,
findMyUser,
findUserById,
usersIdBlocking,
usersIdBlock,
getUsersIdBookmarks,
postUsersIdBookmarks,
usersIdBookmarksDelete,
userFollowedLists,
listUserFollow,
listUserUnfollow,
usersIdFollowers,
usersIdFollowing,
usersIdFollow,
usersIdLikedTweets,
usersIdLike,
usersIdUnlike,
getUserListMemberships,
usersIdMentions,
usersIdMuting,
usersIdMute,
listUserOwnedLists,
listUserPinnedLists,
listUserPin,
listUserUnpin,
usersIdRetweets,
usersIdUnretweets,
usersIdTimeline,
usersIdTweets,
usersIdUnblock,
usersIdUnfollow,
usersIdUnmute,
} from "./openapi-types";
/**
* Twitter API TypeScript Client
*
* TypeScript SDK for use with the Twitter API
*
*/
export class Client {
#auth: AuthClient;
#defaultRequestOptions?: Partial<RequestOptions>;
version: string;
twitterApiOpenApiVersion: string;
constructor(
auth: string | AuthClient,
requestOptions?: Partial<RequestOptions>
) {
this.version = "1.2.1";
this.twitterApiOpenApiVersion = "2.54";
this.#auth = typeof auth === "string" ? new OAuth2Bearer(auth) : auth;
this.#defaultRequestOptions = {
...requestOptions,
headers: {
"User-Agent": "twitter-api-typescript-sdk/" + this.version,
...requestOptions?.headers,
},
};
}
/**
* Bookmarks
*
* Endpoints related to retrieving, managing bookmarks of a user
*
* Find out more
* https://developer.twitter.com/en/docs/twitter-api/bookmarks
*/
public readonly bookmarks = {
/**
* Bookmarks by User
*
* Returns Tweet objects that have been bookmarked by the requesting User
* @param id - The ID of the authenticated source User for whom to return results.
* @param params - The params for getUsersIdBookmarks
* @param request_options - Customize the options for this request
*/
getUsersIdBookmarks: (
id: string,
params: TwitterParams<getUsersIdBookmarks> = {},
request_options?: Partial<RequestOptions>
): TwitterPaginatedResponse<TwitterResponse<getUsersIdBookmarks>> =>
paginate<TwitterResponse<getUsersIdBookmarks>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/users/${id}/bookmarks`,
params,
method: "GET",
}),
/**
* Add Tweet to Bookmarks
*
* Adds a Tweet (ID in the body) to the requesting User's (in the path) bookmarks
* @param id - The ID of the authenticated source User for whom to add bookmarks.
* @param request_body - The request_body for postUsersIdBookmarks
* @param request_options - Customize the options for this request
*/
postUsersIdBookmarks: (
id: string,
request_body: TwitterBody<postUsersIdBookmarks>,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<postUsersIdBookmarks>> =>
rest<TwitterResponse<postUsersIdBookmarks>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/users/${id}/bookmarks`,
request_body,
method: "POST",
}),
/**
* Remove a bookmarked Tweet
*
* Removes a Tweet from the requesting User's bookmarked Tweets.
* @param id - The ID of the authenticated source User whose bookmark is to be removed.
* @param tweet_id - The ID of the Tweet that the source User is removing from bookmarks.
* @param request_options - Customize the options for this request
*/
usersIdBookmarksDelete: (
id: string,
tweet_id: string,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<usersIdBookmarksDelete>> =>
rest<TwitterResponse<usersIdBookmarksDelete>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/users/${id}/bookmarks/${tweet_id}`,
method: "DELETE",
}),
};
/**
* Compliance
*
* Endpoints related to keeping Twitter data in your systems compliant
*
* Find out more
* https://developer.twitter.com/en/docs/twitter-api/compliance/batch-tweet/introduction
*/
public readonly compliance = {
/**
* List Compliance Jobs
*
* Returns recent Compliance Jobs for a given job type and optional job status
* @param params - The params for listBatchComplianceJobs
* @param request_options - Customize the options for this request
*/
listBatchComplianceJobs: (
params: TwitterParams<listBatchComplianceJobs>,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<listBatchComplianceJobs>> =>
rest<TwitterResponse<listBatchComplianceJobs>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/compliance/jobs`,
params,
method: "GET",
}),
/**
* Create compliance job
*
* Creates a compliance for the given job type
* @param request_body - The request_body for createBatchComplianceJob
* @param request_options - Customize the options for this request
*/
createBatchComplianceJob: (
request_body: TwitterBody<createBatchComplianceJob>,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<createBatchComplianceJob>> =>
rest<TwitterResponse<createBatchComplianceJob>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/compliance/jobs`,
request_body,
method: "POST",
}),
/**
* Get Compliance Job
*
* Returns a single Compliance Job by ID
* @param id - The ID of the Compliance Job to retrieve.
* @param params - The params for getBatchComplianceJob
* @param request_options - Customize the options for this request
*/
getBatchComplianceJob: (
id: string,
params: TwitterParams<getBatchComplianceJob> = {},
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<getBatchComplianceJob>> =>
rest<TwitterResponse<getBatchComplianceJob>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/compliance/jobs/${id}`,
params,
method: "GET",
}),
/**
* Tweets Compliance stream
*
* Streams 100% of compliance data for Tweets
* @param params - The params for getTweetsComplianceStream
* @param request_options - Customize the options for this request
*/
getTweetsComplianceStream: (
params: TwitterParams<getTweetsComplianceStream>,
request_options?: Partial<RequestOptions>
): AsyncGenerator<TwitterResponse<getTweetsComplianceStream>> =>
stream<TwitterResponse<getTweetsComplianceStream>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/tweets/compliance/stream`,
params,
method: "GET",
}),
/**
* Tweets Label stream
*
* Streams 100% of labeling events applied to Tweets
* @param params - The params for getTweetsLabelStream
* @param request_options - Customize the options for this request
*/
getTweetsLabelStream: (
params: TwitterParams<getTweetsLabelStream> = {},
request_options?: Partial<RequestOptions>
): AsyncGenerator<TwitterResponse<getTweetsLabelStream>> =>
stream<TwitterResponse<getTweetsLabelStream>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/tweets/label/stream`,
params,
method: "GET",
}),
/**
* Users Compliance stream
*
* Streams 100% of compliance data for Users
* @param params - The params for getUsersComplianceStream
* @param request_options - Customize the options for this request
*/
getUsersComplianceStream: (
params: TwitterParams<getUsersComplianceStream>,
request_options?: Partial<RequestOptions>
): AsyncGenerator<TwitterResponse<getUsersComplianceStream>> =>
stream<TwitterResponse<getUsersComplianceStream>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/users/compliance/stream`,
params,
method: "GET",
}),
};
/**
* General
*
* Miscellaneous endpoints for general API functionality
*
* Find out more
* https://developer.twitter.com/en/docs/twitter-api
*/
public readonly general = {
/**
* Returns the OpenAPI Specification document.
*
* Full OpenAPI Specification in JSON format. (See https://github.com/OAI/OpenAPI-Specification/blob/master/README.md)
* @param request_options - Customize the options for this request
*/
getOpenApiSpec: (
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<getOpenApiSpec>> =>
rest<TwitterResponse<getOpenApiSpec>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/openapi.json`,
method: "GET",
}),
};
/**
* Lists
*
* Endpoints related to retrieving, managing Lists
*
* Find out more
* https://developer.twitter.com/en/docs/twitter-api/lists
*/
public readonly lists = {
/**
* Create List
*
* Creates a new List.
* @param request_body - The request_body for listIdCreate
* @param request_options - Customize the options for this request
*/
listIdCreate: (
request_body: TwitterBody<listIdCreate>,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<listIdCreate>> =>
rest<TwitterResponse<listIdCreate>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/lists`,
request_body,
method: "POST",
}),
/**
* Delete List
*
* Delete a List that you own.
* @param id - The ID of the List to delete.
* @param request_options - Customize the options for this request
*/
listIdDelete: (
id: string,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<listIdDelete>> =>
rest<TwitterResponse<listIdDelete>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/lists/${id}`,
method: "DELETE",
}),
/**
* List lookup by List ID.
*
* Returns a List.
* @param id - The ID of the List.
* @param params - The params for listIdGet
* @param request_options - Customize the options for this request
*/
listIdGet: (
id: string,
params: TwitterParams<listIdGet> = {},
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<listIdGet>> =>
rest<TwitterResponse<listIdGet>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/lists/${id}`,
params,
method: "GET",
}),
/**
* Update List.
*
* Update a List that you own.
* @param id - The ID of the List to modify.
* @param request_body - The request_body for listIdUpdate
* @param request_options - Customize the options for this request
*/
listIdUpdate: (
id: string,
request_body: TwitterBody<listIdUpdate>,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<listIdUpdate>> =>
rest<TwitterResponse<listIdUpdate>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/lists/${id}`,
request_body,
method: "PUT",
}),
/**
* Add a List member
*
* Causes a User to become a member of a List.
* @param id - The ID of the List for which to add a member.
* @param request_body - The request_body for listAddMember
* @param request_options - Customize the options for this request
*/
listAddMember: (
id: string,
request_body: TwitterBody<listAddMember>,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<listAddMember>> =>
rest<TwitterResponse<listAddMember>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/lists/${id}/members`,
request_body,
method: "POST",
}),
/**
* Remove a List member
*
* Causes a User to be removed from the members of a List.
* @param id - The ID of the List to remove a member.
* @param user_id - The ID of User that will be removed from the List.
* @param request_options - Customize the options for this request
*/
listRemoveMember: (
id: string,
user_id: string,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<listRemoveMember>> =>
rest<TwitterResponse<listRemoveMember>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/lists/${id}/members/${user_id}`,
method: "DELETE",
}),
/**
* Get User's Followed Lists
*
* Returns a User's followed Lists.
* @param id - The ID of the User to lookup.
* @param params - The params for userFollowedLists
* @param request_options - Customize the options for this request
*/
userFollowedLists: (
id: string,
params: TwitterParams<userFollowedLists> = {},
request_options?: Partial<RequestOptions>
): TwitterPaginatedResponse<TwitterResponse<userFollowedLists>> =>
paginate<TwitterResponse<userFollowedLists>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/users/${id}/followed_lists`,
params,
method: "GET",
}),
/**
* Follow a List
*
* Causes a User to follow a List.
* @param id - The ID of the authenticated source User that will follow the List.
* @param request_body - The request_body for listUserFollow
* @param request_options - Customize the options for this request
*/
listUserFollow: (
id: string,
request_body: TwitterBody<listUserFollow>,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<listUserFollow>> =>
rest<TwitterResponse<listUserFollow>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/users/${id}/followed_lists`,
request_body,
method: "POST",
}),
/**
* Unfollow a List
*
* Causes a User to unfollow a List.
* @param id - The ID of the authenticated source User that will unfollow the List.
* @param list_id - The ID of the List to unfollow.
* @param request_options - Customize the options for this request
*/
listUserUnfollow: (
id: string,
list_id: string,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<listUserUnfollow>> =>
rest<TwitterResponse<listUserUnfollow>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/users/${id}/followed_lists/${list_id}`,
method: "DELETE",
}),
/**
* Get a User's List Memberships
*
* Get a User's List Memberships.
* @param id - The ID of the User to lookup.
* @param params - The params for getUserListMemberships
* @param request_options - Customize the options for this request
*/
getUserListMemberships: (
id: string,
params: TwitterParams<getUserListMemberships> = {},
request_options?: Partial<RequestOptions>
): TwitterPaginatedResponse<TwitterResponse<getUserListMemberships>> =>
paginate<TwitterResponse<getUserListMemberships>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/users/${id}/list_memberships`,
params,
method: "GET",
}),
/**
* Get a User's Owned Lists.
*
* Get a User's Owned Lists.
* @param id - The ID of the User to lookup.
* @param params - The params for listUserOwnedLists
* @param request_options - Customize the options for this request
*/
listUserOwnedLists: (
id: string,
params: TwitterParams<listUserOwnedLists> = {},
request_options?: Partial<RequestOptions>
): TwitterPaginatedResponse<TwitterResponse<listUserOwnedLists>> =>
paginate<TwitterResponse<listUserOwnedLists>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/users/${id}/owned_lists`,
params,
method: "GET",
}),
/**
* Get a User's Pinned Lists
*
* Get a User's Pinned Lists.
* @param id - The ID of the authenticated source User for whom to return results.
* @param params - The params for listUserPinnedLists
* @param request_options - Customize the options for this request
*/
listUserPinnedLists: (
id: string,
params: TwitterParams<listUserPinnedLists> = {},
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<listUserPinnedLists>> =>
rest<TwitterResponse<listUserPinnedLists>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/users/${id}/pinned_lists`,
params,
method: "GET",
}),
/**
* Pin a List
*
* Causes a User to pin a List.
* @param id - The ID of the authenticated source User that will pin the List.
* @param request_body - The request_body for listUserPin
* @param request_options - Customize the options for this request
*/
listUserPin: (
id: string,
request_body: TwitterBody<listUserPin>,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<listUserPin>> =>
rest<TwitterResponse<listUserPin>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/users/${id}/pinned_lists`,
request_body,
method: "POST",
}),
/**
* Unpin a List
*
* Causes a User to remove a pinned List.
* @param id - The ID of the authenticated source User for whom to return results.
* @param list_id - The ID of the List to unpin.
* @param request_options - Customize the options for this request
*/
listUserUnpin: (
id: string,
list_id: string,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<listUserUnpin>> =>
rest<TwitterResponse<listUserUnpin>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/users/${id}/pinned_lists/${list_id}`,
method: "DELETE",
}),
};
/**
* Spaces
*
* Endpoints related to retrieving, managing Spaces
*
* Find out more
* https://developer.twitter.com/en/docs/twitter-api/spaces
*/
public readonly spaces = {
/**
* Space lookup up Space IDs
*
* Returns a variety of information about the Spaces specified by the requested IDs
* @param params - The params for findSpacesByIds
* @param request_options - Customize the options for this request
*/
findSpacesByIds: (
params: TwitterParams<findSpacesByIds>,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<findSpacesByIds>> =>
rest<TwitterResponse<findSpacesByIds>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/spaces`,
params,
method: "GET",
}),
/**
* Space lookup by their creators
*
* Returns a variety of information about the Spaces created by the provided User IDs
* @param params - The params for findSpacesByCreatorIds
* @param request_options - Customize the options for this request
*/
findSpacesByCreatorIds: (
params: TwitterParams<findSpacesByCreatorIds>,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<findSpacesByCreatorIds>> =>
rest<TwitterResponse<findSpacesByCreatorIds>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/spaces/by/creator_ids`,
params,
method: "GET",
}),
/**
* Search for Spaces
*
* Returns Spaces that match the provided query.
* @param params - The params for searchSpaces
* @param request_options - Customize the options for this request
*/
searchSpaces: (
params: TwitterParams<searchSpaces>,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<searchSpaces>> =>
rest<TwitterResponse<searchSpaces>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/spaces/search`,
params,
method: "GET",
}),
/**
* Space lookup by Space ID
*
* Returns a variety of information about the Space specified by the requested ID
* @param id - The ID of the Space to be retrieved.
* @param params - The params for findSpaceById
* @param request_options - Customize the options for this request
*/
findSpaceById: (
id: string,
params: TwitterParams<findSpaceById> = {},
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<findSpaceById>> =>
rest<TwitterResponse<findSpaceById>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/spaces/${id}`,
params,
method: "GET",
}),
/**
* Retrieve the list of Users who purchased a ticket to the given space
*
* Retrieves the list of Users who purchased a ticket to the given space
* @param id - The ID of the Space to be retrieved.
* @param params - The params for spaceBuyers
* @param request_options - Customize the options for this request
*/
spaceBuyers: (
id: string,
params: TwitterParams<spaceBuyers> = {},
request_options?: Partial<RequestOptions>
): TwitterPaginatedResponse<TwitterResponse<spaceBuyers>> =>
paginate<TwitterResponse<spaceBuyers>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/spaces/${id}/buyers`,
params,
method: "GET",
}),
/**
* Retrieve Tweets from a Space.
*
* Retrieves Tweets shared in the specified Space.
* @param id - The ID of the Space to be retrieved.
* @param params - The params for spaceTweets
* @param request_options - Customize the options for this request
*/
spaceTweets: (
id: string,
params: TwitterParams<spaceTweets> = {},
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<spaceTweets>> =>
rest<TwitterResponse<spaceTweets>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/spaces/${id}/tweets`,
params,
method: "GET",
}),
};
/**
* Tweets
*
* Endpoints related to retrieving, searching, and modifying Tweets
*
* Find out more
* https://developer.twitter.com/en/docs/twitter-api/tweets/lookup
*/
public readonly tweets = {
/**
* List Tweets timeline by List ID.
*
* Returns a list of Tweets associated with the provided List ID.
* @param id - The ID of the List.
* @param params - The params for listsIdTweets
* @param request_options - Customize the options for this request
*/
listsIdTweets: (
id: string,
params: TwitterParams<listsIdTweets> = {},
request_options?: Partial<RequestOptions>
): TwitterPaginatedResponse<TwitterResponse<listsIdTweets>> =>
paginate<TwitterResponse<listsIdTweets>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/lists/${id}/tweets`,
params,
method: "GET",
}),
/**
* Tweet lookup by Tweet IDs
*
* Returns a variety of information about the Tweet specified by the requested ID.
* @param params - The params for findTweetsById
* @param request_options - Customize the options for this request
*/
findTweetsById: (
params: TwitterParams<findTweetsById>,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<findTweetsById>> =>
rest<TwitterResponse<findTweetsById>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/tweets`,
params,
method: "GET",
}),
/**
* Creation of a Tweet
*
* Causes the User to create a Tweet under the authorized account.
* @param request_body - The request_body for createTweet
* @param request_options - Customize the options for this request
*/
createTweet: (
request_body: TwitterBody<createTweet>,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<createTweet>> =>
rest<TwitterResponse<createTweet>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/tweets`,
request_body,
method: "POST",
}),
/**
* Full archive search counts
*
* Returns Tweet Counts that match a search query.
* @param params - The params for tweetCountsFullArchiveSearch
* @param request_options - Customize the options for this request
*/
tweetCountsFullArchiveSearch: (
params: TwitterParams<tweetCountsFullArchiveSearch>,
request_options?: Partial<RequestOptions>
): TwitterPaginatedResponse<
TwitterResponse<tweetCountsFullArchiveSearch>
> =>
paginate<TwitterResponse<tweetCountsFullArchiveSearch>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/tweets/counts/all`,
params,
method: "GET",
}),
/**
* Recent search counts
*
* Returns Tweet Counts from the last 7 days that match a search query.
* @param params - The params for tweetCountsRecentSearch
* @param request_options - Customize the options for this request
*/
tweetCountsRecentSearch: (
params: TwitterParams<tweetCountsRecentSearch>,
request_options?: Partial<RequestOptions>
): TwitterPaginatedResponse<TwitterResponse<tweetCountsRecentSearch>> =>
paginate<TwitterResponse<tweetCountsRecentSearch>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/tweets/counts/recent`,
params,
method: "GET",
}),
/**
* Firehose stream
*
* Streams 100% of public Tweets.
* @param params - The params for getTweetsFirehoseStream
* @param request_options - Customize the options for this request
*/
getTweetsFirehoseStream: (
params: TwitterParams<getTweetsFirehoseStream>,
request_options?: Partial<RequestOptions>
): AsyncGenerator<TwitterResponse<getTweetsFirehoseStream>> =>
stream<TwitterResponse<getTweetsFirehoseStream>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/tweets/firehose/stream`,
params,
method: "GET",
}),
/**
* Sample stream
*
* Streams a deterministic 1% of public Tweets.
* @param params - The params for sampleStream
* @param request_options - Customize the options for this request
*/
sampleStream: (
params: TwitterParams<sampleStream> = {},
request_options?: Partial<RequestOptions>
): AsyncGenerator<TwitterResponse<sampleStream>> =>
stream<TwitterResponse<sampleStream>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/tweets/sample/stream`,
params,
method: "GET",
}),
/**
* Sample 10% stream
*
* Streams a deterministic 10% of public Tweets.
* @param params - The params for getTweetsSample10Stream
* @param request_options - Customize the options for this request
*/
getTweetsSample10Stream: (
params: TwitterParams<getTweetsSample10Stream>,
request_options?: Partial<RequestOptions>
): AsyncGenerator<TwitterResponse<getTweetsSample10Stream>> =>
stream<TwitterResponse<getTweetsSample10Stream>>({