File tree Expand file tree Collapse file tree 2 files changed +38
-3
lines changed Expand file tree Collapse file tree 2 files changed +38
-3
lines changed Original file line number Diff line number Diff line change 11import * as i from 'twitter-openapi-typescript-generated' ;
22import { DefaultFlag } from '@/types' ;
3+ import { RequestParamDefault } from '@/models' ;
34
45export type ProfileSpotlightsQueryParam = {
56 screenName : string ;
6- extraParam : {
7- [ key : string ] : any ;
8- } ;
7+ extraParam ?: { [ key : string ] : any } ;
98} ;
109
1110export class DefaultApiUtils {
@@ -16,4 +15,27 @@ export class DefaultApiUtils {
1615 this . api = api ;
1716 this . flag = flag ;
1817 }
18+
19+ async request < T > ( param : RequestParamDefault < T > ) : Promise < T > {
20+ const apiFn : typeof param . apiFn = param . apiFn . bind ( this . api ) ;
21+ const response = await apiFn ( {
22+ queryId : this . flag [ param . key ] [ 'queryId' ] ,
23+ variables : JSON . stringify ( { ...this . flag [ param . key ] [ 'variables' ] , ...param } ) ,
24+ features : JSON . stringify ( this . flag [ param . key ] [ 'features' ] ) ,
25+ } ) ;
26+ return response . value ( ) as T ;
27+ }
28+
29+ async gettProfileSpotlightsQuery ( param : ProfileSpotlightsQueryParam ) : Promise < i . UserResultByScreenName > {
30+ const args = {
31+ screenName : param . screenName ,
32+ ...param . extraParam ,
33+ } ;
34+ const response = this . request ( {
35+ key : 'ProfileSpotlightsQuery' ,
36+ apiFn : this . api . getProfileSpotlightsQueryRaw ,
37+ param : args ,
38+ } ) ;
39+ return ( await response ) . data . userResultByScreenName ;
40+ }
1941}
Original file line number Diff line number Diff line change 1+ import { getClient , logger } from '@test/init' ;
2+ import { printTweet } from '@test/util' ;
3+
4+ test ( 'gettProfileSpotlightsQuery' , async ( ) => {
5+ logger . log ( 'gettProfileSpotlightsQuery' ) ;
6+ const client = await getClient ( ) ;
7+ const response = await client . getDefaultApi ( ) . gettProfileSpotlightsQuery ( { screenName : 'elonmusk' } ) ;
8+ const legacy = response . result . legacy ;
9+ logger . log ( legacy . screenName ) ;
10+ logger . log ( `followedBy: ${ legacy . followedBy } following: ${ legacy . following } ` ) ;
11+ logger . log ( '┄' . repeat ( 50 ) ) ;
12+ expect ( 0 ) . toBe ( 0 ) ;
13+ } ) ;
You can’t perform that action at this time.
0 commit comments