Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openapi 2.55 update #51

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twitter-api-sdk",
"version": "1.2.1",
"version": "1.3.0",
"description": "A TypeScript SDK for the Twitter API",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -29,9 +29,9 @@
"@types/node-fetch": "^2.6.1",
"jest": "^27.5.1",
"nock": "^13.2.4",
"openapi-typescript": "^5.4.0",
"openapi-typescript": "^5.4.1",
"ts-jest": "^27.0.3",
"ts-node": "^10.8.2",
"ts-node": "^10.9.1",
"typescript": "^4.4.4"
},
"jest": {
Expand Down
12 changes: 10 additions & 2 deletions scripts/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ function importTypes(operationIds: string[]) {
return output;
}

function convertTag(tag: string) {
const [fst, ...rest] = tag.toLowerCase().split(" ");
return (
fst.toLowerCase() +
rest.map((x) => x.charAt(0).toUpperCase() + x.slice(1)).join("")
);
}

function functionDocs(
summary?: string,
description?: string,
Expand Down Expand Up @@ -193,7 +201,7 @@ export async function generate(): Promise<void> {
const { paths, tags } = spec;

const classes = tags.reduce((prev: any, next: { name: string }) => {
const name = next.name.toLowerCase();
const name = convertTag(next.name);
return {
...prev,
[name]: { functions: [], ...next },
Expand Down Expand Up @@ -254,7 +262,7 @@ import { OAuth2Bearer } from "../auth";\n\n`;
operationIds.push(operationId);

if (!tags?.length) throw "No tags found";
const tag = tags[0].toLowerCase();
const tag = convertTag(tags[0]);
classes[tag].functions.push(
functionDocs(
summary,
Expand Down
157 changes: 155 additions & 2 deletions src/gen/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import {
listBatchComplianceJobs,
createBatchComplianceJob,
getBatchComplianceJob,
dmConversationIdCreate,
getDmConversationsWithParticipantIdDmEvents,
dmConversationWithUserEventIdCreate,
dmConversationByIdEventIdCreate,
getDmConversationsIdDmEvents,
getDmEvents,
listIdCreate,
listIdDelete,
listIdGet,
Expand Down Expand Up @@ -108,8 +114,8 @@ export class Client {
auth: string | AuthClient,
requestOptions?: Partial<RequestOptions>
) {
this.version = "1.2.1";
this.twitterApiOpenApiVersion = "2.54";
this.version = "1.3.0";
this.twitterApiOpenApiVersion = "2.55";
this.#auth = typeof auth === "string" ? new OAuth2Bearer(auth) : auth;
this.#defaultRequestOptions = {
...requestOptions,
Expand Down Expand Up @@ -334,6 +340,153 @@ export class Client {
method: "GET",
}),
};
/**
* Direct Messages
*
* Endpoints related to retrieving, managing Direct Messages
*
* Find out more
* https://developer.twitter.com/en/docs/twitter-api/direct-messages
*/
public readonly directMessages = {
/**
* Create a new DM Conversation
*

* Creates a new DM Conversation.
* @param request_body - The request_body for dmConversationIdCreate
* @param request_options - Customize the options for this request
*/
dmConversationIdCreate: (
request_body: TwitterBody<dmConversationIdCreate>,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<dmConversationIdCreate>> =>
rest<TwitterResponse<dmConversationIdCreate>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/dm_conversations`,
request_body,
method: "POST",
}),

/**
* Get DM Events for a DM Conversation
*

* Returns DM Events for a DM Conversation
* @param participant_id - The ID of the participant user for the One to One DM conversation.
* @param params - The params for getDmConversationsWithParticipantIdDmEvents
* @param request_options - Customize the options for this request
*/
getDmConversationsWithParticipantIdDmEvents: (
participant_id: string,
params: TwitterParams<getDmConversationsWithParticipantIdDmEvents> = {},
request_options?: Partial<RequestOptions>
): TwitterPaginatedResponse<
TwitterResponse<getDmConversationsWithParticipantIdDmEvents>
> =>
paginate<TwitterResponse<getDmConversationsWithParticipantIdDmEvents>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/dm_conversations/with/${participant_id}/dm_events`,
params,
method: "GET",
}),

/**
* Send a new message to a user
*

* Creates a new message for a DM Conversation with a participant user by ID
* @param participant_id - The ID of the recipient user that will receive the DM.
* @param request_body - The request_body for dmConversationWithUserEventIdCreate
* @param request_options - Customize the options for this request
*/
dmConversationWithUserEventIdCreate: (
participant_id: string,
request_body: TwitterBody<dmConversationWithUserEventIdCreate>,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<dmConversationWithUserEventIdCreate>> =>
rest<TwitterResponse<dmConversationWithUserEventIdCreate>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/dm_conversations/with/${participant_id}/messages`,
request_body,
method: "POST",
}),

/**
* Send a new message to a DM Conversation
*

* Creates a new message for a DM Conversation specified by DM Conversation ID
* @param dm_conversation_id - The DM Conversation ID.
* @param request_body - The request_body for dmConversationByIdEventIdCreate
* @param request_options - Customize the options for this request
*/
dmConversationByIdEventIdCreate: (
dm_conversation_id: string,
request_body: TwitterBody<dmConversationByIdEventIdCreate>,
request_options?: Partial<RequestOptions>
): Promise<TwitterResponse<dmConversationByIdEventIdCreate>> =>
rest<TwitterResponse<dmConversationByIdEventIdCreate>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/dm_conversations/${dm_conversation_id}/messages`,
request_body,
method: "POST",
}),

/**
* Get DM Events for a DM Conversation
*

* Returns DM Events for a DM Conversation
* @param id - The DM Conversation ID.
* @param params - The params for getDmConversationsIdDmEvents
* @param request_options - Customize the options for this request
*/
getDmConversationsIdDmEvents: (
id: string,
params: TwitterParams<getDmConversationsIdDmEvents> = {},
request_options?: Partial<RequestOptions>
): TwitterPaginatedResponse<
TwitterResponse<getDmConversationsIdDmEvents>
> =>
paginate<TwitterResponse<getDmConversationsIdDmEvents>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/dm_conversations/${id}/dm_events`,
params,
method: "GET",
}),

/**
* Get recent DM Events
*

* Returns recent DM Events across DM conversations
* @param params - The params for getDmEvents
* @param request_options - Customize the options for this request
*/
getDmEvents: (
params: TwitterParams<getDmEvents> = {},
request_options?: Partial<RequestOptions>
): TwitterPaginatedResponse<TwitterResponse<getDmEvents>> =>
paginate<TwitterResponse<getDmEvents>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/dm_events`,
params,
method: "GET",
}),
};
/**
* General
*
Expand Down
Loading