Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[api] Update for node 0.4.0

  • Loading branch information...
commit f541f26ec9b77b73d9171066715fb02132fe9cad 1 parent 0dad6a4
Charlie Robbins indexzero authored

Showing 1 changed file with 27 additions and 19 deletions. Show diff stats Hide diff stats

  1. +27 19 lib/chargify/client.js
46 lib/chargify/client.js
... ... @@ -1,6 +1,6 @@
1 1 require.paths.unshift(__dirname+'/../');
2 2
3   -var http = require ('http'),
  3 +var https = require ('https'),
4 4 events = require ('events'),
5 5 querystring = require ('querystring');
6 6
@@ -196,12 +196,8 @@ function Client (httpClient) {
196 196 };
197 197
198 198 function SimpleHttpClient(username, password, host){
199   - var auth = 'Basic ' + base64.encode(username + ':' + password);
200   - var createClient = function(){
201   - return http.createClient(443, host, true)
202   - };
203   -
204   - var self = this;
  199 + var auth = 'Basic ' + base64.encode(username + ':' + password),
  200 + self = this;
205 201
206 202 ['delete', 'get', 'post', 'put'].forEach(function(method){
207 203 self[method] = function(path, body, cb){
@@ -210,20 +206,32 @@ function SimpleHttpClient(username, password, host){
210 206 });
211 207
212 208 var makeRequest = function(method, path, body, cb) {
213   - var req =createClient().request(method, path, {host:host,
214   - 'Content-Length':body.length,
215   - 'Content-Type':'application/json',
216   - 'Authorization':auth})
217   - req.end(body)
218   - req.on('response', function(resp){
  209 + var options = {
  210 + host: host,
  211 + method: method,
  212 + path: path,
  213 + port: 443,
  214 + headers: {
  215 + host:host,
  216 + 'Content-Length': body.length,
  217 + 'Content-Type': 'application/json',
  218 + 'Authorization': auth
  219 + }
  220 + }
  221 +
  222 + var req = https.request(options, function (res) {
219 223 var buffer = ""
220   - resp.on('data', function(data){
  224 +
  225 + res.on('data', function(data){
221 226 buffer += data.toString()
222   - })
223   - resp.on('end', function(){
224   - cb(resp.headers.status, buffer)
225   - })
226   - })
  227 + });
  228 +
  229 + res.on('end', function(){
  230 + cb(res.headers.status, buffer)
  231 + });
  232 + });
  233 +
  234 + req.end(body);
227 235 };
228 236 };
229 237

0 comments on commit f541f26

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