Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

changed to use https for REST API requests, updated to node 0.6 HTTPS…

… client API
  • Loading branch information...
commit 3ef2c4ac18e3604de4020f63cde64823bb2284e5 1 parent 5c2a246
@jharlap jharlap authored
View
26 lib/tropo-provisioning.js
@@ -1,5 +1,5 @@
var EventEmitter = require('events').EventEmitter;
-var http = require('http');
+var https = require('https');
var base = require('./base');
var provisioningUrlHost = 'api.tropo.com';
@@ -72,21 +72,25 @@ TropoProvision.prototype.makeApiCall = function(method, host, path, payload) {
var headers = {'host': host, 'Authorization': auth , 'Content-Length': payloadLength, 'Content-Type': 'application/json'};
// Set up the HTTP client, set headers and stream the JSON body.
- var tropo = http.createClient('80', host);
- var request = tropo.request(method, path, headers);
- if(payload) {
- request.write(payload);
- }
- request.end();
-
- // Process the response.
- request.on('response', function(response) {
+ var requestOptions = {
+ hostname: host,
+ port: 443,
+ method: method,
+ path: path,
+ headers: headers
+ };
+ var request = https.request(requestOptions, function(response) {
+ // Process the response.
self.emit('responseCode', response.statusCode);
response.setEncoding('utf8');
response.on('data', function(data) {
self.emit('responseBody', data.toString());
- });
+ });
});
+ if(payload) {
+ request.write(payload);
+ }
+ request.end();
};
View
32 lib/tropo-session.js
@@ -1,6 +1,6 @@
var EventEmitter = require('events').EventEmitter;
var sys = require('sys');
-var http = require('http');
+var https = require('https');
var sessionUrlHost = 'api.tropo.com';
var sessionUrlPath = '/1.0/sessions?action=create&token=';
@@ -21,21 +21,25 @@ TropoSession.prototype.makeApiCall = function(token, parameters) {
path += '&' + item + '=' + encodeURI(parameters[item]);
}
- var tropo = http.createClient(80, sessionUrlHost);
- var request = tropo.request('GET', path, {'host': sessionUrlHost});
+ var requestOptions = {
+ hostname: sessionUrlHost,
+ port: 443,
+ method: 'GET',
+ path: path,
+ headers: {'host': sessionUrlHost}
+ };
+ var request = https.request(requestOptions, function(response) {
+ response.setEncoding('utf8');
+ self.emit('responseCode', response.statusCode);
+ response.addListener('data', function (chunk) {
+ this.responseBody = chunk;
+ });
+ response.addListener('end', function() {
+ self.emit('responseBody', this.responseBody);
+ });
+ });
request.end();
-
- request.on('response', function (response) {
- response.setEncoding('utf8');
- self.emit('responseCode', response.statusCode);
- response.addListener('data', function (chunk) {
- this.responseBody = chunk;
- });
- response.addListener('end', function() {
- self.emit('responseBody', this.responseBody);
- });
- });
};
View
2  package.json
@@ -10,6 +10,6 @@
{ "type":"git", "url":"https://github.com/tropo/tropo-webapi-node" }
],
"engines": {
- "node": "> 0.1.9"
+ "node": "> 0.6.0"
}
}
View
30 tests/tests.js
@@ -6,7 +6,7 @@
require('../lib/tropo-webapi');
var assert = require('assert');
-var sys = require('sys');
+var util = require('util');
var sayExpected = '{"tropo":[{ "say":{"value":"Hello, World.","required":true,"voice":"carmen"}}]}';
var askExpected = '{"tropo":[{ "ask":{"choices":{"value":"[5 DIGITS]"},"bargein":true,"name":"foo","required":true,"say":{"value":"Please say your account number."},"timeout":30}}]}';
@@ -19,20 +19,20 @@ var recordExpected = '{"tropo":[{ "record":{"beep":true,"choices":{"value":"[5 D
var numTests = 0;
var numFailed = 0;
-sys.puts('***** Starting Test Run ************');
-sys.puts(' ');
-sys.puts('Say Test: ' + sayTest(sayExpected));
-sys.puts('Ask Test: ' + askTest(askExpected));
-sys.puts('Call Test: ' + callTest(callExpected));
-sys.puts('Conference Test: ' + conferenceTest(conferenceExpected));
-sys.puts('Hangup Test: ' + hangupTest(hangupExpected));
-sys.puts('Message Test: ' + messageTest(messageExpected));
-sys.puts('Record Test: ' + recordTest(recordExpected));
-sys.puts('');
-sys.puts('Total Tests Run: ' + numTests);
-sys.puts('Total Failed: ' + numFailed);
-sys.puts(' ');
-sys.puts('***** Test Run Complete ************');
+util.puts('***** Starting Test Run ************');
+util.puts(' ');
+util.puts('Say Test: ' + sayTest(sayExpected));
+util.puts('Ask Test: ' + askTest(askExpected));
+util.puts('Call Test: ' + callTest(callExpected));
+util.puts('Conference Test: ' + conferenceTest(conferenceExpected));
+util.puts('Hangup Test: ' + hangupTest(hangupExpected));
+util.puts('Message Test: ' + messageTest(messageExpected));
+util.puts('Record Test: ' + recordTest(recordExpected));
+util.puts('');
+util.puts('Total Tests Run: ' + numTests);
+util.puts('Total Failed: ' + numFailed);
+util.puts(' ');
+util.puts('***** Test Run Complete ************');
// A test for the Tropo Say object.
function sayTest(expected) {
Please sign in to comment.
Something went wrong with that request. Please try again.