Permalink
Browse files

The big shift from twitter-node to node-twitter.

  • Loading branch information...
1 parent d1944db commit 83e82469692a3d0d32c821a2962349a5d02cf910 @jdub jdub committed Oct 17, 2010
Showing with 356 additions and 937 deletions.
  1. +0 −3 .gitignore
  2. +2 −1 LICENSE
  3. +37 −114 README.md
  4. +1 −0 index.js
  5. +302 −239 lib/node-twitter/index.js
  6. +0 −92 lib/node-twitter/math.js
  7. +0 −324 lib/node-twitter/oauth.js
  8. +14 −11 package.json
  9. +0 −153 test/twitter_node_config_test.js
View
@@ -1,3 +0,0 @@
-*build/
-*.lock-wscript
-*.node
View
@@ -1,4 +1,5 @@
-Copyright (c) 2010 rick
+node-twitter: Copyright (c) 2010 Jeff Waugh
+parser.js: Copyright (c) 2010 rick
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
151 README.md
@@ -1,129 +1,52 @@
-# twitter-node
+Asynchronous Twitter client API for node.js
+===========================================
-Creates a streaming connection with twitter, and pushes any incoming statuses to a tweet event.
+`node-twitter` aims to provide a complete, asynchronous client library for Twitter (and other compliant endpoints), including REST, stream and search APIs.
-## Installation
+It was inspired by, and uses some code from, technoweenie's `twitter-node`.
-Depends on ntest.
+## Requirements
-Use NPM:
+- node 0.2+
+- [node-oauth](http://github.com/ciaranj/node-oauth)
- npm install twitter-node
+## Getting started
-Otherwise create a symlink in `~/.node_libraries`
+It's early days for `node-twitter`, so I'm going to assume a fair amount of knowledge for the moment. Better documentation to come as we head towards a stable release.
- $ ln -s /path/to/twitter-node/lib/twitter-node ~/.node_libraries/twitter-node
+### Setup
-## Events
+ var sys = require('sys'), twitter = require('node-twitter');
+ var twit = new twitter({
+ consumer_key: 'STATE YOUR NAME',
+ consumer_secret: 'STATE YOUR NAME',
+ access_token_key: 'STATE YOUR NAME',
+ access_token_secret: 'STATE YOUR NAME'
+ });
-TwitterNode emits these events:
+### REST API
-* tweet(json) - This is emitted when a new tweet comes in. This will be a parsed JSON object.
-* limit(json) - This is emitted when a new limit command comes in. Currently, limit detection only works with parsed JSON objects.
-* delete(json) - This is emitted when a new delete command comes in. Currently, delete detection only works with parsed JSON objects.
-* end(response) - This is emitted when the http connection is closed. The HTTP response object is sent.
+Functions can be chained:
-See the [streaming API docs][api-docs] for examples of the limit and delete commands.
+ twit.verifyCredentials(function (data) {
+ sys.puts(sys.inspect(data));
+ })
+ .updateStatus(
+ { status: 'Test tweet from node-twitter/' + twitter.VERSION },
+ function (data) {
+ sys.puts(sys.inspect(data));
+ }
+ );
-[api-docs]: http://apiwiki.twitter.com/Streaming-API-Documentation
+### Streaming API
-## Usage
+ twit.stream('user', {track:'nodejs', function(stream) {
+ stream.on('data', function (data) {
+ sys.puts(sys.inspect(data));
+ });
+ });
- // twitter-node does not modify GLOBAL, that's so rude
- var TwitterNode = require('twitter-node').TwitterNode
- , sys = require('sys')
+## Contributors
- // you can pass args to create() or set them on the TwitterNode instance
- var twit = new TwitterNode({
- user: 'username',
- password: 'password',
- track: ['baseball', 'football'], // sports!
- follow: [12345, 67890], // follow these random users
- locations: [-122.75, 36.8, -121.75, 37.8] // tweets in SF
- });
-
- // adds to the track array set above
- twit.track('foosball');
-
- // adds to the following array set above
- twit.follow(2345);
-
- // follow tweets from NYC
- twit.location(-74, 40, -73, 41)
-
- // http://apiwiki.twitter.com/Streaming-API-Documentation#QueryParameters
- twit.params['count'] = 100;
-
- // http://apiwiki.twitter.com/Streaming-API-Documentation#Methods
- twit.action = 'sample'; // 'filter' is default
-
- twit.headers['User-Agent'] = 'whatever';
-
- // Make sure you listen for errors, otherwise
- // they are thrown
- twit.addListener('error', function(error) {
- console.log(error.message);
- });
-
- twit
- .addListener('tweet', function(tweet) {
- sys.puts("@" + tweet.user.screen_name + ": " + tweet.text);
- })
-
- .addListener('limit', function(limit) {
- sys.puts("LIMIT: " + sys.inspect(limit));
- })
-
- .addListener('delete', function(del) {
- sys.puts("DELETE: " + sys.inspect(del));
- })
-
- .addListener('end', function(resp) {
- sys.puts("wave goodbye... " + resp.statusCode);
- })
-
- .stream();
-
- // We can also add things to track on-the-fly
- twit.track('#nowplaying');
- twit.follow(1234);
-
- // This will reset the stream
- twit.stream();
-
-## Pre-Launch Checklist
-
-See http://apiwiki.twitter.com/Streaming-API-Documentation. Keep these points in mind when getting ready to use TwitterNode in production:
-
-* Not purposefully attempting to circumvent access limits and levels?
-* Creating the minimal number of connections?
-* Avoiding duplicate logins?
-* Backing off from failures: none for first disconnect, seconds for repeated network (TCP/IP) level issues, minutes for repeated HTTP (4XX codes)?
-* Using long-lived connections?
-* Tolerant of other objects and newlines in markup stream? (Non <status> objects...)
-* Tolerant of duplicate messages?
-
-## TODO
-
-* Handle failures as recommended from the Twitter stream documentation.
-
-## \m/
-
-* Tim Smart
-* Matt Secoske (secos)
-* kompozer
-* Twitter
-
-## Note on Patches/Pull Requests
-
-* Fork the project.
-* Make your feature addition or bug fix.
-* Add tests for it. This is important so I don't break it in a
- future version unintentionally.
-* Commit, do not mess with version or history.
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-* Send me a pull request. Bonus points for topic branches.
-
-## Copyright
-
-Copyright (c) 2010 rick. See LICENSE for details.
+- [Jeff Waugh](http://github.com/jdub) (author)
+- [rick](http://github.com/technoweenie) (parser.js)
View
@@ -0,0 +1 @@
+module.exports = require('./lib/node-twitter');
Oops, something went wrong.

0 comments on commit 83e8246

Please sign in to comment.