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
11 changes: 11 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"presets": [
"es2015"
],
"plugins": [
"add-module-exports",
"transform-object-assign",
"es6-promise",
"transform-async-to-generator"
]
}
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
lib/
fixture/
33 changes: 33 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"extends": "standard",
"env": {
"es6": true,
"jest": true,
"node": true
},
"globals": {
"GENTLY": true
},
"rules": {
"no-multi-spaces": 0,
"comma-dangle": [
"error",
"always-multiline"
],
"key-spacing": [
"error",
{
"multiLine": {
"beforeColon": false,
"afterColon": true
},
"align": {
"beforeColon": false,
"afterColon": true,
"on": "colon",
"mode": "strict"
}
}
]
}
}
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
language: node_js
node_js:
- "0.10"
script: npm run test
- "7"
script:
- if [ "${TRAVIS_NODE_VERSION}" = "7" ]; then npm run lint; fi
- npm run test

# travis encrypt [subdomain]:[api token]@[room id]
notifications:
Expand Down
123 changes: 61 additions & 62 deletions examples/fetch_costs_of_all_assemblies_in_timeframe.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,81 @@
// make sure to "npm install async" for this demo
var async = require("async");
const async = require('async')
// You'll likely just want to `require('transloadit')`, but we're requiring the local
// variant here for easier testing:
var TransloaditClient = require("./lib/TransloaditClient");
const TransloaditClient = require('./lib/TransloaditClient')

function TransloaditCostFetcher(authKey, secret) {
this._client = new TransloaditClient({
authKey : authKey,
authSecret : secret
});
class TransloaditCostFetcher {
constructor (authKey, secret) {
this._client = new TransloaditClient({
authKey,
authSecret: secret,
})

this._params = params || {};
if (typeof this._params.page === "undefined") {
this._params.page = 1;
}

this._totalBytes = 0;
this._lastCount = 1;
}
this._params = params || {}
if (typeof this._params.page === 'undefined') {
this._params.page = 1
}

TransloaditCostFetcher.prototype.run = function(cb) {
var self = this;
this._totalBytes = 0
this._lastCount = 1
}

async.whilst(
function() {
return self._lastCount > 0;
},
function (callback) {
console.log("Processing page", self._params.page);
self._client.listAssemblies(self._params, function(err, result) {
self._lastCount = result.count;
self._params.page++;
run (cb) {
const self = this

if (!result.items || result.items.length === 0) {
return callback(err);
}
async.whilst(
() => self._lastCount > 0,
callback => {
console.log('Processing page', self._params.page)
self._client.listAssemblies(self._params, (err, {count, items}) => {
self._lastCount = count
self._params.page++

var q = async.queue(self._fetchAssemblyCost.bind(self), 20);
q.drain = callback;
if (!items || items.length === 0) {
return callback(err)
}

for (var i = 0; i < result.items.length; i++) {
q.push(result.items[i].id);
}
const q = async.queue(self._fetchAssemblyCost.bind(self), 20)
q.drain = callback

});
},
function (err) {
var gb = (self._totalBytes / (1024 * 1024 * 1024)).toFixed(2);
cb(err, gb);
}
);
};
for (let i = 0; i < items.length; i++) {
q.push(items[i].id)
}
})
},
err => {
const gb = (self._totalBytes / (1024 * 1024 * 1024)).toFixed(2)
cb(err, gb)
}
)
}

TransloaditCostFetcher.prototype._fetchAssemblyCost = function(assemblyId, cb) {
var self = this;
_fetchAssemblyCost (assemblyId, cb) {
const self = this

this._client.getAssembly(assemblyId, function(err, result) {
if (err) {
return cb(err);
}
this._client.getAssembly(assemblyId, (err, {bytesUsage}) => {
if (err) {
return cb(err)
}

self._totalBytes += result.bytes_usage ? result.bytes_usage : 0;
cb();
});
};
self._totalBytes += bytesUsage || 0
cb()
})
}
}

var authKey = "YOUR_AUTH_KEY";
var authSecret = "YOUR_AUTH_SECRET";
const authKey = 'YOUR_AUTH_KEY'
const authSecret = 'YOUR_AUTH_SECRET'

