22
33const urlObject = require ( './buildURL' ) ;
44const { getRequest } = require ( './request' ) ;
5+ const utils = require ( './common-utils/index' ) ;
56const FIND_ITEMS_BY_KEYWORD = 'findItemsByKeywords' ;
67const FIND_ITEMS_BY_CATEGORY = 'findItemsByCategory' ;
78const FIND_COMPLETED_ITEMS = 'findCompletedItems' ;
89const FIND_ITEMS_ADV = 'findItemsAdvanced' ;
10+ const FIND_EBAY_STORES = 'findItemsIneBayStores' ;
911
1012const findItemsByKeywords = function ( options ) {
1113 if ( ! options ) {
@@ -16,7 +18,7 @@ const findItemsByKeywords = function (options) {
1618 // support only keyword string.
1719 if ( ! options . keywords ) options = { keywords : options } ;
1820 options . keywords = encodeURIComponent ( options . keywords ) ;
19- this . options . additionalParam = constructAdditionalParams ( options ) ;
21+ this . options . additionalParam = utils . constructAdditionalParams ( options ) ;
2022 const url = urlObject . buildSearchUrl ( this . options ) ;
2123 return getRequest ( url ) . then ( ( data ) => {
2224 return JSON . parse ( data ) . findItemsByKeywordsResponse ;
@@ -48,7 +50,7 @@ const findCompletedItems = function (options) {
4850 options . keywords = encodeURIComponent ( options . keywords ) ;
4951 }
5052 this . options . operationName = FIND_COMPLETED_ITEMS ;
51- this . options . additionalParam = constructAdditionalParams ( options ) ;
53+ this . options . additionalParam = utils . constructAdditionalParams ( options ) ;
5254 const url = urlObject . buildSearchUrl ( this . options ) ;
5355 return getRequest ( url ) . then ( ( data ) => {
5456 return JSON . parse ( data ) . findCompletedItemsResponse ;
@@ -69,8 +71,9 @@ const findItemsAdvanced = function (options) {
6971 options . keywords = encodeURIComponent ( options . keywords ) ;
7072 }
7173 this . options . operationName = FIND_ITEMS_ADV ;
72- this . options . additionalParam = constructAdditionalParams ( options ) ;
74+ this . options . additionalParam = utils . constructAdditionalParams ( options ) ;
7375 const url = urlObject . buildSearchUrl ( this . options ) ;
76+ console . log ( url ) ;
7477 return getRequest ( url ) . then ( ( data ) => {
7578 return JSON . parse ( data ) . findItemsAdvancedResponse ;
7679 } , console . error // eslint-disable-line no-console
@@ -96,57 +99,36 @@ const findItemsByProduct = function (options) {
9699 if ( ! options . productId ) throw new Error ( 'INVALID_REQUEST_PARMS --> Product ID is required.' ) ;
97100 let type = options . type ? options . type : 'ReferenceID' ;
98101 this . options . operationName = 'findItemsByProduct' ;
99- this . options . additionalParam = constructAdditionalParams ( options ) ;
102+ this . options . additionalParam = utils . constructAdditionalParams ( options ) ;
100103 let url = urlObject . buildSearchUrl ( this . options ) ;
101104 url = `${ url } &productId.@type=${ type } ` ;
105+ console . log ( url ) ;
102106 return getRequest ( url ) . then ( ( data ) => {
103107 return JSON . parse ( data ) . findItemsByProductResponse ;
104108
105109 } , console . error // eslint-disable-line no-console
106110 ) ;
107111} ;
108112
113+ const findItemsIneBayStores = function ( options ) {
114+ if ( ! options ) throw new Error ( 'INVALID_REQUEST_PARMS --> Please enter the Valid input.' ) ;
115+ if ( ! options . storeName ) throw new Error ( 'INVALID_REQUEST_PARMS --> Store name is required.' ) ;
116+ this . options . operationName = FIND_EBAY_STORES ;
117+ this . options . additionalParam = utils . constructAdditionalParams ( options ) ;
118+ console . log ( urlObject . buildSearchUrl ( this . options ) ) ;
119+ return getRequest ( urlObject . buildSearchUrl ( this . options ) ) . then ( ( data ) => {
120+ return JSON . parse ( data ) . findItemsIneBayStoresResponse ;
109121
110- /**
111- * Constructs query param based on some logic to support filter and aspect_filter params.
112- * output will be keywords=iphone&itemFilter(0).name=Condition&itemFilter(0).value=3000&itemFilter(1).name=FreeShippingOnly&itemFilter(1).value=true&itemFilter(2).name=SoldItemsOnly&itemFilter(2).value=true
113- * @param {Object } options
114- */
115- const constructAdditionalParams = ( options ) => {
116- let params = '' ;
117- let count = 0 ;
118- for ( let key in options ) {
119- if ( options . hasOwnProperty ( key ) ) {
120- if ( key === 'entriesPerPage' || key === 'pageNumber' ) {
121- params = `${ params } paginationInput.${ key } =${ options [ key ] } &` ;
122- }
123- else if ( key === 'keywords' || key === 'categoryId' || key === 'productId' || key === 'sortOrder' ) {
124- params = `${ params } ${ key } =${ options [ key ] } &` ;
125- }
126- else if ( key === 'affiliate' ) {
127- const innerParams = options [ key ] ;
128- for ( let innerKey in innerParams ) {
129- params = `${ params } ${ key } .${ innerKey } =${ innerParams [ innerKey ] } &` ;
130- }
131- }
132- else {
133- params = `${ params } itemFilter(${ count } ).name=${ key } &
134- itemFilter(${ count } ).value=${ options [ key ] } &` ;
135- count += 1 ;
136- }
137- }
138- }
139- // replace extra space
140- params = params . replace ( / \s / g, '' ) ;
141- return params . substring ( 0 , params . length - 1 ) ;
122+ } , console . error // eslint-disable-line no-console
123+ ) ;
142124} ;
143125
144126module . exports = {
145127 findItemsByKeywords,
146128 findItemsByCategory,
147129 findCompletedItems,
148- constructAdditionalParams,
149130 findItemsByProduct,
150131 findItemsAdvanced,
132+ findItemsIneBayStores,
151133 getVersion
152134} ;
0 commit comments