Socket
Socket
Sign inDemoInstall

socializr

Package Overview
Dependencies
17
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.3 to 0.2.0

lib/message.js

183

lib/providers/twitter.js

@@ -11,2 +11,4 @@ /*!

, qs = require('querystring')
, events = require('events')
, uuid = require('node-uuid')

@@ -20,2 +22,4 @@ , Transform = stream.Transform

, Message = require('../message')
/**

@@ -577,5 +581,5 @@ * Package info

try{
tweet = JSON.parse( tweet.trim());
this.push(tweet);
// console.log('pushed new data to stream successfully');
this.push(
new Message( this, JSON.parse(tweet.trim()) )
);
}catch(err){

@@ -763,6 +767,172 @@ this._body = '';

function TwitterClient(appAuth, userAuth){
if( !appAuth ||
!appAuth.hasOwnProperty('key') ||
!appAuth.hasOwnProperty('secret')
){
throw new Error('Invalid App/Client Authentication info. `key` and `secret` properties are required.');
}
if( !userAuth ||
!userAuth.hasOwnProperty('user') ||
!userAuth.hasOwnProperty('token') ||
!userAuth.hasOwnProperty('secret')
){
throw new Error('Invalid User Authentication info. `user`, `token` and `secret` properties are required.');
}
this._appAuth = appAuth;
this._userAuth = userAuth;
};
util.inherits(TwitterClient, events.EventEmitter);
TwitterClient.prototype.request = function(endpointUrl, method, data, cb){
this._req = https.request(
this._createRequestOptions( endpointUrl, method, data),
this._connectionResponse.bind(this)
);
this._req.on('error', function(e){
cb&&cb(e);
}.bind(this));
if( method=='POST'){
this._req.end(
qs.stringify(data), 'utf8'
);
}else {
this._req.end();
}
return this;
};
TwitterClient.prototype._createRequestOptions = function(endpointUrl, endpointMethod, data){
var method = endpointMethod || 'GET'
, auth = oauth.createAuthHeaders({
method: method,
url: endpointUrl,
data: data,
appKey: this._appAuth.key,
appSecret: this._appAuth.secret,
token: this._userAuth.token,
tokenSecret: this._userAuth.secret
})
;
var _qs = '';
if( method == 'GET'){
_qs = '?' + qs.stringify(data);
}
return {
hostname: hostname( endpointUrl),
path: path( endpointUrl) + _qs,
method: method,
headers: {
'Authorization': auth,
'User-Agent': pkg.name + ' v' + pkg.version,
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
'Accept-Encoding': 'gzip',
'Connection': 'keep-alive'
},
/* Disable agent pooling */
agent: false
};
};
TwitterClient.prototype._connectionResponse = function(res){
switch( res.statusCode){
case 200:
this._connected( res);
break;
default:
this._connectionError( res);
break;
}
};
TwitterClient.prototype._connected = function(res){
// console.log( res.headers, res.statusCode);
this._res = res;
switch( res.headers['content-encoding']){
case 'gzip':
this._gunzip = zlib.createGunzip();
var body = '';
this._gunzip.on('data', function(data){
body += data.toString();
});
this._gunzip.on('end', function(){
this.emit('data',JSON.parse(body));
}.bind(this));
this._res.pipe(this._gunzip);
break;
default:
this.emit('data',data);
break;
}
};
TwitterClient.prototype._connectionError = function(res){
var err;
switch( res.statusCode){
case 401:
err = {
code: 401,
message: 'Unauthorized'
};
break;
case 420:
err = {
code: 420,
message: 'Rate limited'
};
break;
case 503:
err = {
code: 503,
message: 'Service Unavailable'
};
break;
default:
err = {
code: res.statusCode,
message: 'Error connecting.'
};
break;
}
console.log(res.statusCode);
this.emit('error', new Error(err.message));
};
/**

@@ -783,2 +953,6 @@ * Twitter constructor

this._filters = options.filters || [];
this.uuid = uuid.v1();
console.log(this.uuid);
};

@@ -838,2 +1012,3 @@ util.inherits(Twitter, Transform);

strm = new TwitterStream(this._auth, auth[ i]);
strm.uuid = this.uuid;
this._saveStreamForAuth( auth[ i], strm);

@@ -923,2 +1098,4 @@ strm.on('warning', this._onError.bind(this));

*/
Twitter.TwitterClient = TwitterClient;
module.exports = Twitter;

@@ -9,2 +9,3 @@ var https = require('https')

, Instagram = require('./providers/instagram')
, GooglePlus = require('./providers/gplus')
;

@@ -84,2 +85,4 @@

/**

@@ -90,2 +93,3 @@ *

/**

@@ -106,1 +110,6 @@ *

module.exports.Instagram = Instagram;
/**
*
*/
module.exports.GooglePlus = GooglePlus;

6

package.json
{
"name": "socializr",
"version": "0.1.3",
"version": "0.2.0",
"description": "Read data streams from several social networks.",

@@ -37,4 +37,6 @@ "main": "index.js",

"superagent": "0.17.x",
"async": "^0.6.2"
"async": "^0.6.2",
"pragma-scheduler": "^1.0.5",
"node-uuid": "^1.4.1"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc