Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions lib/client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function () {
'use strict';
var https = require('https'),
const https = require('https'),
pjson = require('../package.json'),
Xml2js = require('xml2js'),
parser = new Xml2js.Parser({explicitArray: false});
Expand All @@ -9,31 +9,34 @@
config.RECURLY_HOST = config.SUBDOMAIN + '.recurly.com';
return {

request: function (route, callback, data) {
var endpoint = route[0];
var method = route[1];
var that = this;
var options = {
request: function (route, callback, data,customHeaders) {
const endpoint = route[0];
const method = route[1];
const that = this;
const options = {
host: config.RECURLY_HOST,
port: 443,
path: endpoint,
method: method,
headers: {
Authorization: "Basic " + (new Buffer(config.API_KEY)).toString('base64'),
Accept: 'application/xml',
'Content-Length': (data) ? data.length : 0,
'Content-Length': (data) ? Buffer.byteLength(data, 'utf-8') : 0,
'User-Agent': "node-recurly/" + pjson.version
}
};

if (method.toLowerCase() === 'post' || method.toLowerCase() === 'put') {
options.headers['Content-Type'] = 'application/xml';
options.headers['Content-Type'] = 'application/xml; charset=utf-8';
that.debug(data);
}
if(endpoint.lastIndexOf('shipping_addresses') !== -1 || (customHeaders &&customHeaders.API_VERSION)) {
options.headers['X-Api-Version'] = (customHeaders && customHeaders.API_VERSION)? customHeaders.API_VERSION:2.4;
}
that.debug(options);
var req = https.request(options, function (res) {
const req = https.request(options, function (res) {

var responsedata = '';
let responsedata = '';
res.on('data', function (d) {
responsedata += d;
});
Expand Down Expand Up @@ -93,7 +96,7 @@
// backward compatibility for not node.js style callbacks
// TBD: skip in next version?
else if (callback.length === 1) {
var toreturn = {status: 'ok', data: '', headers: res ? res.headers : null };
let toreturn = {status: 'ok', data: '', headers: res ? res.headers : null };
if (err) {
toreturn.status = 'error';
if (!res || err === Error || err instanceof Error) {
Expand Down
Loading