@@ -4,13 +4,12 @@ const urlObject = require('./buildURL');
4
4
const { getRequest } = require ( './request' ) ;
5
5
6
6
const findItemsByKeywords = function ( options ) {
7
- if ( ! options || ! options . keywords ) {
7
+ if ( ! options ) {
8
8
throw new Error ( 'Keyword is missing, Keyword is required' ) ;
9
9
}
10
-
11
10
this . options . operationName = 'findItemsByKeywords' ;
12
11
this . options . param = 'keywords' ;
13
-
12
+ // support only keyword string.
14
13
if ( ! options . keywords ) {
15
14
this . options . name = options ;
16
15
}
@@ -42,6 +41,11 @@ const findItemsByCategory = function (categoryID) {
42
41
) ;
43
42
} ;
44
43
44
+ /**
45
+ * searches for items whose listings are completed and are no longer available for
46
+ * sale by category (using categoryId), by keywords (using keywords), or a combination of the two.
47
+ * @param {Object } options
48
+ */
45
49
const findCompletedItems = function ( options ) {
46
50
if ( ! options ) throw new Error ( 'Keyword or category ID are required.' ) ;
47
51
if ( ! options . keywords && ! options . categoryId ) throw new Error ( 'Keyword or category ID are required.' ) ;
@@ -58,6 +62,7 @@ const findCompletedItems = function (options) {
58
62
) ;
59
63
} ;
60
64
65
+
61
66
const getVersion = function ( ) {
62
67
this . options . operationName = 'getVersion' ;
63
68
const url = urlObject . buildSearchUrl ( this . options ) ;
@@ -67,6 +72,24 @@ const getVersion = function () {
67
72
) ;
68
73
} ;
69
74
75
+ /**
76
+ * Searches for items on eBay using specific eBay product values.
77
+ * @param {Object } options
78
+ */
79
+ const findItemsByProduct = function ( options ) {
80
+ if ( ! options ) throw new Error ( 'Please enter the Valid input.' ) ;
81
+ if ( ! options . productId ) throw new Error ( 'Product ID is required.' ) ;
82
+ this . options . operationName = 'findItemsByProduct' ;
83
+ this . options . additionalParam = constructAdditionalParams ( options ) ;
84
+ let url = urlObject . buildSearchUrl ( this . options ) ;
85
+ url = `${ url } &productId.@type=ReferenceID` ;
86
+ return getRequest ( url ) . then ( ( data ) => {
87
+ return JSON . parse ( data ) . findItemsByProductResponse ;
88
+
89
+ } , console . error
90
+ ) ;
91
+ } ;
92
+
70
93
const constructAdditionalParams = ( options ) => {
71
94
let params = '' ;
72
95
let count = 0 ;
@@ -75,7 +98,7 @@ const constructAdditionalParams = (options) => {
75
98
if ( key === 'entriesPerPage' || key === 'pageNumber' ) {
76
99
params = `${ params } paginationInput.${ key } =${ options [ key ] } &` ;
77
100
}
78
- else if ( key === 'keywords' || key === 'categoryId' || key === 'sortOrder' ) {
101
+ else if ( key === 'keywords' || key === 'categoryId' || key === 'productId' || key === ' sortOrder') {
79
102
params = `${ params } ${ key } =${ options [ key ] } &` ;
80
103
}
81
104
else {
@@ -95,5 +118,6 @@ module.exports = {
95
118
findItemsByCategory,
96
119
findCompletedItems,
97
120
constructAdditionalParams,
121
+ findItemsByProduct,
98
122
getVersion
99
123
} ;
0 commit comments