Skip to content

Commit cf7ef6a

Browse files
committed
#3 - #9 - Added support for setting pool configuration and gzip
1 parent e7128b7 commit cf7ef6a

File tree

4 files changed

+95
-7
lines changed

4 files changed

+95
-7
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Twitter.pipe(fs.createWriteStream('tweets.json'));
4747
Create a new Twitter Stream API instance.
4848

4949
```js
50-
var Twitter = new TwitterStream(keys, objectMode);
50+
var Twitter = new TwitterStream(keys, [objectMode, options]);
5151
```
5252

5353

@@ -75,6 +75,17 @@ value is `true` which set the stream to emit Objects. If a non-object stream is
7575
wanted, set the value to `false`.
7676

7777

78+
### options (optional)
79+
80+
An Object containing misc configuration. The following values can be provided:
81+
82+
* gzip - Boolean value for enabling / disabling gzip on the connection against Twitter.
83+
* pool - Sets pool configuration on the underlaying request.js object.
84+
85+
Please refere to [request.js](https://github.com/request/request) for further
86+
documentation on these cunfiguration options.
87+
88+
7889

7990
## API
8091

examples/site.basic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ Twitter.on('connection error stall', function () {
4343
console.log('connection error stall');
4444
});
4545

46-
Twitter.on('connection error http', function () {
47-
console.log('connection error http');
46+
Twitter.on('connection error http', function (err) {
47+
console.log('connection error http', err);
4848
});
4949

5050
Twitter.on('connection rate limit', function () {

lib/main.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,28 @@ var util = require('util'),
2727
* @param {String} keys.consumer_secret Twitter consumer secret (API Secret)
2828
* @param {String} keys.token Twitter access token
2929
* @param {String} keys.token_secret Twitter access token secret
30-
* @param {Boolean} objectMode If the stream should run in object mode or not. Default true.
30+
* @param {(Boolean[]|Object[])} param1 If the stream should run in object mode or not. Default true.
31+
* @param {Object[]} param2 A configurations Object
3132
*/
3233

33-
var Twitter = module.exports = function (keys, objectMode) {
34+
var Twitter = module.exports = function (keys, param1, param2) {
3435
var self = this;
35-
objectMode = utils.isNullOrUndefined(objectMode) ? true : objectMode;
36+
var objectMode = true;
37+
var options = {};
3638

37-
this.connection = new Connection(keys);
39+
if (utils.isBoolean(param1)) {
40+
objectMode = param1;
41+
}
42+
43+
if (utils.isObject(param1)) {
44+
options = param1;
45+
}
46+
47+
if (utils.isObject(param2)) {
48+
options = param2;
49+
}
50+
51+
this.connection = new Connection(keys, options);
3852
this.streamEndpoint = 'statuses/filter';
3953
this.streamParams = null;
4054

test/main.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* jshint node: true, strict: true */
2+
3+
"use strict";
4+
5+
var tap = require('tap'),
6+
TwitterStream = require('../lib/main.js');
7+
8+
9+
var keys = {
10+
consumer_key: "a",
11+
consumer_secret: "b",
12+
token: "c",
13+
token_secret: "d"
14+
};
15+
16+
17+
18+
tap.test('Main() - no rest attributes set - "objectMode" should be "true" - "options" should be empty Object', function (t) {
19+
var Twitter = new TwitterStream(keys);
20+
t.equal(Twitter._readableState.objectMode, true);
21+
t.same(Twitter.connection.options, {});
22+
t.end();
23+
});
24+
25+
26+
tap.test('Main() - 1st rest attribute is "true" - "objectMode" should be "true" - "options" should be empty Object', function (t) {
27+
var Twitter = new TwitterStream(keys, true);
28+
t.equal(Twitter._readableState.objectMode, true);
29+
t.same(Twitter.connection.options, {});
30+
t.end();
31+
});
32+
33+
34+
tap.test('Main() - 1st rest attribute is "false" - "objectMode" should be "false" - "options" should be empty Object', function (t) {
35+
var Twitter = new TwitterStream(keys, false);
36+
t.equal(Twitter._readableState.objectMode, false);
37+
t.same(Twitter.connection.options, {});
38+
t.end();
39+
});
40+
41+
42+
tap.test('Main() - 1st rest attribute is a Object - "objectMode" should be "true" - "options" should be same Object', function (t) {
43+
var Twitter = new TwitterStream(keys, {gzip : true});
44+
t.equal(Twitter._readableState.objectMode, true);
45+
t.same(Twitter.connection.options, {gzip : true});
46+
t.end();
47+
});
48+
49+
50+
tap.test('Main() - 1st rest attribute is "true" - 2nd rest attribute is an Object - "objectMode" should be "true" - "options" should be same Object', function (t) {
51+
var Twitter = new TwitterStream(keys, true, {gzip : true});
52+
t.equal(Twitter._readableState.objectMode, true);
53+
t.same(Twitter.connection.options, {gzip : true});
54+
t.end();
55+
});
56+
57+
58+
tap.test('Main() - 1st rest attribute is "false" - 2nd rest attribute is an Object - "objectMode" should be "true" - "options" should be same Object', function (t) {
59+
var Twitter = new TwitterStream(keys, false, {gzip : true});
60+
t.equal(Twitter._readableState.objectMode, false);
61+
t.same(Twitter.connection.options, {gzip : true});
62+
t.end();
63+
});

0 commit comments

Comments
 (0)