twitterer.js

0.0.6 • Public • Published

twitterer.js

A light Twitter API wrapper that makes use of native promises. Works for both the User and Application only workflows.

Instalation

$ npm i twitterer.js

Usage

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)

Making requests

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.

Stream API

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.

Contributing

This a very early build of this package, so issues/PRs are most welcome.

Package Sidebar

Install

npm i twitterer.js

Weekly Downloads

3

Version

0.0.6

License

Apache-2.0

Last publish

Collaborators

  • fog_yamato
  • teeseal