11'use strict' ;
22let httpRequest = require ( 'https' ) ;
3- const qs = require ( 'querystring' ) ;
43
54const getRequest = ( url ) => {
65 if ( url . includes ( 'http://' ) ) httpRequest = require ( 'http' ) ;
@@ -25,22 +24,17 @@ const getRequest = (url) => {
2524 } ) ) ;
2625} ;
2726
28- const makeRequest = function postRequest ( self , endpoint , methodName , token ) {
29- let dataString = '' ;
30- if ( self . data ) {
31- dataString = self . data ;
32- }
33- else {
34- methodName === 'POST' ? dataString = qs . stringify ( self . body ) : '' ;
35- }
27+ function makeRequest ( self , endpoint , methodName , token ) {
28+ const dataString = self . body || '' ;
3629 const options = {
3730 'hostname' : self . baseUrl ,
3831 'path' : endpoint ,
3932 'method' : methodName || 'GET' ,
4033 'headers' : {
4134 'content-type' : self . contentType ? self . contentType : 'application/json' ,
42- 'authorization ' : token ,
35+ 'Authorization ' : token ,
4336 'cache-control' : 'no-cache' ,
37+ 'X-EBAY-C-MARKETPLACE-ID' : 'EBAY_US' ,
4438 ...self . headers
4539 }
4640 } ;
@@ -50,23 +44,19 @@ const makeRequest = function postRequest(self, endpoint, methodName, token) {
5044 let body = '' ;
5145 res . on ( 'data' , ( data ) => {
5246 body += data ;
53- //console.log(body);
5447 } ) ;
5548 res . on ( 'end' , ( ) => {
5649 resolve ( body ) ;
57-
5850 } ) ;
5951 res . on ( 'error' , ( error ) => {
6052 reject ( error ) ;
61-
6253 } ) ;
6354 } ) ;
6455 //console.log('request ' + dataString);
6556 if ( methodName === 'POST' ) req . write ( dataString ) ;
6657 req . end ( ) ;
6758 } ) ) ;
68- } ;
69-
59+ }
7060
7161const base64Encode = ( encodeData ) => {
7262 const buff = Buffer . from ( encodeData ) ;
0 commit comments