A light Twitter API wrapper that makes use of native promises. Works for both the User and Application only workflows.
$ npm i twitterer.js
Application:
const { Application } = require('twitterer.js')
const app = new Application({
consumerKey: '-',
consumerSecret: '-',
accessToken: '-' // Optional
})
As Twitter does not expire access tokens, you can provide one at instance creation. If you do so, the application won't have to go through the extra authentication step. Likewise, if you provide the access token, there is no need to provide the first 2 keys.
After creation, you may use the helper methods get
, post
and delete
to hit the endpoints
exposed by the Twitter API.
app.get('search/tweets', { params: { q: 'stuff' } }).then(console.log)
User:
const { User } = require('twitterer.js')
const user = new User({
consumerKey: '-',
consumerSecret: '-',
accessToken: '-',
accessTokenSecret: '-'
})
In this case, all keys are required.
user.get('account/settings').then(console.log)
We have used Axios as our HTTP client, so the request API
is directly inherited from it. You can specify any of the configuration fields offered by Axios, however, some of them, such as the Authorization
header,
will be overwritten.
The User class offers access to the stream endpoints as follows:
user.stream('statuses/filter', { params: { track: 'stuff' } }).then(stream => {
stream.on('tweet', console.log)
})
This hasn't been tested much and is subject to changes.
This a very early build of this package, so issues/PRs are most welcome.