Skip to content

Commit

Permalink
Added Tropo Session API support.
Browse files Browse the repository at this point in the history
  • Loading branch information
mheadd committed Jan 24, 2011
1 parent d791103 commit b762053
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
42 changes: 42 additions & 0 deletions lib/tropo-session.js
@@ -0,0 +1,42 @@
var EventEmitter = require('events').EventEmitter;
var sys = require('sys');
var http = require('http');

var sessionUrlHost = 'api.tropo.com';
var sessionUrlPath = '/1.0/sessions?action=create&token=';

TropoSession = function() {
this.responseBody;
};

TropoSession.prototype = new EventEmitter;

TropoSession.prototype.makeApiCall = function(token, parameters) {

var self = this;

var path = sessionUrlPath + token;

for(item in parameters) {
path += '&' + item + '=' + encodeURI(parameters[item]);
}

var tropo = http.createClient(80, sessionUrlHost);
var request = tropo.request('GET', path, {'host': sessionUrlHost});

request.end();

request.on('response', function (response) {
response.setEncoding('utf8');
self.emit('responseCode', response.statusCode);
response.addListener('data', function (chunk) {
this.responseBody = chunk;
});
response.addListener('end', function() {
self.emit('responseBody', this.responseBody);
});
});

};

exports.TropoSession = TropoSession;
5 changes: 3 additions & 2 deletions package.json
@@ -1,10 +1,11 @@
{
"name": "tropo-webapi",
"description": "A Node.js library for the Tropo WebAPI.",
"version": "1.0.7",
"version": "1.0.12",
"homepage": "http://tropo.com",
"author": "Mark Headd <mheadd@voxeo.com> (http://tropo.com)",
"main": "lib/tropo-webapi",
"main": "./lib/tropo-webapi",
"directories" : { "lib" : "./lib", "samples": "./samples", "tests": "./tests" },
"repositories" : [
{ "type":"git", "url":"https://github.com/tropo/tropo-webapi-node" }
],
Expand Down

0 comments on commit b762053

Please sign in to comment.