Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 1734bd7369b9ed363a22b1a7817a9507c75073a3 0 parents
@gmwils authored
1  .gitignore
@@ -0,0 +1 @@
+node_modules
22 LICENSE
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2011 Geoff Wilson <gmwils@gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14 Makefile
@@ -0,0 +1,14 @@
+TESTS = test/*.js
+
+test:
+ @NODE_ENV=test ./node_modules/.bin/mocha \
+ --require should \
+ $(TESTS)
+
+test-cov:
+ @TESTFLAGS=--cov $(MAKE) test
+
+lint:
+ find . -not -path '*node_modules*' -and -name '*.js' -print0 | xargs -0 jslint
+
+.PHONY: test test-cov lint
53 README.md
@@ -0,0 +1,53 @@
+# Overview
+
+This is a Node.js client for the Transloadit server, a cloud transcoder for images, video and other content.
+
+Before you get started you'll want to
+[enable API authentication](http://transloadit.com/docs/authentication).
+
+# Installation
+
+ npm install node-transloadit
+
+# API
+
+```javascript
+
+var transloadit = require('node-transloadit');
+
+var client = new transloadit('AUTH_KEY', 'AUTH_SECRET');
+
+client.send(params, ok_callback, fail_callback);
+
+```
+
+# Example
+
+```javascript
+
+var transloadit = require('node-transloadit');
+
+var client = new transloadit('AUTH_KEY', 'AUTH_SECRET');
+var params = {
+ steps: {
+ ':original': {
+ robot: '/http/import',
+ url: 'http://example.com/file.mov'
+ }
+ },
+ template_id: 'your_template_id_here'
+};
+
+client.send(params, function(ok) {
+ // success callback [optional]
+ console.log('Success: ' + JSON.stringify(ok));
+}, function(err) {
+ // error callback [optional]
+ console.log('Error: ' + JSON.stringify(err));
+});
+
+```
+
+# Authors
+
+- Geoff Wilson (gmwils@gmail.com)
1  index.js
@@ -0,0 +1 @@
+module.exports = require("./lib/client");
75 lib/client.js
@@ -0,0 +1,75 @@
+var http = require('http');
+var multi = require('multiparter');
+var crypto = require('crypto');
+var datejs = require('datejs');
+
+var API_HOST = 'api2.transloadit.com';
+var API_PATH = '/assemblies';
+
+/**
+ * Class Client
+ *
+ * @param {authKey} string Transloadit API key
+ * @param {authSecret} string Transloadit API secret
+ *
+ * @return {Client} object
+ */
+
+var Client = module.exports = function(authKey, authSecret) {
+ this.authKey = authKey;
+ this.authSecret = authSecret;
+ this.apiOptions = {
+ host: API_HOST,
+ port: 80,
+ path: API_PATH,
+ method: 'POST'
+ };
+
+};
+
+var methods = function() {
+ /**
+ * Public methods
+ */
+
+ this.send = function(params, success_cb, failure_cb) {
+ var expires_date = new Date().add({ days: 1 });
+
+ if (!params.auth) { params.auth = {}; }
+ if (!params.auth.key) { params.auth.key = this.authKey; }
+ params.auth.expires = expires_date.toISOString();
+
+ var req = new multi.request(http, this.apiOptions);
+ var json_params = JSON.stringify(params);
+ var hmac = crypto.createHmac('sha1', this.authSecret);
+ hmac.update(json_params);
+ var signature = hmac.digest('hex');
+
+ req.setParam("params", json_params);
+ req.setParam("signature", signature);
+
+ req.send(function(err, res) {
+ var body = '';
+ res.on('data', function (chunk) {
+ body += chunk;
+ });
+
+ res.on('end', function() {
+ var result = JSON.parse(body);
+ // console.log('Final data: ' + JSON.stringify(result));
+
+ if (result.ok) {
+ if (success_cb) {
+ success_cb(result);
+ }
+ } else {
+ if (failure_cb) {
+ failure_cb(result);
+ }
+ }
+ });
+ });
+ };
+};
+
+methods.call(Client.prototype);
27 package.json
@@ -0,0 +1,27 @@
+{
+ "name": "node-transloadit",
+ "version": "0.0.1",
+ "description": "Node.js client for Transloadit API",
+ "keywords": ["transloadit", "encoding", "transcoding", "video", "audio", "mp3"],
+ "author": "Geoff Wilson <gmwils@gmail.com>",
+ "engines": [ "node" ],
+ "dependencies": {
+ "multiparter": "0.1.4"
+ , "datejs": ""
+ },
+ "devDependencies": {
+ "mocha": ""
+ , "should": "0.3.2"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/gmwils/node-transloadit.git"
+ },
+ "directories": {
+ "lib": "./lib"
+ },
+ "scripts": {
+ "test": "make test"
+ },
+ "main": "./index"
+}
11 test/sanity.js
@@ -0,0 +1,11 @@
+var transloadit = require('../');
+var assert = require('assert');
+
+describe('Client creation', function() {
+ it('should create without error', function() {
+ var client = new transloadit('AUTH_KEY', 'AUTH_SECRET');
+ assert.equal(client.authKey, 'AUTH_KEY');
+ assert.equal(client.authSecret, 'AUTH_SECRET');
+ assert.equal(typeof(client.send), 'function');
+ })
+});
Please sign in to comment.
Something went wrong with that request. Please try again.