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

add generator #27

Merged
merged 1 commit into from
Jul 14, 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
56 changes: 54 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,21 @@ You can see various examples on how to use the authentication in [examples/](exa

## Getting Started

Make sure you to turn on OAuth2 in your apps user authentication settings, and set the type of app to be a confidential client (Web App or Automated App or Bot).
Make sure you turn on OAuth2 in your apps user authentication settings, and set the type of app to be either a confidential client or a public client.

### Creating an Auth Client
### Creating an public Auth Client

```typescript
const authClient = new auth.OAuth2User({
client_id: process.env.CLIENT_ID,
callback: "http://127.0.0.1:3000/callback",
scopes: ["tweet.read", "users.read", "offline.access"],
});

const client = new Client(authClient);
```

### Creating an confidential Auth Client
```typescript
const authClient = new auth.OAuth2User({
client_id: process.env.CLIENT_ID,
Expand All @@ -121,6 +132,7 @@ const authClient = new auth.OAuth2User({
const client = new Client(authClient);
```


### Generating an Authentication URL

```typescript
Expand All @@ -142,3 +154,43 @@ await authClient.requestAccessToken(code);
```typescript
const response = await authClient.revokeAccessToken();
```

## Contributing

Note this is only for developers who want to contribute code to the SDK


### Clone the Repository

```
git clone https://github.com/twitterdev/twitter-api-typescript-sdk
```

### Running the generation script

Generating the SDK with the [latest OpenAPI spec](https://api.twitter.com/2/openapi.json). The version is any valid [SemVer](https://semver.org/) version

```
yarn generate 1.0.0
```

Generating the SDK with a local OpenAPI specification file.

```
yarn generate 1.0.0 --specFile ~/path/to/file/openapi.json
```

The files generated are put in the [src/gen](src/gen) directory, these files are not edited manually.

### Building

```
yarn build
```

### Testing

```
yarn test
```

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twitter-api-sdk",
"version": "1.0.9",
"version": "1.1.0",
"description": "A TypeScript SDK for the Twitter API",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -10,6 +10,7 @@
"scripts": {
"build": "tsc",
"prebuild": "yarn clean",
"generate": "ts-node scripts/generate.ts",
"prepublishOnly": "yarn test",
"build:watch": "tsc --watch",
"test": "jest",
Expand All @@ -23,11 +24,14 @@
"node": ">=14"
},
"devDependencies": {
"@apidevtools/json-schema-ref-parser": "^9.0.9",
"@types/jest": "^27.4.1",
"@types/node-fetch": "^2.6.1",
"jest": "^27.5.1",
"nock": "^13.2.4",
"openapi-typescript": "^5.4.0",
"ts-jest": "^27.0.3",
"ts-node": "^10.8.2",
"typescript": "^4.4.4"
},
"jest": {
Expand Down
Loading