Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


TropoProvision now emits "end" when the response from Tropo ends #12

merged 9 commits into from

3 participants


Before, TropoProvision.makeApiCall (used internally by all the TropoProvision methods) would emit responseCode and responseBody events, but there was no way for a consumer of the library to know when to stop expecting responseBody events - i.e., when the response was actually done.

This commit adds an 'end' event to TropoProvision which is called when we receive the end event on a request made against Tropo's servers.


In retrospect, having used this a bit more now, I'm not sure this was the right approach. What would you think of changing it so that the data chunks are accumulated until the end is received, and then only emit responseBody on end? I think this is how the code in tropo-session works, and I'd be happy to submit a pull request with that change in tropo-provision.



I actually like that approach a bit better. I'll pull that in if you have a chance to make that change.



Sorry for the delay, but I've made the change now so instead of emitting 'end', provisioning goes back to just emitting 'responseBody' but now accumulates chunks.

@akalsey akalsey merged commit 33027e5 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 3 deletions.
  1. +6 −2 lib/tropo-provisioning.js
  2. +0 −1  lib/tropo-session.js
8 lib/tropo-provisioning.js
@@ -91,10 +91,14 @@ TropoProvision.prototype.makeApiCall = function(method, host, path, payload) {
var request = https.request(requestOptions, function(response) {
// Process the response.
+ var data = '';
self.emit('responseCode', response.statusCode);
- response.on('data', function(data) {
- self.emit('responseBody', data.toString());
+ response.on('data', function(chunk) {
+ data = data + chunk;
+ });
+ response.on('end', function() {
+ self.emit('responseBody', data);
if(payload) {
1  lib/tropo-session.js
@@ -1,5 +1,4 @@
var EventEmitter = require('events').EventEmitter;
-var sys = require('sys');
var https = require('https');
var sessionUrlHost = '';
Something went wrong with that request. Please try again.