Comparing version 1.0.0 to 2.0.0
@@ -9,4 +9,2 @@ import { AxiosResponse } from 'axios'; | ||
export declare class TwitterClient { | ||
baseUrl: string; | ||
creds: TwitterCredentials; | ||
constructor(creds: TwitterCredentials); | ||
@@ -13,0 +11,0 @@ get(api: string): Promise<AxiosResponse>; |
16
index.js
@@ -6,10 +6,9 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TwitterClient = void 0; | ||
var crypto_1 = __importDefault(require("crypto")); | ||
var oauth_1_0a_1 = __importDefault(require("oauth-1.0a")); | ||
var axios_1 = __importDefault(require("axios")); | ||
axios_1.default.defaults.baseURL = 'https://api.twitter.com/'; | ||
var TwitterClient = /** @class */ (function () { | ||
function TwitterClient(creds) { | ||
var _this = this; | ||
this.baseUrl = 'https://api.twitter.com/'; | ||
this.creds = creds; | ||
var oauth = new oauth_1_0a_1.default({ | ||
@@ -23,2 +22,5 @@ consumer: { | ||
return crypto_1.default.createHmac('sha1', key).update(baseString).digest('base64'); | ||
}, | ||
body_hash_function: function (data) { | ||
return crypto_1.default.createHash('sha1').update(data).digest('base64'); | ||
} | ||
@@ -30,10 +32,10 @@ }); | ||
method: config.method || 'GET', | ||
data: config.data | ||
data: config.data, | ||
includeBodyHash: true | ||
}, { | ||
key: _this.creds.accessToken || '', | ||
secret: _this.creds.accessTokenSecret || '' | ||
key: creds.accessToken || '', | ||
secret: creds.accessTokenSecret || '' | ||
})); | ||
return config; | ||
}); | ||
axios_1.default.defaults.baseURL = this.baseUrl; | ||
} | ||
@@ -40,0 +42,0 @@ TwitterClient.prototype.get = function (api) { |
{ | ||
"name": "twttr", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Minimal Twitter API client", | ||
@@ -11,12 +11,13 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@types/node": "^13.11.0", | ||
"@typescript-eslint/eslint-plugin": "^2.26.0", | ||
"@typescript-eslint/parser": "^2.26.0", | ||
"eslint": "^6.8.0", | ||
"jest": "^25.2.7", | ||
"ts-jest": "^25.3.1", | ||
"typescript": "^3.8.3" | ||
"@types/node": "^14.0.14", | ||
"@typescript-eslint/eslint-plugin": "^3.5.0", | ||
"@typescript-eslint/parser": "^3.5.0", | ||
"eslint": "^7.4.0", | ||
"jest": "^26.1.0", | ||
"ts-jest": "^26.1.1", | ||
"typescript": "^3.9.6" | ||
}, | ||
"scripts": { | ||
"build": "eslint index.ts && tsc", | ||
"prebuild": "eslint index.ts", | ||
"build": "tsc", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
@@ -23,0 +24,0 @@ }, |
# twttr | ||
Minimal Twitter API client | ||
Based on the [twine](https://github.com/pofallon/twine) sample created in the [Building Command Line Applications in Node.js](https://www.pluralsight.com/courses/node-js-building-command-line-app) Pluralsight course. | ||
Based on the [twine](https://github.com/pofallon/twine) sample created in the [Building Command Line Applications in Node.js](https://www.pluralsight.com/courses/node-js-building-command-line-app) Pluralsight course. | ||
## Usage | ||
Install with `npm install --save twttr` then: | ||
``` | ||
const { TwitterClient } = require('twttr') | ||
const t = new TwitterClient({ | ||
consumerKey: 'abc123', | ||
consumerSecret: 'abc123', | ||
accessToken: 'abc123', | ||
accessTokenSecret: 'abc123' | ||
}) | ||
t.get('1.1/account_activity/all/webhooks.json') | ||
.then(results => console.log(JSON.stringify(results.data,null,4))) | ||
.catch(error => console.log(error)) | ||
``` |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
5276
23
0