ebay-oauth-nodejs-client
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -20,2 +20,3 @@ /* | ||
/* eslint no-console: "off" */ | ||
/* eslint no-redeclare: "off" */ | ||
'use strict'; | ||
@@ -35,6 +36,13 @@ const EbayAuthToken = require('../src/index'); | ||
const ebayAuthToken = new EbayAuthToken({ | ||
// pass the credentials through the ext file. | ||
let ebayAuthToken = new EbayAuthToken({ | ||
filePath: 'demo/ebay-config-sample.json' | ||
}); | ||
// pass the credentials through constructor | ||
ebayAuthToken = new EbayAuthToken({ | ||
clientId: '---Client id ----', | ||
clientSecret: '-- client secret---' | ||
}); | ||
const clientScope = 'https://api.ebay.com/oauth/api_scope'; | ||
@@ -41,0 +49,0 @@ // // Client Crendential Auth Flow |
{ | ||
"name": "ebay-oauth-nodejs-client", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Get oauth2 token for ebay developer application", | ||
@@ -29,2 +29,3 @@ "main": "src/index.js", | ||
"chai": "^4.2.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-ebay": "^1.1.1", | ||
@@ -31,0 +32,0 @@ "mocha": "^6.1.4", |
@@ -1,6 +0,6 @@ | ||
# Ebay Oauth API | ||
# Ebay Oauth Client | ||
This code allows developers to fetch an OAuth token that can be used to call the eBay Developer REST APIs. The code is intended for use with Node.js. | ||
[![npm version](https://badge.fury.io/js/oauth-ebay.svg)](https://badge.fury.io/js/oauth-ebay) | ||
[![npm version](https://badge.fury.io/js/ebay-oauth-nodejs-client.svg)](https://badge.fury.io/js/ebay-oauth-nodejs-client) | ||
@@ -20,3 +20,2 @@ ## Table of Contents | ||
* [Grant Type: Refresh Token](#refresh-token) | ||
* [Developers and Contributors](#developers-and-contributors) | ||
* [References](#references) | ||
@@ -48,2 +47,9 @@ * [License](#license) | ||
``` | ||
OR | ||
```javascript | ||
const ebayAuthToken = new EbayAuthToken({ | ||
clientId: '<your_client_id>', | ||
clientSecret: '<your_client_secret>' | ||
}); | ||
``` | ||
2. If you want to get your application credentials such as AppId, DevId, and CertId. Refer to [Creating eBay Developer Account](https://developer.ebay.com/api-docs/static/creating-edp-account.html) for details on how to get these credentials. | ||
@@ -102,8 +108,5 @@ 3. You can refer to example.js for an example of how to use credentials. | ||
## Questions/problems? | ||
you've found an bug/issue, please file it on [GitHub](https://github.com/eBay/ebay-oauth-nodejs-client/issues). | ||
## Developers and Contributors | ||
Ajaykumar Prathap | ||
Sandeep Dhiman | ||
Sree Kalahasthi | ||
## References | ||
@@ -110,0 +113,0 @@ |
@@ -24,3 +24,3 @@ /* | ||
const postRequest = require('./request'); | ||
const { readJSONFile, validateParams } = require('./utils'); | ||
const { readJSONFile, validateParams, readOptions } = require('./utils'); | ||
@@ -42,6 +42,6 @@ /** | ||
constructor(options) { | ||
if (!options || !options.filePath) { | ||
throw new Error('input filePath is required'); | ||
if (!options) { | ||
throw new Error('This method accepts an object with filepath or with client id and client secret'); | ||
} | ||
this.credentials = readJSONFile(options.filePath); | ||
this.credentials = options.filePath ? readJSONFile(options.filePath) : readOptions(options); | ||
this.grantType = ''; | ||
@@ -48,0 +48,0 @@ return this; |
@@ -21,2 +21,4 @@ 'use strict'; | ||
const path = require('path'); | ||
const sandboxBaseUrl = 'api.sandbox.ebay.com'; | ||
const prodBaseUrl = 'api.ebay.com'; | ||
@@ -39,2 +41,10 @@ const readJSONFile = (fileName) => { | ||
module.exports = { readJSONFile, validateParams }; | ||
const readOptions = (options) => { | ||
const credentials = {}; | ||
if (!options.env) options.env = 'PRODUCTION'; | ||
options.baseUrl = options.env === 'PRODUCTION' ? prodBaseUrl : sandboxBaseUrl; | ||
credentials[options.env] = { ...options }; | ||
return credentials; | ||
}; | ||
module.exports = { readJSONFile, validateParams, readOptions }; |
@@ -15,7 +15,24 @@ 'use strict'; | ||
new EbayAuthToken(); // eslint-disable-line no-new | ||
}).to.throw(Error, 'input filePath is required'); | ||
}).to.throw(Error, 'This method accepts an object with filepath or with client id and client secret'); | ||
}); | ||
it('test getApplicationToken method', () => { | ||
it('test input params without filePath', () => { | ||
const ebayAuthToken = new EbayAuthToken({ | ||
clientId: 'PROD1234ABCD', | ||
clientSecret: 'PRODSSSXXXZZZZ', | ||
devid: 'SANDBOXDEVID' | ||
}); | ||
expect(ebayAuthToken.credentials).deep.equals({ | ||
'PRODUCTION': { | ||
'clientId': 'PROD1234ABCD', | ||
'clientSecret': 'PRODSSSXXXZZZZ', | ||
'devid': 'SANDBOXDEVID', | ||
'env': 'PRODUCTION', | ||
'baseUrl': 'api.ebay.com' | ||
} | ||
}); | ||
}); | ||
it('test getApplicationToken method using filePath', () => { | ||
const ebayAuthToken = new EbayAuthToken({ | ||
filePath: 'test/test.json' | ||
@@ -22,0 +39,0 @@ }); |
Sorry, the diff of this file is not supported yet
36613
409
138
5