Skip to content

Commit 617a386

Browse files
Optional urlPrefix and apiVersion for Platform.createUrl. (#95)
3.2.0 * Optional urlPrefix and apiVersion for Platform.createUrl. * Assertions for new urlPrefix and apiVersion options of platform.createUrl. * Introducing Platform._knownPrefixes.
1 parent 23c96e0 commit 617a386

File tree

7 files changed

+77
-53
lines changed

7 files changed

+77
-53
lines changed

build/ringcentral.js

Lines changed: 55 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/ringcentral.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/ringcentral.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/ringcentral.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ringcentral",
3-
"version": "3.1.3",
3+
"version": "3.2.0",
44
"scripts": {
55
"clean": "rm -rf build/*",
66
"build": "npm run clean && webpack --display-modules --progress --colors --bail",

src/platform/Platform-spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,10 @@ describe('RingCentral.platform.Platform', function() {
411411
addMethod: 'POST'
412412
})).to.equal('http://whatever/restapi/v1.0/foo?bar&_method=POST&access_token=ACCESS_TOKEN');
413413

414+
expect(platform.createUrl('/rcvideo/v1/foo?bar', {
415+
addServer: true,
416+
addToken: true,
417+
})).to.equal('http://whatever/rcvideo/v1/foo?bar&access_token=ACCESS_TOKEN');
414418
}));
415419

416420
});

src/platform/Platform.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ function Platform(options) {
7878
/** @private */
7979
this._client = options.client;
8080

81+
/** @private */
82+
this._knownPrefixes = options.knownPrefixes || Platform._knownPrefixes;
83+
84+
8185
/** @private */
8286
this._refreshPromise = null;
8387

@@ -92,6 +96,7 @@ function Platform(options) {
9296

9397
Platform._urlPrefix = '/restapi';
9498
Platform._apiVersion = 'v1.0';
99+
Platform._knownPrefixes = ['/rcvideo'];
95100
Platform._tokenEndpoint = '/restapi/oauth/token';
96101
Platform._revokeEndpoint = '/restapi/oauth/revoke';
97102
Platform._authorizeEndpoint = '/restapi/oauth/authorize';
@@ -135,11 +140,16 @@ Platform.prototype.createUrl = function(path, options) {
135140
options = options || {};
136141

137142
var builtUrl = '',
138-
hasHttp = path.indexOf('http://') != -1 || path.indexOf('https://') != -1;
143+
hasHttp = path.indexOf('http://') != -1 || path.indexOf('https://') != -1,
144+
alreadyPrefixed = this._knownPrefixes.some(function(prefix) {
145+
return path.indexOf(prefix) === 0;
146+
});
139147

140148
if (options.addServer && !hasHttp) builtUrl += this._server;
141149

142-
if (path.indexOf(Platform._urlPrefix) == -1 && !hasHttp) builtUrl += Platform._urlPrefix + '/' + Platform._apiVersion;
150+
if (path.indexOf(Platform._urlPrefix) == -1 && !hasHttp && !alreadyPrefixed) {
151+
builtUrl += Platform._urlPrefix + '/' + Platform._apiVersion;
152+
}
143153

144154
builtUrl += path;
145155

0 commit comments

Comments
 (0)