var params = {
fromdate : "2014-05-22 00:00:00",
todate : "2014-05-22 23:59:59"
};
var fetcher = new TransloaditCostFetcher(authKey, authSecret, params);
fetcher.run(function(err, usageInGb) {
fromdate: '2014-05-22 00:00:00',
todate : '2014-05-22 23:59:59',
}
const fetcher = new TransloaditCostFetcher(authKey, authSecret, params)
fetcher.run((err, usageInGb) => {
if (err) {
console.error(err);
console.error(err)
} else {
console.log("Total GB:", usageInGb);
console.log('Total GB:', usageInGb)
}
});
})
26 changes: 13 additions & 13 deletions examples/list_assembly_notifications.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// You'll likely just want to `require('transloadit')`, but we're requiring the local
// variant here for easier testing:
var TransloaditClient = require("../lib/TransloaditClient");
const TransloaditClient = require('../lib/TransloaditClient')

var client = new TransloaditClient({
authKey : 'YOUR_AUTH_KEY',
authSecret : 'YOUR_AUTH_SECRET'
});
const client = new TransloaditClient({
authKey : 'YOUR_AUTH_KEY',
authSecret: 'YOUR_AUTH_SECRET',
})

var params = {
type: 'all'
};
client.listAssemblyNotifications(params, function(err, result) {
const params = {
type: 'all',
}
client.listAssemblyNotifications(params, (err, result) => {
if (err) {
console.log('fail');
console.log('fail')
} else {
console.log('success');
console.log('success')
}
console.log(result);
});
console.log(result)
})
94 changes: 47 additions & 47 deletions examples/template_api.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,74 @@
// You'll likely just want to `require('transloadit')`, but we're requiring the local
// variant here for easier testing:
var TransloaditClient = require("../lib/TransloaditClient");
const TransloaditClient = require('../lib/TransloaditClient')

var client = new TransloaditClient({
authKey : 'YOUR_AUTH_KEY',
authSecret : 'YOUR_AUTH_SECRET'
});
const client = new TransloaditClient({
authKey : 'YOUR_AUTH_KEY',
authSecret: 'YOUR_AUTH_SECRET',
})

var template = {
const template = {
steps: {
encode: {
use: ":original",
robot: "/video/encode",
preset: "ipad-high"
use : ':original',
robot : '/video/encode',
preset: 'ipad-high',
},
thumbnail: {
use: "encode",
robot: "/video/thumbnails"
}
}
};
use : 'encode',
robot: '/video/thumbnails',
},
},
}

var templateString = JSON.stringify(template);
var params = {
name : 'node_sdk_test1',
template : templateString
};
var newParams = {
name : 'node_sdk_test2',
template : templateString
};
var listParams = {
sort : 'created',
order : 'asc'
};
const templateString = JSON.stringify(template)
const params = {
name : 'node_sdk_test1',
template: templateString,
}
const newParams = {
name : 'node_sdk_test2',
template: templateString,
}
const listParams = {
sort : 'created',
order: 'asc',
}

// this just serves as an example, normally you would refactor this
// christmas tree with control flow modules such as "async"

client.listTemplates(listParams, function(err, templates) {
client.listTemplates(listParams, (err, {count}) => {
if (err) {
return console.log('failed fetching templates:', err);
return console.log('failed fetching templates:', err)
}
console.log('Successfully fetched', templates.count, 'template(s)');
console.log('Successfully fetched', count, 'template(s)')

client.createTemplate(params, function(err, result) {
client.createTemplate(params, (err, result) => {
if (err) {
return console.log('Failed creating template', err);
return console.log('Failed creating template', err)
}
console.log('Template created successfully:', result);
console.log('Template created successfully:', result)

client.editTemplate(result.template_id, newParams, function(err, editResult) {
client.editTemplate(result.template_id, newParams, (err, editResult) => {
if (err) {
return console.log('failed editing template:', err);
return console.log('failed editing template:', err)
}
console.log('Successfully edited template', editResult);
console.log('Successfully edited template', editResult)

client.getTemplate(result.template_id, function(err, templateResult) {
client.getTemplate(result.template_id, (err, templateResult) => {
if (err) {
return console.log('failed fetching template:', err);
return console.log('failed fetching template:', err)
}
console.log('Successfully fetched template', templateResult);
console.log('Successfully fetched template', templateResult)

client.deleteTemplate(result.template_id, function(err, delResult) {
client.deleteTemplate(result.template_id, (err, delResult) => {
if (err) {
return console.log('failed deleting template:', err);
return console.log('failed deleting template:', err)
}
console.log('Successfully deleted template', delResult);
});
});
});
});
});
console.log('Successfully deleted template', delResult)
})
})
})
})
})
Loading