2
2
3
3
const urlObject = require ( './buildURL' ) ;
4
4
const { getRequest } = require ( './request' ) ;
5
+ const utils = require ( './common-utils/index' ) ;
5
6
const FIND_ITEMS_BY_KEYWORD = 'findItemsByKeywords' ;
6
7
const FIND_ITEMS_BY_CATEGORY = 'findItemsByCategory' ;
7
8
const FIND_COMPLETED_ITEMS = 'findCompletedItems' ;
8
9
const FIND_ITEMS_ADV = 'findItemsAdvanced' ;
10
+ const FIND_EBAY_STORES = 'findItemsIneBayStores' ;
9
11
10
12
const findItemsByKeywords = function ( options ) {
11
13
if ( ! options ) {
@@ -16,7 +18,7 @@ const findItemsByKeywords = function (options) {
16
18
// support only keyword string.
17
19
if ( ! options . keywords ) options = { keywords : options } ;
18
20
options . keywords = encodeURIComponent ( options . keywords ) ;
19
- this . options . additionalParam = constructAdditionalParams ( options ) ;
21
+ this . options . additionalParam = utils . constructAdditionalParams ( options ) ;
20
22
const url = urlObject . buildSearchUrl ( this . options ) ;
21
23
return getRequest ( url ) . then ( ( data ) => {
22
24
return JSON . parse ( data ) . findItemsByKeywordsResponse ;
@@ -48,7 +50,7 @@ const findCompletedItems = function (options) {
48
50
options . keywords = encodeURIComponent ( options . keywords ) ;
49
51
}
50
52
this . options . operationName = FIND_COMPLETED_ITEMS ;
51
- this . options . additionalParam = constructAdditionalParams ( options ) ;
53
+ this . options . additionalParam = utils . constructAdditionalParams ( options ) ;
52
54
const url = urlObject . buildSearchUrl ( this . options ) ;
53
55
return getRequest ( url ) . then ( ( data ) => {
54
56
return JSON . parse ( data ) . findCompletedItemsResponse ;
@@ -69,8 +71,9 @@ const findItemsAdvanced = function (options) {
69
71
options . keywords = encodeURIComponent ( options . keywords ) ;
70
72
}
71
73
this . options . operationName = FIND_ITEMS_ADV ;
72
- this . options . additionalParam = constructAdditionalParams ( options ) ;
74
+ this . options . additionalParam = utils . constructAdditionalParams ( options ) ;
73
75
const url = urlObject . buildSearchUrl ( this . options ) ;
76
+ console . log ( url ) ;
74
77
return getRequest ( url ) . then ( ( data ) => {
75
78
return JSON . parse ( data ) . findItemsAdvancedResponse ;
76
79
} , console . error // eslint-disable-line no-console
@@ -96,57 +99,36 @@ const findItemsByProduct = function (options) {
96
99
if ( ! options . productId ) throw new Error ( 'INVALID_REQUEST_PARMS --> Product ID is required.' ) ;
97
100
let type = options . type ? options . type : 'ReferenceID' ;
98
101
this . options . operationName = 'findItemsByProduct' ;
99
- this . options . additionalParam = constructAdditionalParams ( options ) ;
102
+ this . options . additionalParam = utils . constructAdditionalParams ( options ) ;
100
103
let url = urlObject . buildSearchUrl ( this . options ) ;
101
104
url = `${ url } &productId.@type=${ type } ` ;
105
+ console . log ( url ) ;
102
106
return getRequest ( url ) . then ( ( data ) => {
103
107
return JSON . parse ( data ) . findItemsByProductResponse ;
104
108
105
109
} , console . error // eslint-disable-line no-console
106
110
) ;
107
111
} ;
108
112
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 ;
109
121
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
+ ) ;
142
124
} ;
143
125
144
126
module . exports = {
145
127
findItemsByKeywords,
146
128
findItemsByCategory,
147
129
findCompletedItems,
148
- constructAdditionalParams,
149
130
findItemsByProduct,
150
131
findItemsAdvanced,
132
+ findItemsIneBayStores,
151
133
getVersion
152
134
} ;
0 commit comments