chirp-stream
Advanced tools
Comparing version 0.0.2 to 1.0.0
@@ -10,3 +10,3 @@ var ChirpStream = require('./'); | ||
public: process.env.TWITTER_TOKEN_PUBLIC, | ||
secret: process.env.TWITTER_SECRET_SECRET | ||
secret: process.env.TWITTER_TOKEN_SECRET | ||
} | ||
@@ -13,0 +13,0 @@ }); |
21
index.js
@@ -12,3 +12,3 @@ var debug = require('debug')('chirp-stream'); | ||
if(!(opt.consumer && opt.consumer.public && opt.consumer.secret)) { | ||
if(!(opt && opt.consumer && opt.consumer.public && opt.consumer.secret)) { | ||
throw new Error('consumer.public and consumer.secret are required'); | ||
@@ -38,6 +38,8 @@ } | ||
* @param {String} url streaming endpoint | ||
* @param {Object} opt request option | ||
* @param {Object} param twitter parameters | ||
* @param {String} method twitter endpoint | ||
* | ||
* @return {stream.Readable} stream.Readable object | ||
*/ | ||
ChirpStream.prototype.stream = function(url, opt) { | ||
ChirpStream.prototype.stream = function(url, param, method) { | ||
var self = this; | ||
@@ -49,13 +51,10 @@ | ||
if(!opt) { | ||
opt = {}; | ||
} | ||
param = param || {}; | ||
method = method || 'GET'; | ||
opt.method = opt.method || 'GET'; | ||
opt.param = opt.param || {}; | ||
var request_data = { | ||
url: url, | ||
method: opt.method, | ||
data: opt.param | ||
method: method, | ||
data: param | ||
}; | ||
@@ -62,0 +61,0 @@ |
{ | ||
"name": "chirp-stream", | ||
"version": "0.0.2", | ||
"version": "1.0.0", | ||
"description": "twitter streaming apis in nodejs", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -35,3 +35,2 @@ chirp-stream [![Build Status](https://travis-ci.org/ddo/chirp-stream.svg)](https://travis-ci.org/ddo/chirp-stream) | ||
userstream.on('data', function(data) { | ||
console.log('data'); | ||
console.log(data); | ||
@@ -41,3 +40,2 @@ }); | ||
userstream.on('json', function(json) { | ||
console.log('json'); | ||
console.log(json); | ||
@@ -51,3 +49,2 @@ }); | ||
userstream.on('error', function(error) { | ||
console.log('error'); | ||
console.log(error); | ||
@@ -64,3 +61,3 @@ }); | ||
```js | ||
var userstream = twitter.stream('https://stream.twitter.com/1.1/statuses/filter.json', { | ||
var filterstream = twitter.stream('https://stream.twitter.com/1.1/statuses/filter.json', { | ||
data: { | ||
@@ -76,3 +73,3 @@ follow: 61260444 //me :) | ||
```js | ||
var userstream = twitter.stream('https://stream.twitter.com/1.1/statuses/sample.json'); | ||
var samplestream = twitter.stream('https://stream.twitter.com/1.1/statuses/sample.json'); | ||
//listen to events... | ||
@@ -101,4 +98,4 @@ ``` | ||
* ``url``: ``String`` Twitter endpoint | ||
* ``param``: ``Object`` Twitter parameters ``optional`` | ||
* ``method``: ``String`` default ``GET`` | ||
* ``param``: ``Object`` Twitter parameters | ||
@@ -111,3 +108,4 @@ #### return | ||
* ``json``: ``Object`` twitter data **Use this instead of ``data``** | ||
* ``response``: ``Object`` response object | ||
* ``error``: status code (404, 503, ...) | ||
* ``end`` |
92
test.js
@@ -6,16 +6,15 @@ var expect = require('chai').expect; | ||
describe("chirp-stream", function() { | ||
describe("#stream", function() { | ||
var twitter = new ChirpStream({ | ||
consumer: { | ||
public: process.env.TWITTER_CONSUMER_PUBLIC, | ||
secret: process.env.TWITTER_CONSUMER_SECRET | ||
}, | ||
token: { | ||
public: process.env.TWITTER_TOKEN_PUBLIC, | ||
secret: process.env.TWITTER_SECRET_SECRET | ||
} | ||
}); | ||
var twitter = new ChirpStream({ | ||
consumer: { | ||
public: process.env.TWITTER_CONSUMER_PUBLIC, | ||
secret: process.env.TWITTER_CONSUMER_SECRET | ||
}, | ||
token: { | ||
public: process.env.TWITTER_TOKEN_PUBLIC, | ||
secret: process.env.TWITTER_TOKEN_SECRET | ||
} | ||
}); | ||
describe("#userstream", function() { | ||
it("should be return friend array", function(done) { | ||
var userstream = twitter.stream('https://userstream.twitter.com/1.1/user.json'); | ||
@@ -29,2 +28,71 @@ | ||
}); | ||
describe("#samplestream", function() { | ||
it("should be return some random data", function(done) { | ||
var samplestream = twitter.stream('https://stream.twitter.com/1.1/statuses/sample.json'); | ||
var _done = false; | ||
samplestream.on('json', function(json) { | ||
expect(json).to.be.an('object'); | ||
if(!_done) { | ||
_done = true; | ||
done(); | ||
} | ||
}); | ||
}); | ||
}); | ||
describe("#filterstream", function() { | ||
it("should be return some random data", function(done) { | ||
var filterstream = twitter.stream('https://stream.twitter.com/1.1/statuses/filter.json', { | ||
track: 'apple' | ||
}, 'POST'); | ||
var _done = false; | ||
filterstream.on('json', function(json) { | ||
expect(json).to.have.property('id'); | ||
expect(json).to.have.property('text'); | ||
expect(json).to.have.property('user').that.is.an('object'); | ||
if(!_done) { | ||
_done = true; | ||
done(); | ||
} | ||
}); | ||
}); | ||
}); | ||
https://stream.twitter.com/1.1/statuses/filter.json | ||
describe("invalid init", function() { | ||
it("should throw error", function() { | ||
expect(function() { | ||
ChirpStream(); | ||
}).to.throw('consumer.public and consumer.secret are required'); | ||
}); | ||
it("should throw consumer error", function() { | ||
expect(function() { | ||
ChirpStream({ | ||
token: { | ||
public: process.env.TWITTER_TOKEN_PUBLIC, | ||
secret: process.env.TWITTER_TOKEN_SECRET | ||
} | ||
}); | ||
}).to.throw('consumer.public and consumer.secret are required'); | ||
}); | ||
it("should throw token error", function() { | ||
expect(function() { | ||
ChirpStream({ | ||
consumer: { | ||
public: process.env.TWITTER_CONSUMER_PUBLIC, | ||
secret: process.env.TWITTER_CONSUMER_SECRET | ||
} | ||
}); | ||
}).to.throw('token.public and token.secret are required'); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
12306
203
0
105
12