Browse files

[api] Update for node 0.4.0

  • Loading branch information...
1 parent 0dad6a4 commit f541f26ec9b77b73d9171066715fb02132fe9cad @indexzero indexzero committed Feb 11, 2011
Showing with 27 additions and 19 deletions.
  1. +27 −19 lib/chargify/client.js
View
46 lib/chargify/client.js
@@ -1,6 +1,6 @@
require.paths.unshift(__dirname+'/../');
-var http = require ('http'),
+var https = require ('https'),
events = require ('events'),
querystring = require ('querystring');
@@ -196,12 +196,8 @@ function Client (httpClient) {
};
function SimpleHttpClient(username, password, host){
- var auth = 'Basic ' + base64.encode(username + ':' + password);
- var createClient = function(){
- return http.createClient(443, host, true)
- };
-
- var self = this;
+ var auth = 'Basic ' + base64.encode(username + ':' + password),
+ self = this;
['delete', 'get', 'post', 'put'].forEach(function(method){
self[method] = function(path, body, cb){
@@ -210,20 +206,32 @@ function SimpleHttpClient(username, password, host){
});
var makeRequest = function(method, path, body, cb) {
- var req =createClient().request(method, path, {host:host,
- 'Content-Length':body.length,
- 'Content-Type':'application/json',
- 'Authorization':auth})
- req.end(body)
- req.on('response', function(resp){
+ var options = {
+ host: host,
+ method: method,
+ path: path,
+ port: 443,
+ headers: {
+ host:host,
+ 'Content-Length': body.length,
+ 'Content-Type': 'application/json',
+ 'Authorization': auth
+ }
+ }
+
+ var req = https.request(options, function (res) {
var buffer = ""
- resp.on('data', function(data){
+
+ res.on('data', function(data){
buffer += data.toString()
- })
- resp.on('end', function(){
- cb(resp.headers.status, buffer)
- })
- })
+ });
+
+ res.on('end', function(){
+ cb(res.headers.status, buffer)
+ });
+ });
+
+ req.end(body);
};
};

0 comments on commit f541f26

Please sign in to comment.