From eaefa15a0e6ac3db316a941691fde104750dec77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20D=C3=BC=C3=BCna?= Date: Thu, 9 May 2013 17:34:03 -0700 Subject: [PATCH 1/2] Fix tests, fix tropo cluttering global namespace --- lib/base.js | 34 +++++++++++++++---------------- lib/tropo-provisioning.js | 8 ++++---- lib/tropo-session.js | 2 +- lib/tropo-webapi.js | 10 ++++++---- package.json | 2 +- tests/tests.js | 42 +++++++++++++++++++-------------------- 6 files changed, 50 insertions(+), 48 deletions(-) diff --git a/lib/base.js b/lib/base.js index 25a05c0..d757ccf 100644 --- a/lib/base.js +++ b/lib/base.js @@ -2,7 +2,7 @@ * Tropo action classes. * */ -Ask = function(choices, attempts, bargein, minConfidence, name, recognizer, required, say, timeout, voice, interdigitTimeout, sensitivity, speechCompleteTimeout, speechIncompleteTimeout) { +function Ask(choices, attempts, bargein, minConfidence, name, recognizer, required, say, timeout, voice, interdigitTimeout, sensitivity, speechCompleteTimeout, speechIncompleteTimeout) { this.choices = (say.event !== null) ? choices : serializeProperty(choices); this.attempts = attempts; this.bargein = bargein; @@ -19,7 +19,7 @@ Ask = function(choices, attempts, bargein, minConfidence, name, recognizer, requ this.speechIncompleteTimeout = speechIncompleteTimeout; }; -Call = function(to, answerOnMedia, channel, from, headers, name, network, recording, required, timeout, allowSignals) { +function Call(to, answerOnMedia, channel, from, headers, name, network, recording, required, timeout, allowSignals) { this.to = to; this.answerOnMedia = answerOnMedia; this.channel = channel; @@ -33,13 +33,13 @@ Call = function(to, answerOnMedia, channel, from, headers, name, network, record this.allowSignals = allowSignals; }; -Choices = function(value, mode, terminator) { +function Choices(value, mode, terminator) { this.value = value; this.mode = mode; this.terminator = terminator; }; -Conference = function(id, mute, name, playTones, required, terminator, allowSignals, interdigitTimeout) { +function Conference(id, mute, name, playTones, required, terminator, allowSignals, interdigitTimeout) { this.id = id; this.mute = mute; this.name = name; @@ -50,9 +50,9 @@ Conference = function(id, mute, name, playTones, required, terminator, allowSign this.interdigitTimeout = interdigitTimeout; }; -Hangup = function() {}; +function Hangup() {}; -Message = function(say, to, answerOnMedia, channel, from, name, network, required, timeout, voice) { +function Message(say, to, answerOnMedia, channel, from, name, network, required, timeout, voice) { this.say = serializeProperty(say); this.to = to; this.answerOnMedia = answerOnMedia; @@ -65,7 +65,7 @@ Message = function(say, to, answerOnMedia, channel, from, name, network, require this.voice = voice; }; -On = function(event, name, next, required, say) { +function On(event, name, next, required, say) { this.event = event; this.name = name; this.next = next; @@ -73,7 +73,7 @@ On = function(event, name, next, required, say) { this.say = serializeProperty(say); }; -Record = function(attempts, bargein, beep, choices, format, maxSilence, maxTime, method, minConfidence, name, required, say, timeout, transcription, url, password, username, voice, allowSignals, interdigitTimeout) { +function Record(attempts, bargein, beep, choices, format, maxSilence, maxTime, method, minConfidence, name, required, say, timeout, transcription, url, password, username, voice, allowSignals, interdigitTimeout) { this.attempts = attempts; this.bargein = bargein; this.beep = beep; @@ -96,15 +96,15 @@ Record = function(attempts, bargein, beep, choices, format, maxSilence, maxTime, this.interdigitTimeout = interdigitTimeout; }; -Redirect = function(to, name, required) { +function Redirect(to, name, required) { this.to = to; this.name = name; this.required = required; }; -Reject = function() {}; +function Reject() {}; -Result = function(json) { +function Result(json) { var result = JSON.parse(json); this.sessionId = result.result.sessionId; this.callId = result.result.callId; @@ -126,7 +126,7 @@ Result = function(json) { return this; }; -Say = function(value, as, event, name, required, voice, allowSignals) { +function Say(value, as, event, name, required, voice, allowSignals) { if(event != null){ var say = new Array(); for (var i=0;i (http://tropo.com)", "main": "./lib/tropo-webapi", diff --git a/tests/tests.js b/tests/tests.js index 63f1c52..df89002 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -4,7 +4,7 @@ * ~$ node tropo-webapi-node/tests/tests.js */ -require('../lib/tropo-webapi'); +var Tropo = require('../lib/tropo-webapi'); var assert = require('assert'); var util = require('util'); @@ -37,64 +37,64 @@ util.puts('***** Test Run Complete ************'); // A test for the Tropo Say object. function sayTest(expected) { - var tropo = new TropoWebAPI(); - tropo.say("Hello, World.", null, null, true, "carmen"); - return runTest(TropoJSON(tropo), expected); + var tropo = new Tropo.TropoWebAPI(); + tropo.say("Hello, World.", null, null, null, true, "carmen"); + return runTest(Tropo.TropoJSON(tropo), expected); } // A test for the Tropo Ask object. function askTest(expected) { - var tropo = new TropoWebAPI(); - var say = new Say("Please say your account number."); - var choices = new Choices("[5 DIGITS]"); + var tropo = new Tropo.TropoWebAPI(); + var say = new Tropo.Say("Please say your account number."); + var choices = new Tropo.Choices("[5 DIGITS]"); tropo.ask(choices, null, true, null, "foo", null, true, say, 30, null); - return runTest(TropoJSON(tropo), expected); + return runTest(Tropo.TropoJSON(tropo), expected); } // A test for the Tropo Call object. function callTest(expected) { - var tropo = new TropoWebAPI(); + var tropo = new Tropo.TropoWebAPI(); tropo.call("3055195825"); - return runTest(TropoJSON(tropo), expected); + return runTest(Tropo.TropoJSON(tropo), expected); } // A test for the Tropo Conference object. function conferenceTest(expected) { - var tropo = new TropoWebAPI(); + var tropo = new Tropo.TropoWebAPI(); tropo.conference(1234, false, "foo", false, null, "#"); - return runTest(TropoJSON(tropo), expected); + return runTest(Tropo.TropoJSON(tropo), expected); } // A test for the Tropo Hangup object. function hangupTest(expected) { - var tropo = new TropoWebAPI(); + var tropo = new Tropo.TropoWebAPI(); tropo.hangup(); - return runTest(TropoJSON(tropo), expected) + return runTest(Tropo.TropoJSON(tropo), expected) } // A test for the Tropo Message object. function messageTest(expected) { - var tropo = new TropoWebAPI(); - var say = new Say("This is an announcement"); + var tropo = new Tropo.TropoWebAPI(); + var say = new Tropo.Say("This is an announcement"); tropo.message(say, "3055195825", false, "TEXT", "3055551212", null, "SMS", null, 10, "kate"); - return runTest(TropoJSON(tropo), expected) + return runTest(Tropo.TropoJSON(tropo), expected) } // A test for the Tropo Record object. function recordTest(expected) { - var tropo = new TropoWebAPI(); - var say = new Say("Please say your account number"); - var choices = new Choices("[5 DIGITS]"); + var tropo = new Tropo.TropoWebAPI(); + var say = new Tropo.Say("Please say your account number"); + var choices = new Tropo.Choices("[5 DIGITS]"); tropo.record(null, null, true, choices, null, 5, null, "POST", null, "foo", true, say); - return runTest(TropoJSON(tropo), expected) + return runTest(Tropo.TropoJSON(tropo), expected) } From d9c1599113914f8b23b674b90a750fe7769c864b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20D=C3=BC=C3=BCna?= Date: Thu, 9 May 2013 17:37:50 -0700 Subject: [PATCH 2/2] Fix samples --- samples/express/say-ask.js | 4 ++-- samples/resource-routing.js | 11 ++++++----- samples/say-ask.js | 4 ++-- samples/say-event-ask.js | 4 ++-- samples/use-result.js | 6 +++--- samples/use-session.js | 2 +- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/samples/express/say-ask.js b/samples/express/say-ask.js index 7e26ba4..34ce6ab 100644 --- a/samples/express/say-ask.js +++ b/samples/express/say-ask.js @@ -22,8 +22,8 @@ app.post('/', function(req, res){ tropo.say("Welcome to my Tropo Web API node demo."); // Demonstrates how to use the base Tropo action classes. - var say = new Say("Please enter your 5 digit zip code."); - var choices = new Choices("[5 DIGITS]"); + var say = new tropowebapi.Say("Please enter your 5 digit zip code."); + var choices = new tropowebapi.Choices("[5 DIGITS]"); // Action classes can be passes as parameters to TropoWebAPI class methods. // use the ask method https://www.tropo.com/docs/webapi/ask.htm diff --git a/samples/resource-routing.js b/samples/resource-routing.js index 1c182da..0f38aa9 100644 --- a/samples/resource-routing.js +++ b/samples/resource-routing.js @@ -20,6 +20,7 @@ var server = http.createServer(function (request, response) { // Get the pathname for the current request. var pathname = require('url').parse(request.url).pathname; + var json = null; // Add a listener for the data event (incoming data from the HTTP request) request.addListener('data', function(data){ @@ -35,13 +36,13 @@ var server = http.createServer(function (request, response) { if(pathname == '/') { // Create a new instance of the Session object and give it the JSON delivered from Tropo. - var session = Session(json); + var session = tropowebapi.Session(json); tropo.say("Welcome to my Tropo Web API node demo for " + session.userType + "."); // Demonstrates how to use the base Tropo action classes. - var say = new Say("Please enter your 5 digit zip code."); - var choices = new Choices("[5 DIGITS]"); + var say = new tropowebapi.Say("Please enter your 5 digit zip code."); + var choices = new tropowebapi.Choices("[5 DIGITS]"); // Action classes can be passes as parameters to TropoWebAPI class methods. tropo.ask(choices, 3, false, null, "foo", null, true, say, 5, null); @@ -52,8 +53,8 @@ var server = http.createServer(function (request, response) { if(pathname == '/answer') { // Create a new instance of the Session object and give it the JSON delivered from Tropo. - var result = Result(json); - zip = result.interpretation; + var result = tropowebapi.Result(json); + var zip = result.interpretation; tropo.say("Your zip code is " + zip + "."); tropo.hangup(); diff --git a/samples/say-ask.js b/samples/say-ask.js index 87f3fe5..84cdf0f 100644 --- a/samples/say-ask.js +++ b/samples/say-ask.js @@ -13,8 +13,8 @@ var server = http.createServer(function (request, response) { tropo.say("Welcome to my Tropo Web API node demo."); // Demonstrates how to use the base Tropo action classes. - var say = new Say("Please enter your 5 digit zip code."); - var choices = new Choices("[5 DIGITS]"); + var say = new tropowebapi.Say("Please enter your 5 digit zip code."); + var choices = new tropowebapi.Choices("[5 DIGITS]"); // Action classes can be passes as parameters to TropoWebAPI class methods. tropo.ask(choices, 3, false, null, "foo", null, true, say, 5, null); diff --git a/samples/say-event-ask.js b/samples/say-event-ask.js index 49d04fc..d6403ea 100644 --- a/samples/say-event-ask.js +++ b/samples/say-event-ask.js @@ -21,8 +21,8 @@ var server = http.createServer(function (request, response) { var e = new Array(e1,e2,e3); // Demonstrates how to use the base Tropo action classes. - var say = new Say("Please enter your 5 digit zip code.", null, e, null, null, null); - var choices = new Choices("[5 DIGITS]"); + var say = new tropowebapi.Say("Please enter your 5 digit zip code.", null, e, null, null, null); + var choices = new tropowebapi.Choices("[5 DIGITS]"); // Action classes can be passes as parameters to TropoWebAPI class methods. tropo.ask(choices, 3, false, null, "foo", null, true, say, 5, null); diff --git a/samples/use-result.js b/samples/use-result.js index 642a263..aa0a82a 100644 --- a/samples/use-result.js +++ b/samples/use-result.js @@ -28,8 +28,8 @@ var server = http.createServer(function (request, response) { // The path for the first step in the application flow (ask the caller for input). if(pathname == '/') { - var say = new Say("Please enter a number one through 5."); - var choices = new Choices("1,2,3,4,5"); + var say = new tropowebapi.Say("Please enter a number one through 5."); + var choices = new tropowebapi.Choices("1,2,3,4,5"); tropo.ask(choices, 3, false, null, "foo", null, true, say, 5, null); tropo.on("continue", null, '/selection', true); response.writeHead(200, {'Content-Type': 'application/json'}); @@ -41,7 +41,7 @@ var server = http.createServer(function (request, response) { if(pathname == '/selection') { // Create a new instance of the Result object and give it the JSON delivered from Tropo. - var result = Result(json); + var result = tropowebapi.Result(json); tropo.say("Your selection was, " + result.interpretation + ". Goodbye."); tropo.hangup(); response.writeHead(200, {'Content-Type': 'application/json'}); diff --git a/samples/use-session.js b/samples/use-session.js index 8114d08..3db9c52 100644 --- a/samples/use-session.js +++ b/samples/use-session.js @@ -20,7 +20,7 @@ var server = http.createServer(function (request, response) { try { // Create a new instance of the Session object and give it the JSON delivered from Tropo. - var session = Session(json); + var session = tropowebapi.Session(json); // Create a new instance of the TropoWebAPI object. var tropo = new tropowebapi.TropoWebAPI();