Skip to content
Browse files

Fixed bug affecting chuncked content returned from SMSified API.

  • Loading branch information...
1 parent b20a7c8 commit 0af1dfb03cff99b6c6ab4592155e77fcdf19377f @mheadd mheadd committed Sep 12, 2011
View
4 examples/check-status.js
@@ -1,10 +1,10 @@
/**
* Check the status of an SMS message.
*/
-var sys = require('sys');
+var util = require('util');
var smsified = require('../lib/smsified');
var sms = new SMSified('username', 'password');
sms.checkStatus('4075541234', '43d2f75b2bda27006200003e9b7dcf3b', function(result) {
- sys.puts(sys.inspect(result.deliveryInfoList.deliveryInfo));
+ util.puts(util.inspect(result.deliveryInfoList.deliveryInfo));
});
View
4 examples/create-subscription.js
@@ -1,10 +1,10 @@
/**
* Create a subscription for an account phone number.
*/
-var sys = require('sys');
+var util = require('util');
var smsified = require('../lib/smsified');
var sms = new SMSified('username', 'password');
sms.createSubscription('4075541234', 'outbound', 'http://path-to-somewhere', function(result) {
- sys.puts(sys.inspect(result));
+ util.puts(util.inspect(result));
});
View
6 examples/delete-subscription.js
@@ -2,15 +2,15 @@
* Delete a subscription.
*/
-var sys = require('sys');
+var util = require('util');
var smsified = require('../lib/smsified');
var sms = new SMSified('username', 'password');
sms.deleteSubscriptions('6267217aae394b5dc656ba4216082304', 'outbound', function(result) {
if(result = '204') {
- sys.puts('Subscription delted.');
+ util.puts('Subscription delted.');
}
else {
- sys.puts('Could not delete subscription.');
+ util.puts('Could not delete subscription.');
}
});
View
6 examples/process-inbound.js
@@ -1,7 +1,7 @@
/**
* Process an inbound SMS message.
*/
-var sys = require('sys');
+var util = require('util');
var http = require('http');
var smsified = require('../lib/smsified');
var port = 8000 || process.ARGS[1];
@@ -17,11 +17,11 @@ var server = http.createServer(function(req, res) {
var inbound = new InboundMessage(json);
// Access desired property of Inbound Message object.
- sys.puts('Inbound message: ' + inbound.message);
+ util.puts('Inbound message: ' + inbound.message);
});
res.writeHead(200);
res.end();
}).listen(port);
-sys.puts('Server listening on port ' + port);
+util.puts('Server listening on port ' + port);
View
4 examples/retrieve-message.js
@@ -1,10 +1,10 @@
/**
* Retrieve delivery information on a message.
*/
-var sys = require('sys');
+var util = require('util');
var smsified = require('../lib/smsified');
var sms = new SMSified('username', 'password');
sms.getMessages('02b45e3072ae5e157a12d0408bcede65', null, function(result) {
- sys.puts(sys.inspect(result));
+ util.puts(util.inspect(result));
});
View
6 examples/retrieve-messages-filter.js
@@ -2,10 +2,10 @@
* Retrieve delivery information on a set of messages, using filters to specify messages.
*/
-var sys = require('sys');
+var util = require('util');
var smsified = require('../lib/smsified');
var sms = new SMSified('username', 'password');
-sms.getMessages(null, {status: 'success', direction: 'in'}, function(result) {
- sys.puts(sys.inspect(result));
+sms.getMessages(null, {startDate: '2011-09-01', endDate: '2011-09-12'}, function(result) {
+ util.puts(util.inspect(result));
});
View
4 examples/send-message-callback.js
@@ -2,11 +2,11 @@
* Send an outbound SMS message and set a callback URL.
*/
-var sys = require('sys');
+var util = require('util');
var smsified = require('../lib/smsified');
var sms = new SMSified('username', 'password');
var options = {senderAddress: '4075541234', address: '15184761234', message: 'Hello from Node.js with another callback', notifyURL: 'http://path-to-somewhere/'};
sms.sendMessage(options, function(result) {
- sys.puts(sys.inspect(result));
+ util.puts(util.inspect(result));
});
View
4 examples/send-message.js
@@ -2,11 +2,11 @@
* Send an outbound SMS message.
*/
-var sys = require('sys');
+var util = require('util');
var smsified = require('../lib/smsified');
var sms = new SMSified('username', 'password');
var options = {senderAddress: '4075541234', address: '15184761234', message: 'Hello world from Node.js'};
sms.sendMessage(options, function(result) {
- sys.puts(sys.inspect(result));
+ util.puts(util.inspect(result));
});
View
6 examples/send-multi-message.js
@@ -1,11 +1,11 @@
/**
* Send multiple outbound SMS messages.
- * Note - please refer to output resitrctions in the SMSified documentation.
+ * Note - please refer to output restrictions in the SMSified documentation.
* http://smsified.com/sms-api-documentation#output_restrictions
*/
-var sys = require('sys');
+var util = require('util');
var smsified = require('../lib/smsified');
var messages = new Array('I love Node.js', 'I love Node.js even more', 'I love Node.js the mostest');
@@ -14,6 +14,6 @@ var sms = new SMSified('username', 'password');
for(var i=0; i<messages.length; i++) {
var options = {senderAddress: '4076541234', address: '16867541234', message: messages[i]};
sms.sendMessage(options, function(result) {
- sys.puts(sys.inspect(result));
+ util.puts(util.inspect(result));
});
}
View
6 examples/view-subscriptions.js
@@ -2,11 +2,11 @@
* View all active subscriptions.
*/
-var sys = require('sys');
+var util = require('util');
var smsified = require('../lib/smsified');
var sms = new SMSified('username', 'password');
sms.viewSubscriptions('4075541234', 'outbound', function(result) {
- sys.puts('Number of subscriptions: ' + result.outboundSubscriptionList.numberOfSubscriptions);
- sys.puts(sys.inspect(result.outboundSubscriptionList.outboundSubscription));
+ util.puts('Number of subscriptions: ' + result.outboundSubscriptionList.numberOfSubscriptions);
+ util.puts(util.inspect(result.outboundSubscriptionList.outboundSubscription));
});
View
11 lib/smsified.js
@@ -12,7 +12,7 @@ SMSified = function(username, password) {
this.responseBody;
};
-// Send an outbmound SMS message.
+// Send an outbound SMS message.
SMSified.prototype.sendMessage = function(options, callback) {
path = '/' + this.version + '/smsmessaging/outbound/' + options.senderAddress + '/requests?address=' + options.address + '&message=' + encodeURI(options.message);
path += options.notifyURL ? '&notifyURL=' + options.notifyURL : '';
@@ -37,7 +37,7 @@ SMSified.prototype.viewSubscriptions = function(senderAddress, direction, callba
this.makeApiCall('GET', path, callback);
};
-// Delete a subscrption.
+// Delete a subscription.
SMSified.prototype.deleteSubscriptions = function(subscriptionID, direction, callback) {
path = '/' + this.version + '/smsmessaging/' + direction + '/subscriptions/' + subscriptionID;
this.makeApiCall('DELETE', path, callback);
@@ -94,9 +94,12 @@ SMSified.prototype.makeApiCall = function(method, path, callback) {
else {
self.responseBody = "";
response.setEncoding('utf8');
- response.on('data', function(data) {
- callback(JSON.parse(data));
+ response.on('data', function(chunk) {
+ self.responseBody += chunk;
});
+ response.on('end', function() {
+ callback(JSON.parse(self.responseBody));
+ });
}
});
apiCall.end();

0 comments on commit 0af1dfb

Please sign in to comment.
Something went wrong with that request. Please try again.