Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional urlPrefix and apiVersion for Platform.createUrl. #95

Merged
merged 7 commits into from
Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's OK.



/** @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