@@ -5,62 +5,83 @@ const urlObject = require('./buildURL');
5
5
const makeString = require ( 'make-string' ) ;
6
6
7
7
const getAllCategories = function ( categoryID ) {
8
- this . options . name = categoryID ? categoryID : - 1 ;
9
- this . options . operationName = 'GetCategoryInfo' ;
10
- this . options . param = 'CategoryID' ;
11
- const url = urlObject . buildShoppingUrl ( this . options ) ;
12
- return getRequest ( url ) . then ( ( data ) => {
8
+ const requestURL = `${ urlObject . buildShoppingUrl ( this . options , 'GetCategoryInfo' ) } &${ stringifyUrl ( { 'CategoryID' : categoryID || - 1 } ) } ` ;
9
+ return getRequest ( requestURL ) . then ( ( data ) => {
13
10
return JSON . parse ( data ) ;
14
11
} , console . error // eslint-disable-line no-console
15
12
) ;
16
13
} ;
17
14
18
15
const getUserDetails = function ( input ) {
19
16
if ( ! input || typeof input !== 'object' ) throw new Error ( 'Invalid input' ) ;
20
- if ( ! input . userId ) throw new Error ( 'Invalid Input, UserId is required' ) ;
21
- this . options . operationName = 'GetUserProfile' ;
22
- this . options . param = 'UserID' ;
23
- this . options . name = input . userId ;
24
- this . options . includeSelector = input . details ? 'Details' : null ;
25
- const url = urlObject . buildShoppingUrl ( this . options ) ;
26
- return getRequest ( url ) . then ( ( data ) => {
17
+ if ( ! input . userId ) throw new Error ( 'invalid_request_error -> userId is null or invalid' ) ;
18
+ const requestUrl = `${ urlObject . buildShoppingUrl ( this . options , 'GetUserProfile' ) } &${ stringifyUrl ( input ) } ` ;
19
+ return getRequest ( requestUrl ) . then ( ( data ) => {
27
20
return JSON . parse ( data ) ;
28
21
} , console . error // eslint-disable-line no-console
29
22
) ;
30
23
} ;
31
24
32
25
const getItemStatus = function ( itemIds ) {
33
- if ( ! itemIds ) throw new Error ( 'User ID is null or invalid' ) ;
34
- this . options . operationName = 'GetItemStatus' ;
35
- this . options . param = 'ItemID' ;
36
- this . options . name = makeString ( itemIds , { braces : 'false' , quotes : 'no' } ) ;
37
- const url = urlObject . buildShoppingUrl ( this . options ) ;
38
- return getRequest ( url ) . then ( ( data ) => {
26
+ if ( ! itemIds ) throw new Error ( 'invalid_request_error -> itemIds is null or invalid' ) ;
27
+ const paramsObj = {
28
+ 'ItemID' : makeString ( itemIds , { braces : 'false' , quotes : 'no' } )
29
+ } ;
30
+ const requestUrl = ` ${ urlObject . buildShoppingUrl ( this . options , 'GetItemStatus' ) } & ${ stringifyUrl ( paramsObj ) } ` ;
31
+ return getRequest ( requestUrl ) . then ( ( data ) => {
39
32
return JSON . parse ( data ) ;
40
33
} , console . error // eslint-disable-line no-console
41
34
) ;
42
35
} ;
43
36
44
37
const getShippingCosts = function ( input ) {
45
38
if ( ! input || typeof input !== 'object' ) throw new Error ( 'Invalid input' ) ;
46
- if ( ! input . itemId ) throw new Error ( 'Item ID is null or invalid' ) ;
47
- this . options . operationName = 'GetShippingCosts' ;
48
- this . options . param = 'ItemID' ;
49
- this . options . name = input . itemId ;
50
- const countryCodeParam = input . destCountryCode ? '&DestinationCountryCode=' + input . destCountryCode : '' ;
51
- const postalCodeParam = input . destPostalCode ? '&DestinationPostalCode=' + input . destPostalCode : '' ;
52
- const params = countryCodeParam + postalCodeParam ;
53
- let url = urlObject . buildShoppingUrl ( this . options ) ;
54
- url = url + params ;
39
+ if ( ! input . itemId ) throw new Error ( 'invalid_request_error -> Item id is null or invalid' ) ;
40
+ const url = `${ urlObject . buildShoppingUrl ( this . options , 'GetShippingCosts' ) } &${ stringifyUrl ( input ) } ` ;
55
41
return getRequest ( url ) . then ( ( data ) => {
56
42
return JSON . parse ( data ) ;
57
43
} , console . error // eslint-disable-line no-console
58
44
) ;
59
45
} ;
60
46
47
+ /**
48
+ * @method getMultipleItems {Function}
49
+ * Retrieves publicly visible details about for one or more listings on eBay.
50
+ * @param {Object } options (required)
51
+ */
52
+ const getMultipleItems = function ( options ) {
53
+ if ( ! options || ! options . itemId ) throw new Error ( 'invalid_request_error -> Item ID is null or invalid' ) ;
54
+ const requestUrl = `${ urlObject . buildShoppingUrl ( this . options , 'GetMultipleItems' ) } &${ stringifyUrl ( { 'itemId' : makeString ( options . itemId , { braces : 'false' , quotes : 'no' } ) } ) } ` ;
55
+ return getRequest ( requestUrl ) . then ( ( data ) => {
56
+ return JSON . parse ( data ) ;
57
+ } , console . error // eslint-disable-line no-console
58
+ ) ;
59
+ } ;
60
+
61
+
62
+ /**
63
+ * @method getSingleItem {Function}
64
+ * Retrieves publicly visible details about one listing on eBay.
65
+ * @param {String } itemId (required)
66
+ */
67
+ const getSingleItem = function ( itemId ) {
68
+ if ( ! itemId ) throw new Error ( 'invalid_request_error -> Item ID is null or invalid' ) ;
69
+ const requestUrl = `${ urlObject . buildShoppingUrl ( this . options , 'GetSingleItem' ) } &${ stringifyUrl ( { 'ItemID' : itemId } ) } ` ;
70
+ return getRequest ( requestUrl ) . then ( ( data ) => {
71
+ return JSON . parse ( data ) ;
72
+ } , console . error // eslint-disable-line no-console
73
+ ) ;
74
+ } ;
75
+
76
+ const stringifyUrl = ( obj ) => {
77
+ return makeString ( obj , { braces : 'false' , assignment : '=' , quotes : 'no' , seperator : '&' } ) ;
78
+ } ;
79
+
61
80
module . exports = {
62
81
getAllCategories,
63
82
getUserDetails,
64
83
getItemStatus,
65
- getShippingCosts
84
+ getShippingCosts,
85
+ getSingleItem,
86
+ getMultipleItems
66
87
} ;
0 commit comments