@@ -5,62 +5,83 @@ const urlObject = require('./buildURL');
55const makeString = require ( 'make-string' ) ;
66
77const 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 ) => {
1310 return JSON . parse ( data ) ;
1411 } , console . error // eslint-disable-line no-console
1512 ) ;
1613} ;
1714
1815const getUserDetails = function ( input ) {
1916 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 ) => {
2720 return JSON . parse ( data ) ;
2821 } , console . error // eslint-disable-line no-console
2922 ) ;
3023} ;
3124
3225const 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 ) => {
3932 return JSON . parse ( data ) ;
4033 } , console . error // eslint-disable-line no-console
4134 ) ;
4235} ;
4336
4437const getShippingCosts = function ( input ) {
4538 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 ) } ` ;
5541 return getRequest ( url ) . then ( ( data ) => {
5642 return JSON . parse ( data ) ;
5743 } , console . error // eslint-disable-line no-console
5844 ) ;
5945} ;
6046
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+
6180module . exports = {
6281 getAllCategories,
6382 getUserDetails,
6483 getItemStatus,
65- getShippingCosts
84+ getShippingCosts,
85+ getSingleItem,
86+ getMultipleItems
6687} ;
0 commit comments