From c865821480b553c925095e10ac620f472708cb00 Mon Sep 17 00:00:00 2001 From: BL Date: Tue, 25 Feb 2020 16:58:26 +0530 Subject: [PATCH 01/10] add support for the fulfillment api --- .gitignore | 3 ++- .../getFulfillmentPolicies.js | 24 +++++++++++++++++++ lib/eBay-node-client.js | 1 + .../sell/account/fulfillmentPolicy.js | 14 +++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 examples/javaScript/sell/account/fulfillmentPolicy/getFulfillmentPolicies.js create mode 100644 lib/resources/sell/account/fulfillmentPolicy.js diff --git a/.gitignore b/.gitignore index efcdb7c..e25cd54 100644 --- a/.gitignore +++ b/.gitignore @@ -64,4 +64,5 @@ typings/ .idea #Temp Directory -temp/* \ No newline at end of file +temp/* +.DS_Store \ No newline at end of file diff --git a/examples/javaScript/sell/account/fulfillmentPolicy/getFulfillmentPolicies.js b/examples/javaScript/sell/account/fulfillmentPolicy/getFulfillmentPolicies.js new file mode 100644 index 0000000..8df1ac1 --- /dev/null +++ b/examples/javaScript/sell/account/fulfillmentPolicy/getFulfillmentPolicies.js @@ -0,0 +1,24 @@ +'use strict'; + +var clientId = process.env.EBAY_CLIENT_ID || 'YOUR_KEY'; +var clientSecret = process.env.EBAY_CLIENT_SECRET || 'YOUR_SECRET'; + +var eBay = require('../../../../../lib/eBay-node-client')(clientId, clientSecret); +var utils = require('../../../../javaScript/utils'); + +var accountRequest = async function () { + var userToken = utils.USER_TOKEN; + eBay.setUserToken(userToken); + var data = { + marketplace_id: 'EBAY_US' + }; + try { + var response = await eBay.fulfillmentPolicy.getFulfillmentPolicies(data); + console.log('response', response); + } catch (error) { + console.log('error ', error); + return; + } +}; + +accountRequest(); diff --git a/lib/eBay-node-client.js b/lib/eBay-node-client.js index 94456b2..d032e5a 100644 --- a/lib/eBay-node-client.js +++ b/lib/eBay-node-client.js @@ -35,6 +35,7 @@ var exec = require('child_process').exec; var resources = { account: require('./resources/sell/account'), + fulfillmentPolicy: require('./resources/sell/account/fulfillmentPolicy'), application: require('./resources/application'), browse: require('./resources/buy/browse'), catalog: require('./resources/commerce/catalog'), diff --git a/lib/resources/sell/account/fulfillmentPolicy.js b/lib/resources/sell/account/fulfillmentPolicy.js new file mode 100644 index 0000000..552dea8 --- /dev/null +++ b/lib/resources/sell/account/fulfillmentPolicy.js @@ -0,0 +1,14 @@ +'use strict'; + +var eBayResource = require('../../../eBayResource'); +var eBayMethod = eBayResource.method; + +module.exports = eBayResource.extend({ + + getFulfillmentPolicies: eBayMethod({ + authorization: 'User', + method: 'GET', + path: 'sell/account/v1/fulfillment_policy' + }) + +}); From 4cb9d42f3e8f8bad6fc877fa5af65e47c78cee11 Mon Sep 17 00:00:00 2001 From: BL Date: Tue, 25 Feb 2020 17:08:23 +0530 Subject: [PATCH 02/10] Add support for the payment policy API --- .../paymentPolicy/getPaymentPolicies.js | 24 +++++++++++++++++++ lib/eBay-node-client.js | 1 + lib/resources/sell/account/paymentPolicy.js | 14 +++++++++++ 3 files changed, 39 insertions(+) create mode 100644 examples/javaScript/sell/account/paymentPolicy/getPaymentPolicies.js create mode 100644 lib/resources/sell/account/paymentPolicy.js diff --git a/examples/javaScript/sell/account/paymentPolicy/getPaymentPolicies.js b/examples/javaScript/sell/account/paymentPolicy/getPaymentPolicies.js new file mode 100644 index 0000000..fd4a783 --- /dev/null +++ b/examples/javaScript/sell/account/paymentPolicy/getPaymentPolicies.js @@ -0,0 +1,24 @@ +'use strict'; + +var clientId = process.env.EBAY_CLIENT_ID || 'YOUR_KEY'; +var clientSecret = process.env.EBAY_CLIENT_SECRET || 'YOUR_SECRET'; + +var eBay = require('../../../../../lib/eBay-node-client')(clientId, clientSecret); +var utils = require('../../../utils'); + +var accountRequest = async function () { + var userToken = utils.USER_TOKEN; + eBay.setUserToken(userToken); + var data = { + marketplace_id: 'EBAY_US' + }; + try { + var response = await eBay.paymentPolicy.getPaymentPolicies(data); + console.log('response', response); + } catch (error) { + console.log('error ', error); + return; + } +}; + +accountRequest(); diff --git a/lib/eBay-node-client.js b/lib/eBay-node-client.js index d032e5a..f70c592 100644 --- a/lib/eBay-node-client.js +++ b/lib/eBay-node-client.js @@ -36,6 +36,7 @@ var exec = require('child_process').exec; var resources = { account: require('./resources/sell/account'), fulfillmentPolicy: require('./resources/sell/account/fulfillmentPolicy'), + paymentPolicy: require('./resources/sell/account/paymentPolicy'), application: require('./resources/application'), browse: require('./resources/buy/browse'), catalog: require('./resources/commerce/catalog'), diff --git a/lib/resources/sell/account/paymentPolicy.js b/lib/resources/sell/account/paymentPolicy.js new file mode 100644 index 0000000..bf0c4a0 --- /dev/null +++ b/lib/resources/sell/account/paymentPolicy.js @@ -0,0 +1,14 @@ +'use strict'; + +var eBayResource = require('../../../eBayResource'); +var eBayMethod = eBayResource.method; + +module.exports = eBayResource.extend({ + + getPaymentPolicies: eBayMethod({ + authorization: 'User', + method: 'GET', + path: 'sell/account/v1/payment_policy' + }) + +}); From 98da7b04c970d5aba950274fc0f8f4bb9e1ad12b Mon Sep 17 00:00:00 2001 From: BL Date: Tue, 25 Feb 2020 17:12:51 +0530 Subject: [PATCH 03/10] add supports for the return policy API --- .../account/returnPolicy/getReturnPolicies.js | 24 +++++++++++++++++++ lib/eBay-node-client.js | 2 +- lib/resources/sell/account/returnPolicy.js | 14 +++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 examples/javaScript/sell/account/returnPolicy/getReturnPolicies.js create mode 100644 lib/resources/sell/account/returnPolicy.js diff --git a/examples/javaScript/sell/account/returnPolicy/getReturnPolicies.js b/examples/javaScript/sell/account/returnPolicy/getReturnPolicies.js new file mode 100644 index 0000000..31b1e14 --- /dev/null +++ b/examples/javaScript/sell/account/returnPolicy/getReturnPolicies.js @@ -0,0 +1,24 @@ +'use strict'; + +var clientId = process.env.EBAY_CLIENT_ID || 'YOUR_KEY'; +var clientSecret = process.env.EBAY_CLIENT_SECRET || 'YOUR_SECRET'; + +var eBay = require('../../../../../lib/eBay-node-client')(clientId, clientSecret); +var utils = require('../../../utils'); + +var accountRequest = async function () { + var userToken = utils.USER_TOKEN; + eBay.setUserToken(userToken); + var data = { + marketplace_id: 'EBAY_US' + }; + try { + var response = await eBay.returnPolicy.getReturnPolicies(data); + console.log('response', response); + } catch (error) { + console.log('error ', error); + return; + } +}; + +accountRequest(); diff --git a/lib/eBay-node-client.js b/lib/eBay-node-client.js index f70c592..6649949 100644 --- a/lib/eBay-node-client.js +++ b/lib/eBay-node-client.js @@ -37,6 +37,7 @@ var resources = { account: require('./resources/sell/account'), fulfillmentPolicy: require('./resources/sell/account/fulfillmentPolicy'), paymentPolicy: require('./resources/sell/account/paymentPolicy'), + returnPolicy: require('./resources/sell/account/returnPolicy'), application: require('./resources/application'), browse: require('./resources/buy/browse'), catalog: require('./resources/commerce/catalog'), @@ -53,7 +54,6 @@ var resources = { eBay.eBayResource = require('./eBayResource'); eBay.resources = resources; - function eBay(clientId, clientSecret, isSandbox) { if (!(this instanceof eBay)) { return new eBay(clientId, clientSecret, isSandbox); diff --git a/lib/resources/sell/account/returnPolicy.js b/lib/resources/sell/account/returnPolicy.js new file mode 100644 index 0000000..3bdd04b --- /dev/null +++ b/lib/resources/sell/account/returnPolicy.js @@ -0,0 +1,14 @@ +'use strict'; + +var eBayResource = require('../../../eBayResource'); +var eBayMethod = eBayResource.method; + +module.exports = eBayResource.extend({ + + getReturnPolicies: eBayMethod({ + authorization: 'User', + method: 'GET', + path: 'sell/account/v1/return_policy' + }) + +}); From 1f4fe9bc6760493251c6b605f72e3fd092995a8a Mon Sep 17 00:00:00 2001 From: BL Date: Tue, 25 Feb 2020 17:46:42 +0530 Subject: [PATCH 04/10] Add support for the override the content language, upgrade version in package json, modify the change log, add nodejs support upto version 12 --- .npmignore | 2 +- .travis.yml | 3 +++ CHANGELOG.md | 6 ++++++ README.md | 15 +++++++++++++++ index.d.ts | 2 ++ lib/eBay-node-client.js | 10 ++++++++++ lib/eBayResource.js | 5 ++++- package.json | 4 +++- 8 files changed, 44 insertions(+), 3 deletions(-) diff --git a/.npmignore b/.npmignore index 3e59ee9..393e815 100644 --- a/.npmignore +++ b/.npmignore @@ -1,5 +1,5 @@ node_modules +node_modules/* .npm-debug.log tags -package-lock.json .idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 8f14d78..75bbadc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,4 +6,7 @@ node_js: - "7" - "8" - "9" + - "10" + - "11" + - "12" sudo: false \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 644a95c..6fdfaea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +0.0.10 + - Add support for override content language + - Add support for the fulfillment API + - Add support for the payment policy API + - Add support for the return policy API + 0.0.9 - Add support for trading APIs, shopping APIs & Finding APIs diff --git a/README.md b/README.md index a9c50e4..38df1a4 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,21 @@ const eBay = new eBay(); eBay.setApiKey('YOUR_KEY', 'YOUR_SECRET'); ``` +## Set Application Access Token +```js + eBay.setToken(token.access_token); +``` + +## Set User Token +```js + eBay.setUserToken(userToken); +``` + +## Set Content Language (Default is en-US) +```js + eBay.setContentLanguage('en-GB'); +``` + ## Pull Request - Contributors can send their Pull Request to `development` branch. - Kindly validate test cases & linting before opening new PR. diff --git a/index.d.ts b/index.d.ts index eb96ae6..b5673a8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -489,6 +489,8 @@ declare class eBayNodeClient { setDevName(devName: string): void; setCertName(certName: string): void; + + setContentLanguage(contentLanguage: string): void; } diff --git a/lib/eBay-node-client.js b/lib/eBay-node-client.js index 6649949..d66483e 100644 --- a/lib/eBay-node-client.js +++ b/lib/eBay-node-client.js @@ -181,6 +181,12 @@ eBay.prototype = { } }, + setContentLanguage: function (contentLanguage) { + if (contentLanguage) { + this._setApiField('contentLanguage', contentLanguage); + } + }, + setTimeout: function (timeout) { this._setApiField('timeout', timeout === null ? eBay.DEFAULT_TIMEOUT : timeout); }, @@ -209,6 +215,10 @@ eBay.prototype = { return this._api['certName']; }, + getContentLanguage: function () { + return this._api['contentLanguage']; + }, + getApiField: function (key) { return this._api[key]; }, diff --git a/lib/eBayResource.js b/lib/eBayResource.js index 3458d39..c0f7534 100644 --- a/lib/eBayResource.js +++ b/lib/eBayResource.js @@ -374,7 +374,10 @@ eBayResource.prototype = { 'Content-Language': 'en-US', 'authorization': authorization }; - + var contentLanguage = self._eBay.getContentLanguage(); + if (contentLanguage) { + headers['Content-Language'] = contentLanguage; + } /** * eBay Old API Implementation */ diff --git a/package.json b/package.json index 8ef2175..a811167 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ebay-node-client", - "version": "0.0.9", + "version": "0.0.10", "description": "eBay API wrapper", "keywords": [ "eBay", @@ -8,6 +8,8 @@ "eBay Inventory API", "eBay Compliance API", "eBay Fulfillment API", + "eBay Payment Policy API", + "eBay Return Policy API", "eBay Marketing API", "eBay Analytics API", "eBay Metadata API", From 76a915dc2b0c4552c538320c5ade15310b2fd9bb Mon Sep 17 00:00:00 2001 From: BL Date: Tue, 25 Feb 2020 19:47:09 +0530 Subject: [PATCH 05/10] Add support for the searchByImage API; Add support for override content language --- CHANGELOG.md | 2 + README.md | 5 + .../javaScript/buy/browse/sample-image.jpg | Bin 0 -> 15223 bytes .../javaScript/buy/browse/searchByImage.js | 36 +++++++ index.d.ts | 4 +- lib/eBay-node-client.js | 10 ++ lib/eBayResource.js | 102 +++++++++--------- lib/resources/buy/browse.js | 8 +- 8 files changed, 116 insertions(+), 51 deletions(-) create mode 100644 examples/javaScript/buy/browse/sample-image.jpg create mode 100644 examples/javaScript/buy/browse/searchByImage.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fdfaea..53725ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ 0.0.10 - Add support for override content language - Add support for the fulfillment API + - Add support for override marketplace - Add support for the payment policy API - Add support for the return policy API + - Add support for the searchByImage API 0.0.9 - Add support for trading APIs, shopping APIs & Finding APIs diff --git a/README.md b/README.md index 38df1a4..1e97a24 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,11 @@ eBay.setApiKey('YOUR_KEY', 'YOUR_SECRET'); eBay.setContentLanguage('en-GB'); ``` +## Set MarketplaceId +```js + eBay.setMarketplaceId('EBAY_US'); +``` + ## Pull Request - Contributors can send their Pull Request to `development` branch. - Kindly validate test cases & linting before opening new PR. diff --git a/examples/javaScript/buy/browse/sample-image.jpg b/examples/javaScript/buy/browse/sample-image.jpg new file mode 100644 index 0000000000000000000000000000000000000000..55da74ca9fef8c6f71fcd5ef0da60b85e834b98f GIT binary patch literal 15223 zcmb8VWk6ibvM!86fZ#K@yEABTch}(V8r&hl-Ccvby9amoK(OHM4!M(e@3YT2-*^Aq z?j>E-UDZ{+dZv0kz5cBH*@8fmk&u>vfP{pEkOF6jKkpE%N=^NtULYnA6AKfGkB60MSI?NvHWl_98*07>w< z{XN|ZF$HP}Ah(9)Q`F98ckuWIm$t{|OGNn;yX54hyoyfau`wOu^!Ay4X}OB@f4W&b z^E9QH|Jby3QeA$NndwupQFS#ZCqwWDLU^*~+lrH~Z_ZcnDE%j)lkPmd_oTI2h@9@X zG)dN-I(G+kQJ$D`3zTdP+st^Nbq_INqHi8-8}XW6LoUvzJd^HQ4X+UdStqepM^D!t(hr(4j|Z?$FndAesa^_ZgOpl4;eL8AQqA@Pl(PUKP?t=Elh#bfsH`=A~@+hB^iZJsej<3Pd~OC~bCq;Mival^okmo7Z+ zo=azU5{a~RtAh7+r9&F?oE-z`fd)V+HS0-EL7DZWL1#5ut=D#HO(rF zT8c*FNagY}f$Nf76Rre9`Q{96{$`KMtIk3UtTrRS%D%bVYB9?RQYIN%MlJRF3az5i zv^wvlerDN}v;=G~+`6*?XP;r^acepolcpEyq4&`YNTXB@rL?qs;%w)=#UvSmB$>4O z#wHo<`j+}ro|D$Ks^H>gnYj}+ljW!bPyL#t1^J5qE!tQi8fQLPK@-%5kjz2WN5?3g za-)UsT5Gq|w^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)^-n#=qjxU_ zh`H}4JFAI)D;?G;mCo#^uK@9+t|QYFU+COmB|BuX6jP1G3i(-hZaR9@36@7|8BF}Fr^GpUV}CmwTkV3&wJ z$oP7?Bi>!@zdGT02V%SE`_fTr_lz!~MJVQ`uUc{jzn;2#YkZX0xFGQdqOuo)5Gywf z&CumpY*Xzb*9di;a`^HBqwI8}cmRnBsO;mB88v&>*{jA$(Zhlw*AT7vNi=XjX4;9- z`og28B~4kobsH%cAMucBR)MYW&~2B)C&#fK{x*cc2Olu5=v5Fl~f_zkEl z$VM&8m5GJ6^z^iDBw@30!`fCLpN8=S$`S2?m@8|Q+!l$3_TmnA{X8C@iy(kZj?5^^ zRMgEqZzd!;Cqi-t`b$nRdC~!jd_+D$;Yfl^8s&?*9I;ma7W9E>pw3n`h+2AEys>-?z+0;D+&2M8(xe{C zq@jXn6Mu=M#9}{F7D2ykSa=-2wsHG#jXC z4eeL5rEpf*F;;gJE9YflD~Zu5gc2)Na+|cx^I^^dC9%&Xku!WwA@PT5xO}(*we4AU zL$jN#Bd=L&W+}0z1iS2&2@_n;&k>=o+ulJg-rn u+i)168Re&>WN->=lLaF|N&l3=RMHN4xB|FpM>Xu*oa(=dh=A=stN#aFKzZT- literal 0 HcmV?d00001 diff --git a/examples/javaScript/buy/browse/searchByImage.js b/examples/javaScript/buy/browse/searchByImage.js new file mode 100644 index 0000000..4631a0c --- /dev/null +++ b/examples/javaScript/buy/browse/searchByImage.js @@ -0,0 +1,36 @@ +'use strict'; + +var clientId = process.env.EBAY_CLIENT_ID || 'YOUR_KEY'; +var clientSecret = process.env.EBAY_CLIENT_SECRET || 'YOUR_SECRET'; + +var eBay = require('../../../../lib/eBay-node-client')(clientId, clientSecret); +var utils = require('../../../javaScript/utils'); + +var fs = require('fs'); + +// function to encode file data to base64 encoded string +function base64_encode (file) { + // read binary data + var bitmap = fs.readFileSync(file); + // convert binary data to base64 encoded string + return new Buffer(bitmap).toString('base64'); +} + +var browseRequest = async function () { + var userToken = utils.USER_TOKEN; + eBay.setUserToken(userToken); + var base64Content = base64_encode('sample-image.jpg'); + // console.log('base64Content ', base64Content); + var data = { + image: base64Content + }; + try { + var response = await eBay.browse.searchByImage(data); + console.log('response', response); + } catch (error) { + console.log('error ', error); + return; + } +}; + +browseRequest(); diff --git a/index.d.ts b/index.d.ts index b5673a8..6c3e4cb 100644 --- a/index.d.ts +++ b/index.d.ts @@ -25,6 +25,8 @@ declare class Application extends BaseClient { declare class Browse extends BaseClient { search(params: any): Promise; + + searchByImage(imageBase64String: string): Promise; getItem(itemId: string): Promise; @@ -489,7 +491,7 @@ declare class eBayNodeClient { setDevName(devName: string): void; setCertName(certName: string): void; - + setContentLanguage(contentLanguage: string): void; } diff --git a/lib/eBay-node-client.js b/lib/eBay-node-client.js index d66483e..05a65a0 100644 --- a/lib/eBay-node-client.js +++ b/lib/eBay-node-client.js @@ -187,6 +187,12 @@ eBay.prototype = { } }, + setMarketplaceId: function (marketplaceId) { + if (marketplaceId) { + this._setApiField('marketplaceId', marketplaceId); + } + }, + setTimeout: function (timeout) { this._setApiField('timeout', timeout === null ? eBay.DEFAULT_TIMEOUT : timeout); }, @@ -219,6 +225,10 @@ eBay.prototype = { return this._api['contentLanguage']; }, + getMarketplaceId: function () { + return this._api['marketplaceId']; + }, + getApiField: function (key) { return this._api[key]; }, diff --git a/lib/eBayResource.js b/lib/eBayResource.js index c0f7534..1366783 100644 --- a/lib/eBayResource.js +++ b/lib/eBayResource.js @@ -15,7 +15,7 @@ var Error = require('./Error'); var hasOwn = {}.hasOwnProperty; -var RESPONSE_CONTENT_TYPE = ['text/xml', 'text/xml;charset=utf-8', 'application/xml']; +var RESPONSE_CONTENT_TYPE = [ 'text/xml', 'text/xml;charset=utf-8', 'application/xml' ]; // Provide extension mechanism for eBay Resource Sub-Classes eBayResource.extend = utils.protoExtend; @@ -26,7 +26,7 @@ eBayResource.BASIC_METHODS = require('./eBayMethod.basic.js'); /** * Encapsulates request logic for a eBay Resource */ -function eBayResource(eBay, urlData) { +function eBayResource (eBay, urlData) { this._eBay = eBay; this._urlData = urlData || {}; @@ -35,7 +35,7 @@ function eBayResource(eBay, urlData) { if (this.includeBasic) { this.includeBasic.forEach(function (methodName) { - this[methodName] = eBayResource.BASIC_METHODS[methodName]; + this[ methodName ] = eBayResource.BASIC_METHODS[ methodName ]; }, this); } @@ -63,10 +63,10 @@ eBayResource.prototype = { createFullPath: function (commandPath, urlData) { return path.join( - this.basePath(urlData), - this.path(urlData), - typeof commandPath === 'function' ? - commandPath(urlData) : commandPath + this.basePath(urlData), + this.path(urlData), + typeof commandPath === 'function' ? + commandPath(urlData) : commandPath ).replace(/\\/g, '/'); // ugly workaround for Windows }, @@ -75,7 +75,7 @@ eBayResource.prototype = { // Merge in baseData for (var i in this._urlData) { if (hasOwn.call(this._urlData, i)) { - urlData[i] = this._urlData[i]; + urlData[ i ] = this._urlData[ i ]; } } return urlData; @@ -116,10 +116,10 @@ eBayResource.prototype = { _responseHandler: function (requestParamsJSONCopy, req, userOptions, callback) { var self = this; - function processResponseType(res, responseString, callback) { + function processResponseType (res, responseString, callback) { //debug('res %o ', res); //debug('res.headers %o ', res.headers); - if (RESPONSE_CONTENT_TYPE.indexOf(res.headers['content-type'].toLowerCase()) > -1) { + if (RESPONSE_CONTENT_TYPE.indexOf(res.headers[ 'content-type' ].toLowerCase()) > -1) { debug('It is XML Response'); var parser = new xml2js.Parser({ explicitArray: false, @@ -157,14 +157,14 @@ eBayResource.prototype = { var charset = ''; var content_type = ''; var responseString = ''; - if (headers['content-type']) { - content_type = headers['content-type'].toLowerCase(); + if (headers[ 'content-type' ]) { + content_type = headers[ 'content-type' ].toLowerCase(); } - if (content_type && content_type.indexOf('charset') > -1 && content_type.split(';')[0] && content_type.split(';')[1]) { - if (content_type.split(';')[1] && content_type.split(';')[1].match(/^((\b[^\s=]+)=(([^=]|\\=)+))*$/)[3]) { - charset = content_type.split(';')[1].match(/^((\b[^\s=]+)=(([^=]|\\=)+))*$/)[3]; + if (content_type && content_type.indexOf('charset') > -1 && content_type.split(';')[ 0 ] && content_type.split(';')[ 1 ]) { + if (content_type.split(';')[ 1 ] && content_type.split(';')[ 1 ].match(/^((\b[^\s=]+)=(([^=]|\\=)+))*$/)[ 3 ]) { + charset = content_type.split(';')[ 1 ].match(/^((\b[^\s=]+)=(([^=]|\\=)+))*$/)[ 3 ]; } - content_type = content_type.split(';')[0].toLowerCase(); + content_type = content_type.split(';')[ 0 ].toLowerCase(); } var ResponseHeaders = headers; @@ -309,7 +309,7 @@ eBayResource.prototype = { // getRedirectUrl var authorizeURLOptions = { redirect_uri: data.redirectURI, - scope: [data.scope] + scope: [ data.scope ] }; var authorizationUriPromise = oauth2.authorizationCode.authorizeURL(authorizeURLOptions); return callback(null, authorizationUriPromise); @@ -376,57 +376,61 @@ eBayResource.prototype = { }; var contentLanguage = self._eBay.getContentLanguage(); if (contentLanguage) { - headers['Content-Language'] = contentLanguage; + headers[ 'Content-Language' ] = contentLanguage; + } + var marketplaceId = self._eBay.getMarketplaceId(); + if (marketplaceId) { + headers[ 'X-EBAY-C-MARKETPLACE-ID' ] = marketplaceId; } /** * eBay Old API Implementation */ if (options.api === 'trading') { delete headers.authorization; - headers['X-EBAY-API-SITEID'] = 0; - headers['X-EBAY-API-COMPATIBILITY-LEVEL'] = 967; - headers['X-EBAY-API-CALL-NAME'] = options.call; + headers[ 'X-EBAY-API-SITEID' ] = 0; + headers[ 'X-EBAY-API-COMPATIBILITY-LEVEL' ] = 967; + headers[ 'X-EBAY-API-CALL-NAME' ] = options.call; var appName = self._eBay.getAppName(); var devName = self._eBay.getDevName(); var certName = self._eBay.getCertName(); if (appName) { - headers['X-EBAY-API-APP-NAME'] = appName; + headers[ 'X-EBAY-API-APP-NAME' ] = appName; } if (devName) { - headers['X-EBAY-API-DEV-NAME'] = devName; + headers[ 'X-EBAY-API-DEV-NAME' ] = devName; } if (certName) { - headers['X-EBAY-API-CERT-NAME'] = certName; + headers[ 'X-EBAY-API-CERT-NAME' ] = certName; } } if (options.api === 'finding') { delete headers.authorization; - headers['X-EBAY-SOA-OPERATION-NAME'] = options.call; - headers['X-EBAY-SOA-SECURITY-APPNAME'] = self._eBay.getAppName(); + headers[ 'X-EBAY-SOA-OPERATION-NAME' ] = options.call; + headers[ 'X-EBAY-SOA-SECURITY-APPNAME' ] = self._eBay.getAppName(); } if (options.api === 'shopping') { // debug('Inside shopping API call'); delete headers.authorization; - headers['X-EBAY-API-APP-ID'] = self._eBay.getAppName(); - headers['X-EBAY-API-SITEID'] = '0'; - headers['X-EBAY-API-CALL-NAME'] = options.call; - headers['X-EBAY-API-VERSION'] = '863'; - headers['X-EBAY-API-REQUEST-ENCODING'] = 'XML'; + headers[ 'X-EBAY-API-APP-ID' ] = self._eBay.getAppName(); + headers[ 'X-EBAY-API-SITEID' ] = '0'; + headers[ 'X-EBAY-API-CALL-NAME' ] = options.call; + headers[ 'X-EBAY-API-VERSION' ] = '863'; + headers[ 'X-EBAY-API-REQUEST-ENCODING' ] = 'XML'; } if (options.contentType && options.contentType === 'text/xml') { self.body = data.content; } else if (options.contentType && options.contentType === 'application/json') { self.body = JSON.stringify(data); - } else if (['POST'].indexOf(method) > -1) { + } else if ([ 'POST' ].indexOf(method) > -1) { // debug('Inside POST Request'); - headers['Content-Type'] = 'application/x-www-form-urlencoded'; + headers[ 'Content-Type' ] = 'application/x-www-form-urlencoded'; self.body = '&' + qs.stringify(data); - } else if (['PUT'].indexOf(method) > -1) { + } else if ([ 'PUT' ].indexOf(method) > -1) { self.body = JSON.stringify(data); - } else if (['GET'].indexOf(method) > -1) { + } else if ([ 'GET' ].indexOf(method) > -1) { path = path.concat('?', qs.stringify(data)); - } else if (['DELETE'].indexOf(method) > -1) { + } else if ([ 'DELETE' ].indexOf(method) > -1) { self.body = JSON.stringify(data); } @@ -438,7 +442,7 @@ eBayResource.prototype = { makeRequest(); }); - function makeRequest() { + function makeRequest () { var timeout = self._eBay.getApiField('timeout'); var isInsecureConnection = self._eBay.getApiField('protocol') === 'http'; @@ -451,22 +455,22 @@ eBayResource.prototype = { headers: headers }; if (options.api === 'trading') { - params['api'] = options.api; - params['call'] = options.call; - params['variation'] = options.variation; + params[ 'api' ] = options.api; + params[ 'call' ] = options.call; + params[ 'variation' ] = options.variation; } else if (options.api === 'finding') { // debug('Inside finding call'); - params['host'] = self._eBay.getApiField('findingApiHost'); - params['api'] = options.api; - params['call'] = options.call; - params['variation'] = options.variation; + params[ 'host' ] = self._eBay.getApiField('findingApiHost'); + params[ 'api' ] = options.api; + params[ 'call' ] = options.call; + params[ 'variation' ] = options.variation; } else if (options.api === 'shopping') { // debug('Inside shopping call'); - params['host'] = self._eBay.getApiField('shoppingApiHost'); - params['port'] = 80; - params['api'] = options.api; - params['call'] = options.call; - params['variation'] = options.variation; + params[ 'host' ] = self._eBay.getApiField('shoppingApiHost'); + params[ 'port' ] = 80; + params[ 'api' ] = options.api; + params[ 'call' ] = options.call; + params[ 'variation' ] = options.variation; } debug('path ', path); debug('params %o ', params); diff --git a/lib/resources/buy/browse.js b/lib/resources/buy/browse.js index 0b53523..db85e81 100644 --- a/lib/resources/buy/browse.js +++ b/lib/resources/buy/browse.js @@ -14,6 +14,12 @@ module.exports = eBayResource.extend({ path: 'buy/browse/v1/item/{item_id}', urlParams: ['item_id'], required: ['item_id'] - }) + }), + searchByImage: eBayMethod({ + authorization: 'User', + contentType: 'application/json', + method: 'POST', + path: 'buy/browse/v1/item_summary/search_by_image' + }), }); From 778759e538ccd5dd5e5c4b99d87ffcc529398ee3 Mon Sep 17 00:00:00 2001 From: BL Date: Tue, 25 Feb 2020 19:55:37 +0530 Subject: [PATCH 06/10] Update README.md with new examples --- README.md | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/README.md b/README.md index 1e97a24..c05744d 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,24 @@ Originally by [Bhushankumar L](mailto:bhushankumar.lilapara@gmail.com). } ``` +#### Search By Image +``` + var userToken = utils.USER_TOKEN; + eBay.setUserToken(userToken); + var base64Content = base64_encode('sample-image.jpg'); + // console.log('base64Content ', base64Content); + var data = { + image: base64Content + }; + try { + var response = await eBay.browse.searchByImage(data); + console.log('response', response); + } catch (error) { + console.log('error ', error); + return; + } +``` + ### Commerce ### Catalog #### Create Change Request @@ -500,6 +518,23 @@ Originally by [Bhushankumar L](mailto:bhushankumar.lilapara@gmail.com). } ``` +### Fulfillment Policy +#### Get Fulfillment Policies +``` + var userToken = utils.USER_TOKEN; + eBay.setUserToken(userToken); + var data = { + marketplace_id: 'EBAY_US' + }; + try { + var response = await eBay.fulfillmentPolicy.getFulfillmentPolicies(data); + console.log('response', response); + } catch (error) { + console.log('error ', error); + return; + } +``` + #### Get Sales Tax ``` var userToken = utils.USER_TOKEN; @@ -531,6 +566,40 @@ Originally by [Bhushankumar L](mailto:bhushankumar.lilapara@gmail.com). } ``` +### Payment Policy +#### Get Payment Policies +``` + var userToken = utils.USER_TOKEN; + eBay.setUserToken(userToken); + var data = { + marketplace_id: 'EBAY_US' + }; + try { + var response = await eBay.paymentPolicy.getPaymentPolicies(data); + console.log('response', response); + } catch (error) { + console.log('error ', error); + return; + } +``` + +### Return Policy +#### Get Return Policies +``` + var userToken = utils.USER_TOKEN; + eBay.setUserToken(userToken); + var data = { + marketplace_id: 'EBAY_US' + }; + try { + var response = await eBay.returnPolicy.getReturnPolicies(data); + console.log('response', response); + } catch (error) { + console.log('error ', error); + return; + } +``` + ### Inventory #### Create Or Replace Inventory Item ``` From 7001bd39662c77526931825ac1aba8e985ab92ed Mon Sep 17 00:00:00 2001 From: Fouad Kada Date: Tue, 25 Feb 2020 20:01:15 +0100 Subject: [PATCH 07/10] add support for bulkCreateOrReplaceInventoryItem --- README.md | 23 +++++++++++++++++++++++ lib/resources/sell/inventory.js | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/README.md b/README.md index a9c50e4..3576dd2 100644 --- a/README.md +++ b/README.md @@ -553,6 +553,29 @@ Originally by [Bhushankumar L](mailto:bhushankumar.lilapara@gmail.com). } ``` +#### Bulk Create Or Replace Inventory Item +``` + var userToken = utils.USER_TOKEN; + eBay.setUserToken(userToken); + var data = { + 'requests': [ + { + 'sku': '13465446' + }, + { + 'sku': '132165496' + } + ] + }; + try { + var response = await eBay.inventory.bulkCreateOrReplaceInventoryItem(data); + console.log('response ', response); + } catch (error) { + console.log('error ', error); + return; + } +``` + #### Delete Inventory Item ``` var userToken = utils.USER_TOKEN; diff --git a/lib/resources/sell/inventory.js b/lib/resources/sell/inventory.js index 4cc59b8..ac26a16 100644 --- a/lib/resources/sell/inventory.js +++ b/lib/resources/sell/inventory.js @@ -38,6 +38,12 @@ module.exports = eBayResource.extend({ contentType: 'application/json', method: 'POST', path: 'sell/inventory/v1/bulk_get_inventory_item' + }), + bulkCreateOrReplaceInventoryItem: eBayMethod({ + authorization: 'User', + contentType: 'application/json', + method: 'POST', + path: 'sell/inventory/v1/bulk_create_or_replace_inventory_item' }) }); From 520b2bc28bd87f35d806705d9556d845b23ee370 Mon Sep 17 00:00:00 2001 From: BL Date: Thu, 27 Feb 2020 12:05:48 +0530 Subject: [PATCH 08/10] fix lint --- lib/resources/buy/browse.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/resources/buy/browse.js b/lib/resources/buy/browse.js index db85e81..916086f 100644 --- a/lib/resources/buy/browse.js +++ b/lib/resources/buy/browse.js @@ -4,7 +4,6 @@ var eBayResource = require('../../eBayResource'); var eBayMethod = eBayResource.method; module.exports = eBayResource.extend({ - search: eBayMethod({ method: 'GET', path: 'buy/browse/v1/item_summary/search' @@ -20,6 +19,6 @@ module.exports = eBayResource.extend({ contentType: 'application/json', method: 'POST', path: 'buy/browse/v1/item_summary/search_by_image' - }), + }) }); From 45e447ebf62d1b4d26d5222295c6f81d6473fca5 Mon Sep 17 00:00:00 2001 From: BL Date: Thu, 27 Feb 2020 12:18:38 +0530 Subject: [PATCH 09/10] Add example sample for the bulkCreateOrReplaceInventoryItem & bulkUpdatePriceQuantity; Add typescript support for the bulkCreateOrReplaceInventoryItem & bulkUpdatePriceQuantity; --- README.md | 80 +++++++++++++------ .../bulkCreateOrReplaceInventoryItem.js | 31 +++++++ .../sell/inventory/bulkUpdatePriceQuantity.js | 42 ++++++++++ index.d.ts | 8 +- lib/resources/sell/inventory.js | 22 +++-- 5 files changed, 151 insertions(+), 32 deletions(-) create mode 100644 examples/javaScript/sell/inventory/bulkCreateOrReplaceInventoryItem.js create mode 100644 examples/javaScript/sell/inventory/bulkUpdatePriceQuantity.js diff --git a/README.md b/README.md index 5c8f588..1615e20 100644 --- a/README.md +++ b/README.md @@ -601,6 +601,63 @@ Originally by [Bhushankumar L](mailto:bhushankumar.lilapara@gmail.com). ``` ### Inventory +#### Bulk Create Or Replace Inventory Item +``` + var userToken = utils.USER_TOKEN; + eBay.setUserToken(userToken); + var data = { + 'requests': [ + { + 'sku': '13465446' + }, + { + 'sku': '132165496' + } + ] + }; + try { + var response = await eBay.inventory.bulkCreateOrReplaceInventoryItem(data); + console.log('response ', response); + } catch (error) { + console.log('error ', error); + return; + } +``` + +#### Bulk Update Price Quantity +``` + var userToken = utils.USER_TOKEN; + eBay.setUserToken(userToken); + var data = { /* BulkPriceQuantity */ + 'requests': [ + { /* PriceQuantity */ + 'offers': [ + { /* OfferPriceQuantity */ + 'availableQuantity': 'integer', + 'offerId': 'string', + 'price': { /* Amount */ + 'currency': 'string', + 'value': 'string' + } + } + ], + 'shipToLocationAvailability': { + /* ShipToLocationAvailability */ + 'quantity': 'integer' + }, + 'sku': 'string' + } + ] + } + try { + var response = await eBay.inventory.bulkUpdatePriceQuantity(sku, data); + console.log('response', response); + } catch (error) { + console.log('error ', error); + return; + } +``` + #### Create Or Replace Inventory Item ``` var userToken = utils.USER_TOKEN; @@ -642,29 +699,6 @@ Originally by [Bhushankumar L](mailto:bhushankumar.lilapara@gmail.com). } ``` -#### Bulk Create Or Replace Inventory Item -``` - var userToken = utils.USER_TOKEN; - eBay.setUserToken(userToken); - var data = { - 'requests': [ - { - 'sku': '13465446' - }, - { - 'sku': '132165496' - } - ] - }; - try { - var response = await eBay.inventory.bulkCreateOrReplaceInventoryItem(data); - console.log('response ', response); - } catch (error) { - console.log('error ', error); - return; - } -``` - #### Delete Inventory Item ``` var userToken = utils.USER_TOKEN; diff --git a/examples/javaScript/sell/inventory/bulkCreateOrReplaceInventoryItem.js b/examples/javaScript/sell/inventory/bulkCreateOrReplaceInventoryItem.js new file mode 100644 index 0000000..022e8c6 --- /dev/null +++ b/examples/javaScript/sell/inventory/bulkCreateOrReplaceInventoryItem.js @@ -0,0 +1,31 @@ +'use strict'; + +var clientId = process.env.EBAY_CLIENT_ID || 'YOUR_KEY'; +var clientSecret = process.env.EBAY_CLIENT_SECRET || 'YOUR_SECRET'; + +var eBay = require('../../../../lib/eBay-node-client')(clientId, clientSecret); +var utils = require('../../utils'); + +var inventoryRequest = async function () { + var userToken = utils.USER_TOKEN; + eBay.setUserToken(userToken); + var data = { + 'requests': [ + { + 'sku': '13465446' + }, + { + 'sku': '132165496' + } + ] + }; + try { + var response = await eBay.inventory.bulkCreateOrReplaceInventoryItem(data); + console.log('response ', response); + } catch (error) { + console.log('error ', error); + return; + } +}; + +inventoryRequest(); diff --git a/examples/javaScript/sell/inventory/bulkUpdatePriceQuantity.js b/examples/javaScript/sell/inventory/bulkUpdatePriceQuantity.js new file mode 100644 index 0000000..5eb3e32 --- /dev/null +++ b/examples/javaScript/sell/inventory/bulkUpdatePriceQuantity.js @@ -0,0 +1,42 @@ +'use strict'; + +var clientId = process.env.EBAY_CLIENT_ID || 'YOUR_KEY'; +var clientSecret = process.env.EBAY_CLIENT_SECRET || 'YOUR_SECRET'; + +var eBay = require('../../../../lib/eBay-node-client')(clientId, clientSecret); +var utils = require('../../utils'); + +var inventoryRequest = async function () { + var userToken = utils.USER_TOKEN; + eBay.setUserToken(userToken); + var data = { /* BulkPriceQuantity */ + 'requests': [ + { /* PriceQuantity */ + 'offers': [ + { /* OfferPriceQuantity */ + 'availableQuantity': 'integer', + 'offerId': 'string', + 'price': { /* Amount */ + 'currency': 'string', + 'value': 'string' + } + } + ], + 'shipToLocationAvailability': { + /* ShipToLocationAvailability */ + 'quantity': 'integer' + }, + 'sku': 'string' + } + ] + } + try { + var response = await eBay.inventory.bulkUpdatePriceQuantity(sku, data); + console.log('response', response); + } catch (error) { + console.log('error ', error); + return; + } +}; + +inventoryRequest(); diff --git a/index.d.ts b/index.d.ts index 6c3e4cb..6954b6b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -25,7 +25,7 @@ declare class Application extends BaseClient { declare class Browse extends BaseClient { search(params: any): Promise; - + searchByImage(imageBase64String: string): Promise; getItem(itemId: string): Promise; @@ -73,6 +73,12 @@ declare class Inventory extends BaseClient { getInventoryItems(params: any): Promise; getBulkInventoryItem(params: any): Promise; + + bulkGetInventoryItem(params: any): Promise; + + bulkCreateOrReplaceInventoryItem(params: any): Promise; + + bulkUpdatePriceQuantity(params: any): Promise; } declare class Location extends BaseClient { diff --git a/lib/resources/sell/inventory.js b/lib/resources/sell/inventory.js index ac26a16..a718192 100644 --- a/lib/resources/sell/inventory.js +++ b/lib/resources/sell/inventory.js @@ -9,29 +9,29 @@ module.exports = eBayResource.extend({ authorization: 'User', method: 'PUT', path: 'sell/inventory/v1/inventory_item/{sku}', - urlParams: ['sku'], - required: ['sku'] + urlParams: [ 'sku' ], + required: [ 'sku' ] }), deleteInventoryItem: eBayMethod({ authorization: 'User', method: 'DELETE', path: 'sell/inventory/v1/inventory_item/{sku}', - urlParams: ['sku'], - required: ['sku'] + urlParams: [ 'sku' ], + required: [ 'sku' ] }), getInventoryItem: eBayMethod({ authorization: 'User', method: 'GET', path: 'sell/inventory/v1/inventory_item/{sku}', - urlParams: ['sku'], - required: ['sku'] + urlParams: [ 'sku' ], + required: [ 'sku' ] }), getInventoryItems: eBayMethod({ authorization: 'User', method: 'GET', path: 'sell/inventory/v1/inventory_item', - urlParams: ['sku'], - required: ['sku'] + urlParams: [ 'sku' ], + required: [ 'sku' ] }), bulkGetInventoryItem: eBayMethod({ authorization: 'User', @@ -44,6 +44,12 @@ module.exports = eBayResource.extend({ contentType: 'application/json', method: 'POST', path: 'sell/inventory/v1/bulk_create_or_replace_inventory_item' + }), + bulkUpdatePriceQuantity: eBayMethod({ + authorization: 'User', + contentType: 'application/json', + method: 'POST', + path: 'sell/inventory/v1/bulk_update_price_quantity' }) }); From 2208305ae0bbfca6033d3b87ded2e3e91cc86bca Mon Sep 17 00:00:00 2001 From: BL Date: Thu, 27 Feb 2020 12:21:35 +0530 Subject: [PATCH 10/10] modify CHANGELOG for new features --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53725ea..6286fb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ - Add support for the payment policy API - Add support for the return policy API - Add support for the searchByImage API + - Add example sample for the bulkCreateOrReplaceInventoryItem & bulkUpdatePriceQuantity; + - Add typescript support for the bulkCreateOrReplaceInventoryItem & bulkUpdatePriceQuantity; 0.0.9 - Add support for trading APIs, shopping APIs & Finding APIs