Skip to content

Commit

Permalink
Fix keyword space in search api (#40)
Browse files Browse the repository at this point in the history
* fix keyword space

* remove lru-cache
  • Loading branch information
pajaydev authored Jun 29, 2019
1 parent b91af7f commit 6ef574b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ebay-node-api",
"version": "2.5.5",
"version": "2.5.6",
"description": "Ebay node api client",
"main": "./src/index.js",
"homepage": "https://github.com/ajay2507/ebay-node-api",
Expand Down
9 changes: 6 additions & 3 deletions src/buy-api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const makeString = require('make-string');
const { makeRequest } = require('./request');
const { encodeURLQuery } = require('./utils');

const getItem = function (itemId) {
if (!itemId) throw new Error('Item Id is required');
Expand Down Expand Up @@ -47,15 +48,17 @@ const searchItems = function (searchConfig) {
if (!searchConfig.keyword && !searchConfig.categoryId && !searchConfig.gtin) throw new Error('Error --> Keyword or category id is required in query param');
if (!this.options.access_token) throw new Error('Error -->Missing Access token, Generate access token');
const auth = 'Bearer ' + this.options.access_token;
let queryParam = searchConfig.keyword ? 'q=' + searchConfig.keyword : '';
let queryParam = searchConfig.keyword ? 'q=' + encodeURIComponent(searchConfig.keyword) : '';
queryParam = queryParam + (searchConfig.gtin ? '&gtin=' + searchConfig.gtin : '');
queryParam = queryParam + (searchConfig.categoryId ? '&category_ids=' + searchConfig.categoryId : '');
queryParam = queryParam + (searchConfig.limit ? '&limit=' + searchConfig.limit : '');
queryParam = queryParam + (searchConfig.sort ? '&sort=' + searchConfig.sort : '');
if (searchConfig.fieldgroups !== undefined) queryParam = queryParam + '&fieldgroups=' + searchConfig.fieldgroups;
if (searchConfig.filter !== undefined) queryParam = queryParam + '&filter=' + encodeURIComponent(makeString(searchConfig.filter, { quotes: 'no', braces: 'false' }));
if (searchConfig.filter !== undefined) queryParam = queryParam + '&' + encodeURLQuery('filter=' + makeString(searchConfig.filter, { quotes: 'no', braces: 'false' }));
console.log(this.options.baseUrl + `/buy/browse/v1/item_summary/search?${(queryParam)}`);
//this.options.baseUrl, `/buy/browse/v1/item_summary/search?${encodeURI(queryParam)}
return new Promise((resolve, reject) => {
makeRequest(this.options.baseUrl, `/buy/browse/v1/item_summary/search?${queryParam}`, 'GET', this.options.body, auth).then((result) => {
makeRequest(this.options.baseUrl, `/buy/browse/v1/item_summary/search?${(queryParam)}`, 'GET', this.options.body, auth).then((result) => {
resolve(result);
}).then((error) => {
reject(error);
Expand Down
7 changes: 6 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ function isString(value) {
return typeof value === 'string' || value instanceof String;
};

function encodeURLQuery(url) {
return encodeURIComponent(url).replace(/'/g, '%27').replace(/"/g, '%22');
};

module.exports = {
upperCase
upperCase,
encodeURLQuery
};
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,13 @@ lolex@^2.2.0, lolex@^2.3.2:
version "2.7.5"
resolved "https://registry.yarnpkg.com/lolex/-/lolex-2.7.5.tgz#113001d56bfc7e02d56e36291cc5c413d1aa0733"

lru-cache@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920"
integrity sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==
dependencies:
yallist "^3.0.2"

make-string@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/make-string/-/make-string-1.0.2.tgz#e88970b637e09e9e98ceb71b6298fa942b3a753c"
Expand Down Expand Up @@ -891,3 +898,8 @@ [email protected]:
resolved "https://registry.yarnpkg.com/write/-/write-1.0.3.tgz#0800e14523b923a387e415123c865616aae0f5c3"
dependencies:
mkdirp "^0.5.1"

yallist@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.3.tgz#b4b049e314be545e3ce802236d6cd22cd91c3de9"
integrity sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==

0 comments on commit 6ef574b

Please sign in to comment.