Skip to content

Commit 34a9dd6

Browse files
committed
First version of the client, with a bearer token
1 parent a2f12dd commit 34a9dd6

File tree

6 files changed

+39
-7
lines changed

6 files changed

+39
-7
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Built js file
2+
dist/
3+
14
# Logs
25
logs
36
*.log

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ They caused me some frustration:
1919

2020
## Goals:
2121

22-
- [ ] bearer token auth
22+
- [x] bearer token auth
2323
- [ ] token auth
2424
- [ ] link auth
2525
- [ ] read/write/DM aware typing

package-lock.json

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
{
2-
"name": "y",
2+
"name": "twitter-api-v2",
33
"version": "0.1.0",
44
"description": "Twitter api v1 and v2 client for node",
5-
"main": "index.js",
5+
"main": "dist/index.js",
66
"scripts": {
7+
"build": "tsc",
78
"test": "echo \"Error: no test specified\" && exit 1"
89
},
910
"repository": "github:plhery/node-twitter-api",
1011
"author": "Paul-Louis Hery <paullouis.hery+twitterapi@gmail.com> (https://twitter.com/plhery)",
1112
"license": "Apache-2.0",
1213
"devDependencies": {
14+
"@types/node": "^14.6.4",
1315
"typescript": "^4.0.2"
1416
},
1517
"bugs": {
16-
"url" : "https://github.com/plhery/node-twitter-api/issues"
18+
"url": "https://github.com/plhery/node-twitter-api/issues"
1719
}
1820
}

src/index.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { request } from 'http'
2+
3+
export default class TwitterApi {
4+
private _bearerToken;
5+
6+
constructor(bearerToken: string) {
7+
this._bearerToken = bearerToken;
8+
}
9+
10+
public get(url: string) {
11+
const req = request(url, {headers: {authorization: this._bearerToken}});
12+
13+
let response = '';
14+
req.on('data', chunk => response += chunk);
15+
16+
return new Promise((resolve, reject) => {
17+
req.on('error', (e) => reject(e));
18+
req.on('end', () => resolve(JSON.parse(response)));
19+
});
20+
}
21+
}

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
1515
// "sourceMap": true, /* Generates corresponding '.map' file. */
1616
// "outFile": "./", /* Concatenate and emit output to single file. */
17-
// "outDir": "./", /* Redirect output structure to the directory. */
18-
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
17+
"outDir": "dist", /* Redirect output structure to the directory. */
18+
"rootDir": "src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
1919
// "composite": true, /* Enable project compilation */
2020
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
2121
// "removeComments": true, /* Do not emit comments to output. */

0 commit comments

Comments
 (0)