Skip to content

Commit 10054a0

Browse files
committed
add generator
1 parent 0d4954c commit 10054a0

10 files changed

+600
-11
lines changed

README.md

+54-2
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,21 @@ You can see various examples on how to use the authentication in [examples/](exa
106106

107107
## Getting Started
108108

109-
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).
109+
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.
110110

111-
### Creating an Auth Client
111+
### Creating an public Auth Client
112112

113+
```typescript
114+
const authClient = new auth.OAuth2User({
115+
client_id: process.env.CLIENT_ID,
116+
callback: "http://127.0.0.1:3000/callback",
117+
scopes: ["tweet.read", "users.read", "offline.access"],
118+
});
119+
120+
const client = new Client(authClient);
121+
```
122+
123+
### Creating an confidential Auth Client
113124
```typescript
114125
const authClient = new auth.OAuth2User({
115126
client_id: process.env.CLIENT_ID,
@@ -121,6 +132,7 @@ const authClient = new auth.OAuth2User({
121132
const client = new Client(authClient);
122133
```
123134

135+
124136
### Generating an Authentication URL
125137

126138
```typescript
@@ -142,3 +154,43 @@ await authClient.requestAccessToken(code);
142154
```typescript
143155
const response = await authClient.revokeAccessToken();
144156
```
157+
158+
## Contributing
159+
160+
Note this is only for developers who want to contribute code to the SDK
161+
162+
163+
### Clone the Repository
164+
165+
```
166+
git clone https://github.com/twitterdev/twitter-api-typescript-sdk
167+
```
168+
169+
### Running the generation script
170+
171+
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
172+
173+
```
174+
yarn generate 1.0.0
175+
```
176+
177+
Generating the SDK with a local OpenAPI specification file.
178+
179+
```
180+
yarn generate 1.0.0 --specFile ~/path/to/file/openapi.json
181+
```
182+
183+
The files generated are put in the [src/gen](src/gen) directory, these files are not edited manually.
184+
185+
### Building
186+
187+
```
188+
yarn build
189+
```
190+
191+
### Testing
192+
193+
```
194+
yarn test
195+
```
196+

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "twitter-api-sdk",
3-
"version": "1.0.9",
3+
"version": "1.1.0",
44
"description": "A TypeScript SDK for the Twitter API",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -10,6 +10,7 @@
1010
"scripts": {
1111
"build": "tsc",
1212
"prebuild": "yarn clean",
13+
"generate": "ts-node scripts/generate.ts",
1314
"prepublishOnly": "yarn test",
1415
"build:watch": "tsc --watch",
1516
"test": "jest",
@@ -23,11 +24,14 @@
2324
"node": ">=14"
2425
},
2526
"devDependencies": {
27+
"@apidevtools/json-schema-ref-parser": "^9.0.9",
2628
"@types/jest": "^27.4.1",
2729
"@types/node-fetch": "^2.6.1",
2830
"jest": "^27.5.1",
2931
"nock": "^13.2.4",
32+
"openapi-typescript": "^5.4.0",
3033
"ts-jest": "^27.0.3",
34+
"ts-node": "^10.8.2",
3135
"typescript": "^4.4.4"
3236
},
3337
"jest": {

0 commit comments

Comments
 (0)