Skip to content

Commit abd055a

Browse files
committed
allowing using different servers concurrently, #67
1 parent d2740db commit abd055a

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

samples/mdSample2.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
var fs = require('fs');
22
var ForgeSDK = require('../src/index');
33

4+
// ForgeSDK.ApiClient.instance.switchServerPath('https://developer-stg.api.autodesk.com');
5+
// var StgApiClient = new ForgeSDK.ApiClient('https://developer-stg.api.autodesk.com');
6+
// var bucketsApiStg = new ForgeSDK.BucketsApi(StgApiClient);
7+
// var oAuth2TwoLeggedStg = new ForgeSDK.AuthClientTwoLegged(FORGE_CLIENT_ID, FORGE_CLIENT_SECRET, ['data:read'], true, StgApiClient);
8+
// var oAuth2TwoLeggedtest = new ForgeSDK.AuthClientTwoLegged(FORGE_CLIENT_ID, FORGE_CLIENT_SECRET, ['data:read'], true); // back to prod
9+
410
// TODO - insert your CLIENT_ID and CLIENT_SECRET
511
var FORGE_CLIENT_ID = process.env.FORGE_CLIENT_ID || 'your forge client id';
612
var FORGE_CLIENT_SECRET = process.env.FORGE_CLIENT_SECRET || 'your forge client secret';

src/ApiClient.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@ module.exports = (function () {
3838
* @alias module:ApiClient
3939
* @class
4040
*/
41-
var exports = function () {
41+
var exports = function (basepath) {
4242
/**
4343
* The base URL against which to resolve every API call's (relative) path.
4444
* @type {String}
4545
* @default https://developer.api.autodesk.com
4646
*/
4747
this.basePath = 'https://developer.api.autodesk.com'.replace(/\/+$/, '');
48+
if ( basepath !== undefined )
49+
this.basePath = basepath.replace(/\/+$/, '');
50+
4851
/**
4952
* The default HTTP headers to be included for all API calls.
5053
* @type {Array.<String>}
@@ -60,6 +63,11 @@ module.exports = (function () {
6063
this.timeout = 60000;
6164
};
6265

66+
exports.prototype.switchServerPath = function (basepath) {
67+
if (basepath !== undefined)
68+
this.basePath = basepath.replace(/\/+$/, '');
69+
};
70+
6371
/**
6472
* Returns a string representation for an actual parameter.
6573
* @param param The actual parameter.

src/auth/OAuth2.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ module.exports = (function () {
103103
* Constructs a new <code>oAuth2</code>.
104104
* @alias module:auth/OAuth2
105105
*/
106-
var OAuth2 = function (clientId, clientSecret, scope, autoRefresh) {
106+
var OAuth2 = function (clientId, clientSecret, scope, autoRefresh, apiClient) {
107+
ApiClient = apiClient || require('../ApiClient').instance;
108+
107109
this.clientId = clientId;
108110
this.clientSecret = clientSecret;
109111
this.credentials = {};

src/auth/OAuth2ThreeLegged.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ module.exports = (function () {
3737
* Inherits from OAuth2
3838
* @alias module:auth/OAuth2ThreeLegged
3939
*/
40-
var OAuth2ThreeLegged = function (clientId, clientSecret, redirectUri, scope, autoRefresh) {
40+
var OAuth2ThreeLegged = function (clientId, clientSecret, redirectUri, scope, autoRefresh, apiClient) {
41+
ApiClient = apiClient || require('../ApiClient').instance;
4142

4243
this.authentication = {
4344
authorizationUrl: '/authentication/v1/authorize',
@@ -62,7 +63,7 @@ module.exports = (function () {
6263

6364
this.authName = 'oauth2_access_code';
6465

65-
OAuth2.call(this, clientId, clientSecret, scope, autoRefresh);
66+
OAuth2.call(this, clientId, clientSecret, scope, autoRefresh, ApiClient);
6667

6768
this.redirectUri = redirectUri;
6869
};

src/auth/OAuth2TwoLegged.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ module.exports = (function () {
3737
* Inherits from OAuth2
3838
* @alias module:auth/OAuth2TwoLegged
3939
*/
40-
var OAuth2TwoLegged = function (clientId, clientSecret, scope, autoRefresh) {
40+
var OAuth2TwoLegged = function (clientId, clientSecret, scope, autoRefresh, apiClient) {
41+
ApiClient = apiClient || require('../ApiClient').instance;
4142

4243
this.authentication = {
4344
tokenUrl: '/authentication/v1/authenticate',
@@ -60,7 +61,7 @@ module.exports = (function () {
6061

6162
this.authName = 'oauth2_application';
6263

63-
OAuth2.call(this, clientId, clientSecret, scope, autoRefresh);
64+
OAuth2.call(this, clientId, clientSecret, scope, autoRefresh, ApiClient);
6465
};
6566

6667
// inherit from OAuth2 class

0 commit comments

Comments
 (0)