Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
demian85 committed May 27, 2012
1 parent 1df59bc commit 3a050d2
Showing 1 changed file with 50 additions and 19 deletions.
69 changes: 50 additions & 19 deletions README.md
Original file line number Original file line Diff line number Diff line change
@@ -1,18 +1,60 @@
gnip gnip
==== ====


Connect to Gnip streaming API and manage rules. Connect to Gnip streaming API and manage rules.
You must have a Gnip account with any data source available, like Twitter Power Track.


JSON is the only supported stream format, so you must enable data normalization in your admin panel. Currenly, this module only supports JSON activity stream format, so you must enable data normalization in your admin panel.

# Gnip.Stream
This class is an EventEmitter and allows you to connect to the stream and start receiving data.

## API methods

#### stream.start()
Connect to the stream and start receiving data. At this point you should have registered at least one event listener for any of these events: 'data', 'object' or 'tweet'.

#### stream.end()
Terminates the connection.

## Events

###### ready
###### data
###### error
###### object
###### tweet
###### delete
###### end

# Gnip.Rules
This class allows you to manage an unlimited number of tracking rules.

## API methods

#### rules.getAll(Function callback)
Get cached rules.

#### rules.update(Array rules, Function callback)
Creates or replaces the live tracking rules.
Rules are sent in batches of 5000 (API limit), so you can pass an unlimited number of rules.
The current tracking rules are stored in a local JSON file so you can update the existing rules efficiently without having to remove them all. The current tracking rules are stored in a local JSON file so you can update the existing rules efficiently without having to remove them all.


**The following methods uses Gnip API directly and ignores the local cache. Avoid when possible.**
#### rules.live.update(Array rules, Function callback)
#### rules.live.add(Array rules, Function callback)
#### rules.live.remove(Array rules, Function callback)
#### rules.live.getAll(Function callback)
#### rules.live.removeAll(Function callback)


Example Usage Example Usage
==== ====
var Gnip = require('gnip'); var Gnip = require('gnip');


var stream = new Gnip.Stream({ var stream = new Gnip.Stream({
url : 'https://stream.gnip.com:443/accounts/xxx/publishers/twitter/streams/track/prod.json', url : 'https://stream.gnip.com:443/accounts/xxx/publishers/twitter/streams/track/prod.json',
username : 'xxx', user : 'xxx',
password : 'xxx' password : 'xxx'
}); });
stream.on('ready', function() { stream.on('ready', function() {
Expand All @@ -25,26 +67,15 @@ Example Usage
console.error(err); console.error(err);
}); });


var rules = new Gnip.Rules('https://api.gnip.com:443/accounts/xxx/publishers/twitter/streams/track/prod/rules.json', 'xxx', 'xxx'); var rules = new Gnip.Rules({
url : 'https://api.gnip.com:443/accounts/xxx/publishers/twitter/streams/track/prod/rules.json',
user : 'xxx',
password : 'xxx'
});


// create or replace tracking rules and update local cache.
// rules are sent in batches of 5000 (API limit), so you can pass an unlimited number of rules.
rules.update(['#hashtag', 'keyword', '@user'], function(err) { rules.update(['#hashtag', 'keyword', '@user'], function(err) {
if (err) throw err; if (err) throw err;
stream.start(); stream.start();
}); });


API methods
====
stream.start()
stream.end()

rules.getAll(Function callback)
rules.update(Array rules, Function callback)
rules.live.update(Array rules, Function callback)
rules.live.add(Array rules, Function callback)
rules.live.remove(Array rules, Function callback)
rules.live.getAll(Function callback)
rules.live.removeAll(Function callback)

More details and tests soon... More details and tests soon...

0 comments on commit 3a050d2

Please sign in to comment.