Permalink
Browse files

initial commit, mostly broken

  • Loading branch information...
1 parent b538a66 commit aba400a4cc3e55bef16bc752b90fbd44ddbabbcb Ian Hansen committed Jul 21, 2012
Showing with 166 additions and 0 deletions.
  1. +1 −0 index.js
  2. +72 −0 lib/assembly.js
  3. +75 −0 lib/transloadit.js
  4. +18 −0 package.json
View
1 index.js
@@ -0,0 +1 @@
+module.exports = require('./lib/transloadit');
View
72 lib/assembly.js
@@ -0,0 +1,72 @@
+function Assembly(transloadit) {
+ this._transloadit = transloadit;
+ this._templateId = null;
+ this._steps = {};
+ this._fields = {};
+ this._files = {};
+ this._streams = {};
+
+ this._response = null;
+}
+
+Assembly.prototype.step = function(name, robot, params) {
+ if (arguments.length === 1) return this._steps[name];
+
+ this._steps[name] = params || {};
+ this._steps[name].robot = robot;
+ return this;
+};
+
+Assembly.prototype.field = function(name, value) {
+ if (arguments.length === 1) return this._fields[name];
+
+ this._fields[name] = value;
+ return this;
+};
+
+Assembly.prototype.templateId = function(templateId) {
+ if (arguments.length === 0) return this._templateId;
+
+ this._templateId = templateId;
+ return this;
+};
+
+// Assembly.prototype.file = function(name, path) {
+// if (arguments.length === 0) return this._files[name];
+
+// this._files[name] = path;
+// return this;
+// };
+
+// Assembly.prototype.stream = function(name, stream) {
+// if (arguments.length === 0) return this._streams[name];
+
+// this._streams[name] = stream;
+// return this;
+// };
+
+Assembly.prototype.run = function(options) {
+ this._transloadit._multipart({
+ path: '/assemblies',
+ params: {
+ test: 'value'
+ },
+ streams: {}
+ }, function handleMultipart(err, response) {
+ console.log('multipart', arguments);
+ });
+};
+
+Assembly.prototype.error = function(cb) {
+ this._error = cb;
+};
+
+Assembly.prototype.success = function(cb) {
+ this._success = cb;
+};
+
+Assembly.prototype.update = function(cb) {
+ this._update = cb;
+};
+
+module.exports = Assembly;
View
75 lib/transloadit.js
@@ -0,0 +1,75 @@
+var multiparter = require('multiparter')
+ , http = require('http')
+ , Assembly = require('./assembly')
+ , API_HOST = 'api2.transloadit.com'
+ , nop = function() {}
+ ;
+
+function Transloadit(options) {
+ options = options || {};
+ this._key = options.key;
+ this._secret = options.secret;
+};
+
+/**
+ * options - {
+ * steps: {} - assembly steps
+ * templateId: (optional) string template id
+ * fields: {} (optional) variables to be used in the assembly
+ * files: {} (optional) hash {name: filepath}
+ * auth: {key: String, secret: String} - (optional) use transloadit constructor values by default
+ * redirect_url: (optional) no redirect url by default
+ * notify_url: (optional) no notify url by default
+ * success: (optional) callback to trigger when the assembly completes successfully
+ * error: (optional) callback to trigger on error
+ * change: (optional) callback to trigger when the state of the assembly changes
+ * }
+ */
+Transloadit.prototype.createAssembly = function(options) {
+ if (!options) return new Assembly(this);
+
+
+ request({
+ url: 'http://' + API_HOST + '/assemblies',
+ method: 'POST',
+ json: options.params || {},
+ })
+};
+
+Transloadit.prototype.getAssemblyStatus = function() {};
+
+/**
+ * options - {
+ * path: '/assemblies',
+ * params: { - hash of name/value parameters
+ * signature: 'Test'
+ * },
+ * streams: { - hash of streams
+ * name: {
+ * fileName,
+ * mimeType,
+ * streamLength,
+ * stream
+ * }
+ * }
+ * }
+ */
+Transloadit.prototype._multipart = function(options, cb) {
+ var request = new multiparter.request(http, {
+ host: API_HOST,
+ port: 80,
+ path: options.path,
+ method: 'POST'
+ });
+ Object.keys(options.params).forEach(function(key) {
+ request.setParam(key, options.params[key]);
+ });
+ Object.keys(options.streams).forEach(function(key) {
+ var stream = options.streams[key];
+ request.addStream(key, stream.fileName, stream.mimeType, stream.streamLength, stream.stream);
+ });
+
+ request.send(cb);
+};
+
+module.exports = Transloadit;
View
18 package.json
@@ -0,0 +1,18 @@
+{
+ "author": "Ian Hansen <ian@supershabam.com>",
+ "name": "transloadit",
+ "description": "A transloadit client library that runs callbacks when they're actually done",
+ "version": "0.0.0",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/SuperShabam/transloadit.git"
+ },
+ "dependencies": {
+ "multiparter": "~0.1.4"
+ },
+ "devDependencies": {},
+ "optionalDependencies": {},
+ "engines": {
+ "node": "*"
+ }
+}

0 comments on commit aba400a

Please sign in to comment.