Skip to content

Commit

Permalink
Optional urlPrefix and apiVersion for Platform.createUrl. (#95)
Browse files Browse the repository at this point in the history
3.2.0
* Optional urlPrefix and apiVersion for Platform.createUrl.
* Assertions for new urlPrefix and apiVersion options of platform.createUrl.
* Introducing Platform._knownPrefixes.
  • Loading branch information
MostFrumiousBandersnatch authored and kirill-konshin committed Feb 14, 2018
1 parent 23c96e0 commit 617a386
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 53 deletions.
100 changes: 55 additions & 45 deletions build/ringcentral.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/ringcentral.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions build/ringcentral.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/ringcentral.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ringcentral",
"version": "3.1.3",
"version": "3.2.0",
"scripts": {
"clean": "rm -rf build/*",
"build": "npm run clean && webpack --display-modules --progress --colors --bail",
Expand Down
4 changes: 4 additions & 0 deletions src/platform/Platform-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ describe('RingCentral.platform.Platform', function() {
addMethod: 'POST'
})).to.equal('http://whatever/restapi/v1.0/foo?bar&_method=POST&access_token=ACCESS_TOKEN');

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

});
Expand Down
14 changes: 12 additions & 2 deletions src/platform/Platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ function Platform(options) {
/** @private */
this._client = options.client;

/** @private */
this._knownPrefixes = options.knownPrefixes || Platform._knownPrefixes;


/** @private */
this._refreshPromise = null;

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

Platform._urlPrefix = '/restapi';
Platform._apiVersion = 'v1.0';
Platform._knownPrefixes = ['/rcvideo'];
Platform._tokenEndpoint = '/restapi/oauth/token';
Platform._revokeEndpoint = '/restapi/oauth/revoke';
Platform._authorizeEndpoint = '/restapi/oauth/authorize';
Expand Down Expand Up @@ -135,11 +140,16 @@ Platform.prototype.createUrl = function(path, options) {
options = options || {};

var builtUrl = '',
hasHttp = path.indexOf('http://') != -1 || path.indexOf('https://') != -1;
hasHttp = path.indexOf('http://') != -1 || path.indexOf('https://') != -1,
alreadyPrefixed = this._knownPrefixes.some(function(prefix) {
return path.indexOf(prefix) === 0;
});

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

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

builtUrl += path;

Expand Down

0 comments on commit 617a386

Please sign in to comment.