Skip to content

Commit

Permalink
Merge pull request #3 from bhushankumarl/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Bhushankumar L authored Sep 19, 2018
2 parents 5827ca1 + 05763af commit 99d1a0f
Show file tree
Hide file tree
Showing 18 changed files with 198 additions and 62 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
0.0.3 September 19, 2018
- Add TypeScript example
- Correct typo in README.md
- Configure mocha test case
- Add types for the application, buy, commerce and sell APIs

0.0.2 September 19, 2018
- Add Support for browse API : search
- Add SANDBOX usage using environment variable
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You can find [examples of JavaScript and TypeScript here](https://github.com/bhu

## Installation
```bash
npm install eBay-node-client --save
npm install ebay-node-client --save
```

## Test Cases
Expand All @@ -35,7 +35,7 @@ export EBAY_CLIENT_ID=KEY
export EBAY_CLIENT_SECRET=SECRET
```

## To Enable Sanbox Purpose
## To Enable Sandbox Purpose
```bash
export EBAY_CLIENT_SANDBOX='true'
```
Expand Down
3 changes: 2 additions & 1 deletion examples/javaScript/buy/browse/getItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ var browseRequest = async function () {
});
eBay.setToken(token.access_token);
} catch (error) {

console.log('error ', error);
return;
}

var itemId = 'v1|110329773707|410089528845';
Expand Down
3 changes: 2 additions & 1 deletion examples/javaScript/buy/browse/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ var browseRequest = async function () {
});
eBay.setToken(token.access_token);
} catch (error) {

console.log('error ', error);
return;
}

var data = {
Expand Down
3 changes: 2 additions & 1 deletion examples/javaScript/commerce/taxonomy/getCategorySubtree.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ var categoryRequest = async function () {
});
eBay.setToken(token.access_token);
} catch (error) {

console.log('error ', error);
return;
}

var categoryTreeId = 203;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ var categoryRequest = async function () {
});
eBay.setToken(token.access_token);
} catch (error) {

console.log('error ', error);
return;
}

var categoryTreeId = 203;
Expand Down
3 changes: 2 additions & 1 deletion examples/javaScript/commerce/taxonomy/getCategoryTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ var categoryRequest = async function () {
});
eBay.setToken(token.access_token);
} catch (error) {

console.log('error ', error);
return;
}

var categoryTreeId = 203;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ var categoryRequest = async function () {
});
eBay.setToken(token.access_token);
} catch (error) {

console.log('error ', error);
return;
}

var data = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ var categoryRequest = async function () {
});
eBay.setToken(token.access_token);
} catch (error) {

console.log('error ', error);
return;
}

var categoryTreeId = 203;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var clientSecret = process.env.EBAY_CLIENT_SECRET || 'YOUR_SECRET';

var eBay = require('../../../../lib/eBay-node-client')(clientId, clientSecret);

var browseRequest = async function () {
var browseRequest = function () {
var userToken = 'USER_TOKEN';
eBay.setUserToken(userToken);

Expand Down
22 changes: 22 additions & 0 deletions examples/typeScript/application/oauthToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const clientId = process.env.EBAY_CLIENT_ID || 'YOUR_KEY';
const clientSecret = process.env.EBAY_CLIENT_SECRET || 'YOUR_SECRET';

const eBay = require('../../../lib/eBay-node-client')(clientId, clientSecret);

const applicationRequest = async function () {

try {
const token = await eBay.application.getOAuthToken({
grant_type: 'client_credentials',
scope: 'https://api.ebay.com/oauth/api_scope'
});
console.log('token.access_token ', token.access_token);
eBay.setToken(token.access_token);
} catch (error) {
console.log('error ', error);
}
};

applicationRequest();
30 changes: 30 additions & 0 deletions examples/typeScript/buy/browse/getItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

const clientId = process.env.EBAY_CLIENT_ID || 'YOUR_KEY';
const clientSecret = process.env.EBAY_CLIENT_SECRET || 'YOUR_SECRET';

const eBay = require('../../../../lib/eBay-node-client')(clientId, clientSecret);

const browseRequest = async function () {
try {
const token = await eBay.application.getOAuthToken({
grant_type: 'client_credentials',
scope: 'https://api.ebay.com/oauth/api_scope'
});
eBay.setToken(token.access_token);
} catch (error) {
console.log('error ', error);
return;
}

const itemId = 'v1|110329773707|410089528845';
eBay.browse.getItem(itemId, function (error, response) {
if (error) {
console.log('error ', error);
return;
}
console.log('response', response);
});
};

browseRequest();
33 changes: 33 additions & 0 deletions examples/typeScript/buy/browse/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'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 browseRequest = async function () {
try {
var token = await eBay.application.getOAuthToken({
grant_type: 'client_credentials',
scope: 'https://api.ebay.com/oauth/api_scope'
});
eBay.setToken(token.access_token);
} catch (error) {
console.log('error ', error);
return;
}

var data = {
gtin: '010942122258',
limit: '1'
};
eBay.browse.search(data, function (error, response) {
if (error) {
console.log('error ', error);
return;
}
console.log('response', response);
});
};

browseRequest();
4 changes: 2 additions & 2 deletions examples/typeScript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"description": "eBay",
"license": "MIT",
"dependencies": {
"@types/node": "^8.0.53",
"@types/es6-promise": "0.0.33",
"@types/node": "^8.0.53",
"babel-eslint": "^8.0.1",
"babel-preset-node6": "^11.0.0",
"eBay-node-client": "*"
"ebay-node-client": "*"
},
"devDependencies": {}
}
81 changes: 31 additions & 50 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,93 +1,74 @@
// Type definitions for amazon-mws
// Type definitions for ebay-node-client

declare class BaseAmazonMWS {

search(params: any): Promise<any>;
declare class BaseeBayNodeClient {

}

declare class Feeds extends BaseAmazonMWS {
declare class Application extends BaseeBayNodeClient {

submit(params: any): Promise<any>;
getOAuthToken(params: any): Promise<any>;

}

declare class Finances extends BaseAmazonMWS {

}
declare class Browse extends BaseeBayNodeClient {

declare class FulfillmentInboundShipment extends BaseAmazonMWS {
getItem(itemId: string): Promise<any>;

create(params: any): Promise<any>;
search(params: any): Promise<any>;

}

declare class FulfillmentInventory extends BaseAmazonMWS {
declare class Taxonomy extends BaseeBayNodeClient {

}
getCategorySubtree(categoryTreeId: string, params: any): Promise<any>;

declare class FulfillmentOutboundShipment extends BaseAmazonMWS {
getCategorySuggestions(categoryTreeId: string, params: any): Promise<any>;

}
getItemAspectsForCategory(categoryTreeId: string, params: any): Promise<any>;

declare class MerchantFulfillment extends BaseAmazonMWS {
getCategoryTree(categoryTreeId: string): Promise<any>;

create(params: any): Promise<any>;
getDefaultCategoryTreeId(params: any): Promise<any>;

}

declare class Orders extends BaseAmazonMWS {

}
declare class Inventory extends BaseeBayNodeClient {

declare class Products extends BaseAmazonMWS {
createOrReplaceInventoryItem(sku: string, params: any): Promise<any>;

searchFor(params: any): Promise<any>;
getInventoryItem(sku: string): Promise<any>;

getInventoryItems(params: any): Promise<any>;

}

declare class Reports extends BaseAmazonMWS {
declare class eBayNodeClient {

}
application: Application;

declare class Sellers extends BaseAmazonMWS {
browse: Browse;

}
taxonomy: Taxonomy;

declare class AmazonMWS {
inventory: Inventory;

constructor()

constructor(key: string, token: string);
constructor(clientId: string, clientSecret: string);

setApiKey(key: string, secret: string): void;
constructor(clientId: string, clientSecret: string, isSandbox: boolean);

setHost(host?: string, port?: string, protocol?: string): void;

feeds: Feeds;

finances: Finances;

fulfillmentInboundShipment: FulfillmentInboundShipment;

fulfillmentInventory: FulfillmentInventory;
setApiKey(clientId: string, clientSecret: string): void;

fulfillmentOutboundShipment: FulfillmentOutboundShipment;

merchantFulfillment: MerchantFulfillment;

orders: Orders;

products: Products;

reports: Reports;
setHost(host?: string, port?: string, protocol?: string): void;

sellers: Sellers;
setToken(applicationToken: string): void;

setUserToken(userToken: string): void;
}


declare namespace AmazonMWS {
declare namespace eBayNodeClient {

}
export = AmazonMWS;
export = eBayNodeClient;
6 changes: 6 additions & 0 deletions test/intialize/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';
module.exports = {
clientId: process.env.EBAY_CLIENT_ID,
clientSecret: process.env.EBAY_CLIENT_SECRET,
USER_TOKEN: process.env.EBAY_USER_TOKEN,
};
11 changes: 11 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
###
### mocha.opts
###

--bail
--silly
--full-trace
--recursive
--timeout 20000
--reporter spec
./test/specs/**/*.spec.js
40 changes: 40 additions & 0 deletions test/specs/application/oauth.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';
var config = require('../../intialize/config');
var clientId = config.clientId;
var clientSecret = config.clientSecret;

var chai = require('chai');
var expect = chai.expect;

var eBay = require('../../../lib/eBay-node-client')(clientId, clientSecret);

describe('Application', function () {

before(function () {
expect(clientId).to.be.a('string');
expect(clientSecret).to.be.a('string');
});

it('It should get Application OAuth Token ', async function () {
var options = {
grant_type: 'client_credentials',
scope: 'https://api.ebay.com/oauth/api_scope'
};

expect(options.grant_type).to.be.a('string');
expect(options.scope).to.be.a('string');

try {
var response = await eBay.application.getOAuthToken(options);
eBay.setToken(response.access_token);
expect(response).to.be.a('object');
expect(response).to.have.property('access_token').to.be.a('string');
expect(response).to.have.property('expires_in').to.be.a('number');
expect(response).to.have.property('token_type').to.be.a('string');
} catch (error) {
console.log('error ', error);
expect(response).to.be.a(undefined);
}

});
});

0 comments on commit 99d1a0f

Please sign in to comment.