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.51 #44

Merged
merged 3 commits into from
Oct 2, 2022
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twitter-api-sdk",
"version": "1.1.0",
"version": "1.2.0",
"description": "A TypeScript SDK for the Twitter API",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
18 changes: 10 additions & 8 deletions src/OAuth2User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export interface OAuth2UserOptions {
scopes: OAuth2Scopes[];
/** Overwrite request options for all endpoints */
request_options?: Partial<RequestOptions>;
/** Set the auth token */
token?: Token;
}

export type GenerateAuthUrlOptions =
Expand Down Expand Up @@ -88,17 +90,17 @@ interface GetTokenResponse {
scope?: string;
}

interface Token extends Omit<GetTokenResponse, 'expires_in'> {
interface Token extends Omit<GetTokenResponse, "expires_in"> {
/** Date that the access_token will expire at. */
expires_at?: Date;
expires_at?: number;
}

function processTokenResponse(token: GetTokenResponse): Token {
const { expires_in, ...rest } = token;
return {
...rest,
...(!!expires_in && {
expires_at: new Date(Date.now() + expires_in * 1000),
expires_at: Date.now() + expires_in * 1000,
}),
};
}
Expand All @@ -112,7 +114,9 @@ export class OAuth2User implements AuthClient {
#code_verifier?: string;
#code_challenge?: string;
constructor(options: OAuth2UserOptions) {
this.#options = options;
const { token, ...defaultOptions } = options;
this.#options = defaultOptions;
this.token = token;
}

/**
Expand Down Expand Up @@ -155,10 +159,8 @@ export class OAuth2User implements AuthClient {
isAccessTokenExpired(): boolean {
const refresh_token = this.token?.refresh_token;
const expires_at = this.token?.expires_at;
return (
!!refresh_token &&
(!expires_at || expires_at <= new Date(Date.now() + 1000))
);
if (!expires_at) return true;
return !!refresh_token && expires_at <= Date.now() + 1000;
}

/**
Expand Down
96 changes: 92 additions & 4 deletions src/gen/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ import {
spaceTweets,
findTweetsById,
createTweet,
getTweetsComplianceStream,
tweetCountsFullArchiveSearch,
tweetCountsRecentSearch,
getTweetsFirehoseStream,
sampleStream,
getTweetsSample10Stream,
tweetsFullarchiveSearch,
tweetsRecentSearch,
searchStream,
Expand All @@ -55,6 +58,7 @@ import {
findUsersById,
findUsersByUsername,
findUserByUsername,
getUsersComplianceStream,
findMyUser,
findUserById,
usersIdBlocking,
Expand Down Expand Up @@ -103,8 +107,8 @@ export class Client {
auth: string | AuthClient,
requestOptions?: Partial<RequestOptions>
) {
this.version = "1.1.0";
this.twitterApiOpenApiVersion = "2.45";
this.version = "1.2.0";
this.twitterApiOpenApiVersion = "2.51";
this.#auth = typeof auth === "string" ? new OAuth2Bearer(auth) : auth;
this.#defaultRequestOptions = {
...requestOptions,
Expand Down Expand Up @@ -265,6 +269,48 @@ export class Client {
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",
}),

/**
* 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
Expand Down Expand Up @@ -875,6 +921,27 @@ export class Client {
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
*
Expand All @@ -896,6 +963,27 @@ export class Client {
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>>({
auth: this.#auth,
...this.#defaultRequestOptions,
...request_options,
endpoint: `/2/tweets/sample10/stream`,
params,
method: "GET",
}),

/**
* Full-archive search
*
Expand Down Expand Up @@ -1532,10 +1620,10 @@ export class Client {
}),

/**
* Returns User objects that follow a List by the provided User ID
* Followers by User ID
*

* Returns a list of Users that follow the provided User ID
* Returns a list of Users who are followers of the specified User ID.
* @param id - The ID of the User to lookup.
* @param params - The params for usersIdFollowers
* @param request_options - Customize the options for this request
Expand Down
Loading