11//let baseURL = "http://svcs.ebay.com/services/search/FindingService/v1";
2- let configData = require ( './config' ) ;
32let makeRequest = require ( './request' ) ;
3+ let urlObject = require ( './buildURL' ) ;
44
55function Ebay ( options ) {
66 console . log ( options ) ;
@@ -13,25 +13,16 @@ function Ebay(options) {
1313}
1414
1515Ebay . prototype = {
16- buildAPIUrl : function ( keyword ) {
17- let base_url = "http://svcs.ebay.com/services/search/FindingService/v1?" ;
18- base_url += "SECURITY-APPNAME=" + this . options . clientID ;
19- base_url += "&OPERATION-NAME=" + configData [ "findItemsByKeywords" ] [ "OPERATION-NAME" ] ;
20- base_url += "&SERVICE-VERSION=1.0.0&RESPONSE-DATA-FORMAT=JSON" ;
21- base_url += "&REST-PAYLOAD&keywords=" + keyword ;
22- base_url += "&paginationInput.entriesPerPage=" + this . options . limit ;
23- base_url += "&GLOBAL-ID=" + this . options . globalID ;
24-
25- return base_url ;
26- } ,
2716
2817 findItemsByKeywords : function ( keyword ) {
2918 this . options . name = keyword ;
30- let url = this . buildAPIUrl ( keyword ) ;
31- //console.log(url);
32- return makeRequest ( url ) . then ( ( result ) => {
33- console . log ( result ) ;
34- return result ;
19+ this . options . operationName = "findItemsByKeywords" ;
20+ this . options . param = "keywords" ;
21+ let url = urlObject . buildSearchUrl ( this . options , keyword ) ;
22+ console . log ( url ) ;
23+ return makeRequest ( url ) . then ( ( data ) => {
24+ let result = JSON . parse ( data ) ;
25+ return result [ "findItemsByKeywordsResponse" ] ;
3526
3627 } , ( error ) => {
3728 console . log ( error ) ;
@@ -42,8 +33,8 @@ Ebay.prototype = {
4233 getAllCategories : function ( ) {
4334 //console.log(url);
4435 return makeRequest ( "http://open.api.ebay.com/Shopping?callname=GetCategoryInfo&appid=" + this . options . clientID + "&version=967&siteid=0&CategoryID=-1&responseencoding=JSON&IncludeSelector=ChildCategories" ) . then ( ( data ) => {
45- // console.log (data);
46- return data ;
36+ let result = JSON . parse ( data ) ;
37+ return result ;
4738 } , ( error ) => {
4839 console . log ( error ) ;
4940 } )
0 commit comments