@@ -6,15 +6,13 @@ const getItem = function (itemId) {
66 const auth = "Bearer " + this . options . access_token ;
77 const id = encodeURIComponent ( itemId ) ;
88 return makeRequest ( 'api.ebay.com' , `/buy/browse/v1/item/${ id } ` , 'GET' , this . options . body , auth ) . then ( ( result ) => {
9- console . log ( "Success" ) ;
109 let resultJSON = JSON . parse ( result ) ;
1110 //this.setAccessToken(resultJSON);
1211 return resultJSON ;
1312 } ) ;
1413} ;
1514
1615const getItemByLegacyId = function ( legacyOptions ) {
17- console . log ( legacyOptions ) ;
1816 if ( ! legacyOptions ) throw new Error ( "Error Required input to get Items By LegacyID" ) ;
1917 if ( ! this . options . access_token ) throw new Error ( "Missing Access token, Generate access token" ) ;
2018 if ( ! legacyOptions . legacyItemId ) throw new Error ( "Error Legacy Item Id is required" ) ;
@@ -24,7 +22,6 @@ const getItemByLegacyId = function (legacyOptions) {
2422
2523 makeRequest ( 'api.ebay.com' , `/buy/browse/v1/item/get_item_by_legacy_id?${ param } ` , 'GET' , this . options . body , auth ) . then ( ( result ) => {
2624 let resultJSON = JSON . parse ( result ) ;
27- //this.setAccessToken(resultJSON);
2825 return resultJSON ;
2926 } ) . then ( ( error ) => {
3027 console . log ( error . errors ) ;
@@ -39,28 +36,27 @@ const getItemByItemGroup = function (itemGroupId) {
3936 const auth = "Bearer " + this . options . access_token ;
4037 return new Promise ( ( resolve , reject ) => {
4138 makeRequest ( 'api.ebay.com' , `/buy/browse/v1/item/get_items_by_item_group?item_group_id=${ itemGroupId } ` , 'GET' , this . options . body , auth ) . then ( ( result ) => {
42- resolve ( JSON . parse ( result ) ) ;
39+ resolve ( result ) ;
4340 } ) ;
4441 } )
4542} ;
4643
4744const searchItems = function ( searchConfig ) {
48- console . log ( searchConfig . keyword ) ;
4945 if ( ! searchConfig ) throw new Error ( "Error --> Missing or invalid input parameter to search" ) ;
5046 if ( ! searchConfig . keyword && ! searchConfig . categoryId ) throw new Error ( "Error --> Keyword or category id is required in query param" ) ;
5147 if ( ! this . options . access_token ) throw new Error ( "Error -->Missing Access token, Generate access token" ) ;
52- if ( searchConfig . fieldgroups . length > 0 && ! Array . isArray ( searchConfig . fieldgroups ) ) throw new Error ( "Error -->Field groups should be an array" ) ;
5348 const auth = "Bearer " + this . options . access_token ;
54- let queryParam = searchConfig . keyword ? "q=" + searchConfig . keyword + "&" : "" ;
55- queryParam = queryParam + searchConfig . categoryId ? "category_ids=" + searchConfig . categoryId + "&" : '' ;
56- queryParam = queryParam + searchConfig . limit ? "limit=" + searchConfig . limit + "&" : "" ;
57- queryParam = queryParam + searchConfig . fieldgroups . length > 0 ? "fieldgroups=" + searchConfig . fieldgroups . toString ( ) + "&" : "" ;
58- queryParam = queryParam + searchConfig . filter != undefined ? "filter=" + JSON . stringify ( searchConfig . filter ) . replace ( / [ { } ] / g, "" ) : "" ;
49+ let queryParam = searchConfig . keyword ? "q=" + searchConfig . keyword : "" ;
50+ queryParam = queryParam + ( searchConfig . categoryId ? "&category_ids=" + searchConfig . categoryId : '' ) ;
51+ queryParam = queryParam + ( searchConfig . limit ? "&limit=" + searchConfig . limit : "" ) ;
52+ if ( searchConfig . fieldgroups != undefined ) queryParam = queryParam + "&fieldgroups=" + searchConfig . fieldgroups . toString ( ) ;
53+ if ( searchConfig . filter != undefined ) queryParam = queryParam + "&filter=" + JSON . stringify ( searchConfig . filter ) . replace ( / [ { } ] / g, "" ) ;
54+ console . log ( queryParam ) ;
5955 return new Promise ( ( resolve , reject ) => {
60- makeRequest ( 'api.ebay.com' , `buy/browse/v1/item_summary/search?${ queryparam } ` , 'GET' , this . options . body , auth ) . then ( ( result ) => {
61- resolve ( JSON . parse ( result ) ) ;
56+ makeRequest ( 'api.ebay.com' , `/ buy/browse/v1/item_summary/search?${ queryParam } ` , 'GET' , this . options . body , auth ) . then ( ( result ) => {
57+ resolve ( result ) ;
6258 } ) ;
63- } )
59+ } ) ;
6460} ;
6561
6662module . exports = {
0 commit comments