Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix module cluttering global namespace #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 17 additions & 17 deletions lib/base.js
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -65,15 +65,15 @@ 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;
this.required = required;
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;
Expand All @@ -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;
Expand All @@ -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<event.length;i++){
Expand All @@ -146,7 +146,7 @@ Say = function(value, as, event, name, required, voice, allowSignals) {
};

//TODO: Complete Session object.
Session = function(json) {
function Session(json) {
var session = JSON.parse(json);
this.id = session.session.id;
this.accountId = session.session.accountId;
Expand All @@ -161,7 +161,7 @@ Session = function(json) {
return this;
};

StartRecording = function(format, method, url, username, password, transcriptionID, transcriptionEmailFormat, transcriptionOutURI) {
function StartRecording(format, method, url, username, password, transcriptionID, transcriptionEmailFormat, transcriptionOutURI) {
this.format = format;
this.method = method;
this.url = url;
Expand All @@ -172,9 +172,9 @@ StartRecording = function(format, method, url, username, password, transcription
this.transcriptionOutURI = transcriptionOutURI;
};

StopRecording = function() {};
function StopRecording() {};

Transfer = function(to, answerOnMedia, choices, from, headers, name, on, required, terminator, timeout, allowSignals, interdigitTimeout, ringRepeat) {
function Transfer(to, answerOnMedia, choices, from, headers, name, on, required, terminator, timeout, allowSignals, interdigitTimeout, ringRepeat) {
this.to = to;
this.answerOnMedia = answerOnMedia;
this.choices = serializeProperty(choices);
Expand All @@ -190,7 +190,7 @@ Transfer = function(to, answerOnMedia, choices, from, headers, name, on, require
this.ringRepeat = ringRepeat;
};

Wait = function(milliseconds, allowSignals){
function Wait(milliseconds, allowSignals){
this.milliseconds = milliseconds;
this.allowSignals = allowSignals;
};
Expand Down
8 changes: 4 additions & 4 deletions lib/tropo-provisioning.js
Expand Up @@ -5,7 +5,7 @@ var base = require('./base');
var provisioningUrlHost = 'api.tropo.com';
var provisioningUrlPath = '/v1/';

TropoProvision = function(userid, password) {
function TropoProvision(userid, password) {
this.userid = userid;
this.password = password;
};
Expand Down Expand Up @@ -111,7 +111,7 @@ TropoProvision.prototype.makeApiCall = function(method, host, path, payload) {
exports.TropoProvision = TropoProvision;

// Objects representing provisioning resources.
Application = function(href, name, voiceUrl, messagingUrl, platform, partition) {
function Application(href, name, voiceUrl, messagingUrl, platform, partition) {
this.href = href;
this.name = name;
this.voiceUrl = voiceUrl;
Expand All @@ -121,7 +121,7 @@ Application = function(href, name, voiceUrl, messagingUrl, platform, partition)

};

Address = function(type, prefix, number, city, state, channel, username, password, token) {
function Address(type, prefix, number, city, state, channel, username, password, token) {
this.type = type;
this.prefix = prefix;
this.city = city;
Expand All @@ -132,7 +132,7 @@ Address = function(type, prefix, number, city, state, channel, username, passwor
this.token = token;
};

Exchange = function(prefix, city, state, country) {
function Exchange(prefix, city, state, country) {
this.prefix = prefix;
this.city = city;
this.state = state;
Expand Down
2 changes: 1 addition & 1 deletion lib/tropo-session.js
Expand Up @@ -4,7 +4,7 @@ var https = require('https');
var sessionUrlHost = 'api.tropo.com';
var sessionUrlPath = '/1.0/sessions?action=create&token=';

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

Expand Down
10 changes: 6 additions & 4 deletions lib/tropo-webapi.js
Expand Up @@ -4,7 +4,7 @@ var base = require('./base');
* Primary Tropo WebAPI class and prototype methods.
*
*/
TropoWebAPI = function() {
function TropoWebAPI() {
this.tropo = new Array();
};

Expand Down Expand Up @@ -84,13 +84,13 @@ exports.TropoWebAPI = TropoWebAPI;
* Helper class to render JSON for Tropo WebAPI.
*
*/
TropoJSON = function(object) {
function TropoJSON(object) {
return JSON.stringify(object).replace(/\\/g, "").replace(/"{/g, "{").replace(/}"/g, "}");
};
exports.TropoJSON = TropoJSON;

//TODO: Complete header method.
Headers = function() {
function Headers () {

};
exports.Headers = Headers;
Expand All @@ -100,4 +100,6 @@ function serializeObject(name, object) {
return "{ \"" + name + "\":" + JSON.stringify(object, base.replaceNull) + "}";
}


Object.keys(base).forEach(function (k) {
exports[k] = base[k];
});
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "tropo-webapi",
"description": "A Node.js library for the Tropo WebAPI.",
"version": "1.0.17",
"version": "1.0.18",
"homepage": "http://tropo.com",
"author": "Mark Headd <mheadd@voxeo.com> (http://tropo.com)",
"main": "./lib/tropo-webapi",
Expand Down
4 changes: 2 additions & 2 deletions samples/express/say-ask.js
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions samples/resource-routing.js
Expand Up @@ -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){
Expand All @@ -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);
Expand All @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions samples/say-ask.js
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions samples/say-event-ask.js
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions samples/use-result.js
Expand Up @@ -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'});
Expand All @@ -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'});
Expand Down
2 changes: 1 addition & 1 deletion samples/use-session.js
Expand Up @@ -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();
Expand Down