Skip to content

Commit

Permalink
[api] Update for node 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Feb 11, 2011
1 parent 0dad6a4 commit f541f26
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions lib/chargify/client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require.paths.unshift(__dirname+'/../');

var http = require ('http'),
var https = require ('https'),
events = require ('events'),
querystring = require ('querystring');

Expand Down Expand Up @@ -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){
Expand All @@ -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);
};
};

Expand Down

0 comments on commit f541f26

Please sign in to comment.