Skip to content

Commit d6ff320

Browse files
authored
add community and searchCommunities endpoints (#561)
1 parent 869a7c8 commit d6ff320

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

src/types/v2/community.v2.types.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export interface CommunityV2 {
2+
id: string;
3+
name: string;
4+
created_at: string;
5+
}
6+
7+
export interface CommunityErrorV2 {
8+
title: string;
9+
type: string;
10+
detail?: string;
11+
status?: number;
12+
}
13+
14+
export interface CommunityV2Result {
15+
data: CommunityV2;
16+
errors?: CommunityErrorV2[];
17+
}
18+
19+
export interface CommunitiesV2Result {
20+
data: CommunityV2[];
21+
errors?: CommunityErrorV2[];
22+
meta: {next_token?: string};
23+
}
24+
25+
export interface CommunityByIDV2Params {
26+
id: string;
27+
}
28+
29+
export interface CommunitySearchV2Params {
30+
query: string;
31+
max_results?: number;
32+
next_token?: string;
33+
pagination_token?: string;
34+
}

src/types/v2/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './tweet.definition.v2';
44
export * from './user.v2.types';
55
export * from './spaces.v2.types';
66
export * from './list.v2.types';
7+
export * from './community.v2.types';

src/v2/client.v2.read.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ import {
5656
TweetV2HomeTimelineResult,
5757
TweetUsageV2Params,
5858
TweetV2UsageResult,
59+
CommunityV2Result,
60+
CommunitiesV2Result,
61+
CommunityByIDV2Params,
62+
CommunitySearchV2Params,
5963
} from '../types';
6064
import {
6165
TweetSearchAllV2Paginator,
@@ -875,4 +879,20 @@ export default class TwitterApiv2ReadOnly extends TwitterApiSubClient {
875879
public async usage(options: Partial<TweetUsageV2Params> = {}) {
876880
return this.get<TweetV2UsageResult>('usage/tweets', options);
877881
}
882+
883+
/**
884+
* Returns a variety of information about a single Community specified by ID.
885+
* https://docs.x.com/x-api/communities/communities-lookup-by-community-id
886+
*/
887+
public community(communityId: string, options: Partial<CommunityByIDV2Params> = {}) {
888+
return this.get<CommunityV2Result>('communities/:id', options, { params: { id: communityId } });
889+
}
890+
891+
/**
892+
* Search for Communities based on keywords.
893+
* https://docs.x.com/x-api/communities/search-communities
894+
*/
895+
public searchCommunities(query: string, options: Partial<CommunitySearchV2Params> = {}) {
896+
return this.get<CommunitiesV2Result>('communities/search', { query, ...options });
897+
}
878898
}

0 commit comments

Comments
 (0)