Skip to content

Commit

Permalink
Merge pull request #143 from hbaqai/master
Browse files Browse the repository at this point in the history
Adding linting
  • Loading branch information
hbaqai authored Nov 23, 2016
2 parents 3ee1dec + faffdc9 commit e552771
Show file tree
Hide file tree
Showing 16 changed files with 1,111 additions and 1,077 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
bower_components
sample

6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "airbnb-base/legacy",
"rules": {
"no-restricted-syntax": ["off", "ForInStatement"]
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
.DS_Store
.vscode
*.log
18 changes: 8 additions & 10 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = function(grunt) {

module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
Expand All @@ -14,17 +13,17 @@ module.exports = function(grunt) {
jasmine_node: {
options: {
extensions: 'js',
specNameMatcher: 'spec',
specNameMatcher: 'spec'
},
all: ['spec/']
},
jsdoc : {
dist : {
src: ['lib/*.js'],
options: {
destination: 'docs'
}
jsdoc: {
dist: {
src: ['lib/*.js'],
options: {
destination: 'docs'
}
}
}
});

Expand All @@ -33,5 +32,4 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-jsdoc');

grunt.registerTask('default', ['mochaTest', 'jasmine_node']);

};
176 changes: 90 additions & 86 deletions lib/archiving.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/*global require, exports*/
/*jshint strict:false, eqnull:true */
/* global require, exports*/
/* jshint strict:false, eqnull:true */

var request = require('request'),
errors = require('./errors'),
pkg = require('../package.json'),
_ = require('lodash');
var request = require('request');
var errors = require('./errors');
var pkg = require('../package.json');
var _ = require('lodash');

// functions
var api;

/**
* An object representing an OpenTok archive.
Expand Down Expand Up @@ -79,10 +82,10 @@ var request = require('request'),
* See the {@link OpenTok#startArchive OpenTok.startArchive()} method.
*
* @property {String} url
* The download URL of the available MP4 file. This is only set for an archive with the status set to
* "available"; for other archives, (including archives with the status "uploaded") this property is
* set to null. The download URL is obfuscated, and the file is only available from the URL for
* 10 minutes. To generate a new URL, call the {@link OpenTok#getArchive OpenTok.getArchive()} or
* The download URL of the available MP4 file. This is only set for an archive with the status set
* to "available"; for other archives, (including archives with the status "uploaded") this
* property is set to null. The download URL is obfuscated, and the file is only available from the
* URL for 10 minutes. To generate a new URL, call the {@link OpenTok#getArchive OpenTok.getArchive()} or
* {@link OpenTok#listArchives OpenTok.listArchives()} method.
*
* @see {@link OpenTok#deleteArchive OpenTok.deleteArchive()}
Expand All @@ -94,13 +97,14 @@ var request = require('request'),
* @class Archive
*/
function Archive(config, properties) {
var hasProp = {}.hasOwnProperty,
id = properties.id,
key;
var hasProp = {}.hasOwnProperty;
var id = properties.id;
var key;

for (key in properties) {
if (!hasProp.call(properties, key)) continue;
this[key] = properties[key];
if (hasProp.call(properties, key)) {
this[key] = properties[key];
}
}

/**
Expand All @@ -127,7 +131,7 @@ function Archive(config, properties) {
* @method #stop
* @memberof Archive
*/
this.stop = function(callback) {
this.stop = function (callback) {
exports.stopArchive(config, id, callback);
};

Expand All @@ -145,14 +149,14 @@ function Archive(config, properties) {
* @method #delete
* @memberof Archive
*/
this.delete = function(callback) {
this.delete = function (callback) {
exports.deleteArchive(config, id, callback);
};
}

var api = function(config, method, path, body, callback) {
api = function (config, method, path, body, callback) {
var rurl = config.apiEndpoint + '/v2/partner/' + config.apiKey + path;
if ("defaults" in request) {
if ('defaults' in request) {
request = request.defaults(_.pick(config, 'proxy', 'timeout'));
}
request({
Expand All @@ -167,52 +171,53 @@ var api = function(config, method, path, body, callback) {
}, callback);
};

exports.listArchives = function(config, options, callback) {
if(typeof options == 'function') {
exports.listArchives = function (config, options, callback) {
var qs = [];

if (typeof options === 'function') {
callback = options;
options = {};
}
if(typeof callback != 'function') {
throw(new errors.ArgumentError('No callback given to listArchives'));
if (typeof callback !== 'function') {
throw (new errors.ArgumentError('No callback given to listArchives'));
}
var qs = [];
if(options.offset) {
if (options.offset) {
qs.push('offset=' + parseInt(options.offset, 10));
}
if(options.count) {
if (options.count) {
qs.push('count=' + parseInt(options.count, 10));
}
api(config, 'GET', '/archive?' + qs.join('&'), null, function(err, response, body) {
if(!err && body ) {
api(config, 'GET', '/archive?' + qs.join('&'), null, function (err, response, body) {
if (!err && body) {
try {
body = JSON.parse(body);
} catch (_err) {
err = _err;
}
}
if(err || response.statusCode != 200) {
if(response && response.statusCode == 403) {
if (err || response.statusCode !== 200) {
if (response && response.statusCode === 403) {
callback(new errors.AuthError('Invalid API key or secret'));
} else {
callback(new errors.RequestError('Unexpected response from OpenTok'));
}
} else {
callback(null, body.items.map(function(item){
callback(null, body.items.map(function (item) {
return new Archive(config, item);
}), body.count);
}
});
};

exports.startArchive = function(config, sessionId, options, callback) {
if(typeof options == 'function') {
exports.startArchive = function (config, sessionId, options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
}
if(typeof callback != 'function') {
throw(new errors.ArgumentError('No callback given to startArchive'));
if (typeof callback !== 'function') {
throw (new errors.ArgumentError('No callback given to startArchive'));
}
if(sessionId == null || sessionId.length === 0) {
if (sessionId == null || sessionId.length === 0) {
callback(new errors.ArgumentError('No session ID given'));
return;
}
Expand All @@ -222,74 +227,73 @@ exports.startArchive = function(config, sessionId, options, callback) {
hasAudio: options.hasAudio,
hasVideo: options.hasVideo,
outputMode: options.outputMode
}, function(err, response, body) {
if(err) {
}, function startArchiveCallback(err, response, body) {
if (err) {
callback(err);
} else if(response.statusCode != 200) {
if(response && response.statusCode == 404) {
} else if (response.statusCode !== 200) {
if (response && response.statusCode === 404) {
callback(new errors.ArchiveError('Session not found'));
} else if(response && response.statusCode == 403) {
} else if (response && response.statusCode === 403) {
callback(new errors.AuthError('Invalid API key or secret'));
} else {
callback(new errors.RequestError('Unexpected response from OpenTok'));
}
} else if(body.status != 'started') {
} else if (body.status !== 'started') {
callback(new errors.RequestError('Unexpected response from OpenTok'));
} else {
callback(null, new Archive(config, body));
}
});
};

exports.stopArchive = function(config, archiveId, callback) {
if(typeof callback != 'function') {
throw(new errors.ArgumentError('No callback given to stopArchive'));
exports.stopArchive = function (config, archiveId, callback) {
if (typeof callback !== 'function') {
throw (new errors.ArgumentError('No callback given to stopArchive'));
}
if(archiveId == null || archiveId.length === 0) {
if (archiveId == null || archiveId.length === 0) {
callback(new errors.ArgumentError('No archive ID given'));
return;
}
api(config, 'POST', '/archive/' + encodeURIComponent(archiveId) + '/stop', {},
function(err, response, body) {
if(err) {
callback(err);
} else if(response.statusCode != 200) {
if(response && response.statusCode == 404) {
callback(new errors.ArchiveError('Archive not found'));
} else if(response && response.statusCode == 409) {
callback(new errors.ArchiveError(body.message));
} else if(response && response.statusCode == 403) {
callback(new errors.AuthError('Invalid API key or secret'));
function stopArchiveCallback(err, response, body) {
if (err) {
callback(err);
} else if (response.statusCode !== 200) {
if (response && response.statusCode === 404) {
callback(new errors.ArchiveError('Archive not found'));
} else if (response && response.statusCode === 409) {
callback(new errors.ArchiveError(body.message));
} else if (response && response.statusCode === 403) {
callback(new errors.AuthError('Invalid API key or secret'));
} else {
callback(new errors.RequestError('Unexpected response from OpenTok'));
}
} else {

callback(new errors.RequestError('Unexpected response from OpenTok'));
callback(null, new Archive(config, body));
}
} else {
callback(null, new Archive(config, body));
}
});
});
};

exports.getArchive = function(config, archiveId, callback) {
if(typeof callback != 'function') {
throw(new errors.ArgumentError('No callback given to getArchive'));
exports.getArchive = function (config, archiveId, callback) {
if (typeof callback !== 'function') {
throw (new errors.ArgumentError('No callback given to getArchive'));
}
if(archiveId == null || archiveId.length === 0) {
if (archiveId == null || archiveId.length === 0) {
callback(new errors.ArgumentError('No archive ID given'));
return;
}
api(config, 'GET', '/archive/' + archiveId, null, function(err, response, body) {
if(!err && body ) {
api(config, 'GET', '/archive/' + archiveId, null, function getArchiveCallback(err, response, body) {
if (!err && body) {
try {
body = JSON.parse(body);
} catch (_err) {
err = _err;
}
}
if(err || response.statusCode != 200) {
if(response && response.statusCode == 404) {
if (err || response.statusCode !== 200) {
if (response && response.statusCode === 404) {
callback(new errors.ArchiveError('Archive not found'));
} else if(response && response.statusCode == 403) {
} else if (response && response.statusCode === 403) {
callback(new errors.AuthError('Invalid API key or secret'));
} else {
callback(new errors.RequestError('Unexpected response from OpenTok'));
Expand All @@ -300,26 +304,26 @@ exports.getArchive = function(config, archiveId, callback) {
});
};

exports.deleteArchive = function(config, archiveId, callback) {
if(typeof callback != 'function') {
throw(new errors.ArgumentError('No callback given to deleteArchive'));
exports.deleteArchive = function (config, archiveId, callback) {
if (typeof callback !== 'function') {
throw (new errors.ArgumentError('No callback given to deleteArchive'));
}
if(archiveId == null || archiveId.length === 0) {
if (archiveId == null || archiveId.length === 0) {
callback(new errors.ArgumentError('No archive ID given'));
return;
}
api(config, 'DELETE', '/archive/' + encodeURIComponent(archiveId), null,
function(err, response) {
if(err || response.statusCode != 204) {
if(response && response.statusCode == 404) {
callback(new errors.ArchiveError('Archive not found'));
} else if(response && response.statusCode == 403) {
callback(new errors.AuthError('Invalid API key or secret'));
function deleteArchiveCallback(err, response) {
if (err || response.statusCode !== 204) {
if (response && response.statusCode === 404) {
callback(new errors.ArchiveError('Archive not found'));
} else if (response && response.statusCode === 403) {
callback(new errors.AuthError('Invalid API key or secret'));
} else {
callback(new errors.RequestError('Unexpected response from OpenTok'));
}
} else {
callback(new errors.RequestError('Unexpected response from OpenTok'));
callback(null);
}
} else {
callback(null);
}
});
});
};
Loading

0 comments on commit e552771

Please sign in to comment.