Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
78 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea | ||
node_modules | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,81 @@ | ||
var Compose = require('compose'); | ||
|
||
(function() { | ||
var _add = function(res, type, attrs, body) { | ||
var buf = res._buf; | ||
function _add(res, type, attrs, body) { | ||
var buf = res._buf; | ||
|
||
buf.push('<', type); | ||
buf.push('<', type); | ||
|
||
if (attrs) { | ||
for (var key in attrs) { | ||
if (attrs.hasOwnProperty(key)) { | ||
buf.push(' ', key, '="', attrs[key], '"'); | ||
} | ||
if (attrs) { | ||
for (var key in attrs) { | ||
if (attrs.hasOwnProperty(key)) { | ||
buf.push(' ', key, '="', attrs[key], '"'); | ||
} | ||
} | ||
} | ||
|
||
if (body) { | ||
buf.push('>'); | ||
buf.push(typeof body === 'function' ? body(res) : body); | ||
buf.push('</', type, '>'); | ||
} else { | ||
buf.push(' />'); | ||
} | ||
if (body) { | ||
buf.push('>'); | ||
buf.push(typeof body === 'function' ? body(res) : body); | ||
buf.push('</', type, '>'); | ||
} else { | ||
buf.push(' />'); | ||
} | ||
} | ||
|
||
var Response = module.exports = Compose(function(res, app) { | ||
this._app = app; | ||
this._buf = []; | ||
this._res = res; | ||
}, { | ||
send: function(res) { | ||
res || (res = this._res); | ||
res.header('Content-Type', 'text/xml'); | ||
res.send('<Response>' + this._buf.join('') + '</Response>'); | ||
return this; | ||
}, | ||
var Response = module.exports = Compose(function(res, app) { | ||
this._app = app; | ||
this._res = res; | ||
this._buf = []; | ||
}, { | ||
toString: function() { | ||
|
||
dtmf: function(digits) { | ||
_add(this, 'DTMF', null, digits); | ||
return this; | ||
}, | ||
}, | ||
|
||
getDigits: function(opts, body) { | ||
if (this._app && !opts.action.match(/\/\//)) { | ||
opts.action = this._app._rootUrl.href + opts.action; | ||
} | ||
send: function(res) { | ||
res || (res = this._res); | ||
res.header('Content-Type', 'text/xml'); | ||
res.send(['<Response>', this._buf.join(''), '</Response>'].join('')); | ||
return this; | ||
}, | ||
|
||
dtmf: function(digits) { | ||
_add(this, 'DTMF', null, digits); | ||
return this; | ||
}, | ||
|
||
_add(this, 'GetDigits', opts, body); | ||
return this; | ||
}, | ||
getDigits: function(opts, body) { | ||
if (this._app && !opts.action.match(/\/\//)) { | ||
opts.action = this._app.rootUrl.href + opts.action; | ||
} | ||
|
||
dialNumber: function(number, dialOpts, numberOpts) { | ||
_add(this, 'Dial', dialOpts, function() { | ||
_add(this, 'Number', numberOpts, number); | ||
}); | ||
return this; | ||
}, | ||
_add(this, 'GetDigits', opts, body); | ||
return this; | ||
}, | ||
|
||
hangup: function(opts) { | ||
_add(this, 'Hangup', opts); | ||
return this; | ||
}, | ||
dialNumber: function(number, dialOpts, numberOpts) { | ||
_add(this, 'Dial', dialOpts, function() { | ||
_add(this, 'Number', numberOpts, number); | ||
}); | ||
return this; | ||
}, | ||
|
||
message: function(src, dest, msg) { | ||
_add(this, 'Message', { src: src, dest: dest }, msg); | ||
return this; | ||
}, | ||
hangup: function(opts) { | ||
_add(this, 'Hangup', opts); | ||
return this; | ||
}, | ||
|
||
play: function(url, opts) { | ||
_add(this, 'Play', opts, url); | ||
return this; | ||
}, | ||
message: function(src, dest, msg) { | ||
_add(this, 'Message', { src: src, dest: dest }, msg); | ||
return this; | ||
}, | ||
|
||
wait: function(length) { | ||
_add(this, 'Wait', length && { length: length }); | ||
return this; | ||
} | ||
}); | ||
})(); | ||
play: function(url, opts) { | ||
_add(this, 'Play', opts, url); | ||
return this; | ||
}, | ||
|
||
wait: function(length) { | ||
_add(this, 'Wait', length && { length: length }); | ||
return this; | ||
} | ||
}); |