Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"preset": "airbnb",
"requirePaddingNewLinesBeforeLineComments": null,
"disallowQuotedKeysInObjects": false,
"disallowMultipleVarDecl": false,
"requireDotNotation": false,
"safeContextKeyword": null
}
4 changes: 2 additions & 2 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters.
"nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment)
"plusplus" : false, // true: Prohibit use of `++` and `--`
"quotmark" : false, // Quotation mark consistency:
"quotmark" : "single", // Quotation mark consistency:
// false : do nothing (default)
// true : ensure whatever is used is consistent
// "single" : require single quotes
Expand Down Expand Up @@ -62,7 +62,7 @@
"proto" : false, // true: Tolerate using the `__proto__` property
"scripturl" : false, // true: Tolerate script-targeted URLs
"shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
"sub" : true, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
"validthis" : false, // true: Tolerate using this in a non-constructor function

Expand Down
12 changes: 7 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var gulp = require('gulp');
var gutil = require('gulp-util');
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
var stylish = require('gulp-jscs-stylish');
var mocha = require('gulp-mocha');
var fs = require('fs');
var git = require('gulp-git');
Expand Down Expand Up @@ -38,12 +40,12 @@ function runSynchronized(tasks, callback){
*/


// check for jshint errors
// check for jshint and jscs errors
gulp.task('lint', function() {
return gulp.src('./src/lib/*.js')
.pipe(jshint({
lookup: true
}))
return gulp.src('./src/**/*.js')
.pipe(jshint({ lookup: true }))
.pipe(jscs())
.pipe(stylish.combineWithHintResults())
.pipe(jshint.reporter('jshint-stylish'));
});

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"gulp-browserify": "^0.5.0",
"gulp-bump": "^0.1.8",
"gulp-git": "git://github.com/stevelacy/gulp-git.git",
"gulp-jscs": "^3.0.1",
"gulp-jscs-stylish": "^1.2.1",
"gulp-jshint": "^1.6.3",
"gulp-mocha": "^0.4.1",
"gulp-shell": "^0.2.7",
Expand Down
54 changes: 28 additions & 26 deletions src/getstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,34 @@ var errors = require('./lib/errors');
var request = require('request');

function connect(apiKey, apiSecret, appId, options) {
/*
* Usage
* stream.connect(apiKey, apiSecret)
* or if you want to be able to subscribe and listen
* for changes
* stream.connect(apiKey, apiSecret, appId)
* or on heroku
* stream.connect(streamURL)
* where streamURL looks like this
* https://thierry:pass@getstream.io/?app=1
*
*/
if (typeof(process) != "undefined" && process.env.STREAM_URL && !apiKey) {
var parts = /https\:\/\/(\w+)\:(\w+)\@([\w-]*).*\?app_id=(\d+)/.exec(process.env.STREAM_URL);
apiKey = parts[1];
apiSecret = parts[2];
var location = parts[3];
appId = parts[4];
if (options === undefined) {
options = {};
}
if (location != 'getstream') {
options.location = location;
}
}
return new StreamClient(apiKey, apiSecret, appId, options);
/*
* Usage
* stream.connect(apiKey, apiSecret)
* or if you want to be able to subscribe and listen
* for changes
* stream.connect(apiKey, apiSecret, appId)
* or on heroku
* stream.connect(streamURL)
* where streamURL looks like this
* https://thierry:pass@getstream.io/?app=1
*
*/
if (typeof (process) !== 'undefined' && process.env.STREAM_URL && !apiKey) {
var parts = /https\:\/\/(\w+)\:(\w+)\@([\w-]*).*\?app_id=(\d+)/.exec(process.env.STREAM_URL);
apiKey = parts[1];
apiSecret = parts[2];
var location = parts[3];
appId = parts[4];
if (options === undefined) {
options = {};
}

if (location !== 'getstream') {
options.location = location;
}
}

return new StreamClient(apiKey, apiSecret, appId, options);
}

module.exports.connect = connect;
Expand Down
26 changes: 13 additions & 13 deletions src/lib/batch_operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@ var request = require('request');
var errors = require('./errors');

module.exports = {
addToMany: function(activity, feeds, callback) {
addToMany: function(activity, feeds, callback) {
var req = this.makeSignedRequest({
url: 'feed/add_to_many/',
body: {
'activity': activity,
'feeds': feeds
}
activity: activity,
feeds: feeds,
},
}, callback);

return req;
},

followMany: function(follows, callback) {
followMany: function(follows, callback) {
var req = this.makeSignedRequest({
url: 'follow_many/',
body: follows
}, callback);
body: follows,
}, callback);

return req;
},

makeSignedRequest: function(kwargs, cb) {
if(!this.apiSecret) {
makeSignedRequest: function(kwargs, cb) {
if (!this.apiSecret) {
throw new errors.SiteError('Missing secret, which is needed to perform signed requests, use var client = stream.connect(key, secret);');
}

Expand All @@ -34,17 +34,17 @@ module.exports = {
kwargs.url = this.enrichUrl(kwargs.url);
kwargs.json = true;
kwargs.method = 'POST';
kwargs.headers = { 'X-Api-Key' : this.apiKey };
kwargs.headers = { 'X-Api-Key': this.apiKey };

var callback = this.wrapCallback(cb);
var req = request(kwargs, callback);

httpSignature.sign(req, {
algorithm: 'hmac-sha256',
key: this.apiSecret,
keyId: this.apiKey
keyId: this.apiKey,
});

return request;
}
},
};
Loading