npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

twitter-rest-lite

v0.3.8

Published

Twitter's REST API Lite

Downloads

33

Readme

twitter-rest-lite Build Status

A lite Twitter's API library for Node.js. It has two interfaces: a simple API interface for interacting via GET and POST requests with Twitter's API and an OAuth interface that takes care of authentication related stuff with Twitter's API.

API Interface

Brief

var tlite = require('twitter-rest-lite');
var twitter = new tlite.API(variableWithDevTwitterKeys);
// You could use new tlite(keys) too but you would need to access to object in the form
// 'twitter.api.get' instead of 'twitter.get'.

twitter.get(url, params, callback);
twitter.post(url, data, callback);

API Initialization

The constructor expects to receive the keys in a JSON that will be used to interact with the API, this includes consumer_key, consumer_secret, token and token_secret. The last two can be found as well in the developers website of Twitter for doing requests with the app's credentials.

API.get

The get method expects to receive an URL for the API as first parameter, then the parameters that the URL accepts in a JSON and a callback as third parameters with the regular «Error first, response after».

This is an example of how it would look with a call to URL https://api.twitter.com/1.1/statuses/mentions_timeline.json:

twitter.get('/statuses/mentions_timeline.json', {
  count: 100
}, function (err, response) {
  // do whatever you want
});

API.post

The post method expects to receive an URL for the API as first parameter, then the data (at the moment only JSON) to be sent and a callback as third paramenter with the regular «Error first, response after».

This is an example of how it would look with a call to the URL https://api.twitter.com/1.1/statuses/update.json:

twitter.post('/statuses/update.json', {
  status: 'I\'m tweeting!'
}, function (err, response) {
  // do whatever you want
});

Testing

In order to get full testing done (with gulp test-all), first create the file test/config.json with the following format:

{
  "consumer_key": "Your credential from Twitter's Developer Interface",
  "consumer_secret": "Your credential from Twitter's Developer Interface",
  "token": "Your credential from Twitter's Developer Interface",
  "token_secret": "Your credential from Twitter's Developer Interface",
  "callback": "Either your callback or 'oob' if is a desktop app"
}

Now run:

gulp test-all

Known Issues

  • There's no testing unit for OAuth.proto.accessToken but the example uses it.

Using

var tlite = require('twitter-rest-lite');

var keys = { consumer_key: 'blahblahblah', consumer_secret: 'blahblahblah', callback: '...' };

var tt = new Twitter(keys);

// Just Twitter's OAuth REST interface
var TwitterOAuth = new Twitter.OAuth(keys);

// Using API module required 'token' and 'token_secret' on 'keys'.
keys['token'] = '...';
keys['token_secret'] = '...';

// Just Twitter's basic GET/POST interface
var twitter = new Twitter.API(keys);

twitter.get('/statuses/mentions_timeline.json', params, function(err, response) {
  ...
});

Documentation

http://ghostbar.github.io/twitter-rest-lite and/or docs/ and/or the code itself. It's the same documentation.

License and author

© 2013-2014, Jose Luis Rivas <[email protected]>.

Licensed under the MIT terms. A copy of the license is on the file LICENSE.