Skip to content

Commit

Permalink
feat: use discovery rcv base uri for rcv request (ringcentral#152)
Browse files Browse the repository at this point in the history
* feat: use discovery rcv api for rcv request
* add rcv with discovery tests
  • Loading branch information
embbnux authored May 25, 2021
1 parent 380d2f6 commit 26a14d4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
7 changes: 7 additions & 0 deletions sdk/src/platform/Platform-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,13 @@ describe('RingCentral.platform.Platform', () => {
expect(data.increment).to.equal(1);
});

it('should fetch rcv api request successfully', async () => {
apiCall('GET', '/rcvideo/v1/bridges', {id: 123});
const res = await platform.get('/rcvideo/v1/bridges');
const data = await res.json();
expect(data.id).to.equal(123);
});

it('should refresh token successfully', async () => {
tokenRefresh();
const noErrors = true;
Expand Down
12 changes: 11 additions & 1 deletion sdk/src/platform/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export default class Platform extends EventEmitter {

private _server: string;

private _rcvServer: string;

private _clientId: string;

private _clientSecret: string;
Expand Down Expand Up @@ -109,6 +111,7 @@ export default class Platform extends EventEmitter {
super();

this._server = server;
this._rcvServer = server;
this._clientId = clientId;
this._clientSecret = clientSecret;
this._brandId = brandId;
Expand Down Expand Up @@ -203,7 +206,13 @@ export default class Platform extends EventEmitter {

const hasHttp = checkPathHasHttp(path);

if (options.addServer && !hasHttp) builtUrl += this._server;
if (options.addServer && !hasHttp) {
if (path.indexOf('/rcvideo') === 0 || (this._urlPrefix && this._urlPrefix.indexOf('/rcvideo') === 0)) {
builtUrl += this._rcvServer;
} else {
builtUrl += this._server;
}
}

if (this._urlPrefix) builtUrl += this._urlPrefix;

Expand Down Expand Up @@ -702,6 +711,7 @@ export default class Platform extends EventEmitter {
throw new Error('Discovery data is missing');
}
this._server = discoveryData.coreApi.baseUri;
this._rcvServer = discoveryData.rcv.baseApiUri;
if (discoveryData.tag) {
options.headers = options.headers || {};
options.headers['Discovery-Tag'] = discoveryData.tag;
Expand Down
3 changes: 3 additions & 0 deletions sdk/src/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ export function getExternalDiscoveryMockData() {
baseUri: 'http://whatever',
tokenUri: 'http://whatever/restapi/oauth/token',
},
rcv: {
baseApiUri: 'http://whatever',
},
coreApi: {
baseUri: 'http://whatever',
pubnubOrigin: 'whatever',
Expand Down

0 comments on commit 26a14d4

Please sign in to comment.