Skip to content

Commit bfc61a0

Browse files
committed
Merge branch 'master' into v4.0.0-branch
2 parents 25acf8f + c19f63f commit bfc61a0

3 files changed

Lines changed: 34 additions & 5 deletions

File tree

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ npm install watson-developer-cloud
5858

5959
## Usage
6060

61-
The [examples][examples] folder has basic and advanced examples. The examples within each service assume that you already have [service credentials](#getting-credentials).
61+
The [examples][examples] folder has basic and advanced examples. The examples within each service assume that you already have [service credentials](#getting-credentials).
6262

6363
Credentials are checked for in the following order:
6464

@@ -70,7 +70,7 @@ Credentials are checked for in the following order:
7070

7171
3. IBM-Cloud-supplied credentials (via the `VCAP_SERVICES` JSON-encoded environment property)
7272

73-
If you run your app in IBM Cloud, the SDK gets credentials from the [`VCAP_SERVICES`][vcap_services] environment variable.
73+
If you run your app in IBM Cloud, the SDK gets credentials from the [`VCAP_SERVICES`][vcap_services] environment variable.
7474

7575
### Client-side usage
7676

@@ -219,7 +219,18 @@ discovery.listEnvironments((err, res) => {
219219
console.log(JSON.stringify(res, null, 2));
220220
}
221221
});
222+
```
223+
224+
### Setting the service URL
225+
226+
You can set the service URL by calling the setServiceUrl() method.
222227

228+
```javascript
229+
const discovery = new DiscoveryV1({
230+
version: '<version-date>'
231+
});
232+
233+
discovery.setServiceUrl('https://gateway-wdc.watsonplatform.net/discovery/api');
223234
```
224235

225236
### Sending request headers
@@ -239,7 +250,7 @@ assistant.message({
239250
headers: {
240251
'Custom-Header': 'custom',
241252
'Accept-Language': 'custom'
242-
253+
243254
}
244255
}, function(err, result, response) {
245256
if (err)
@@ -817,7 +828,7 @@ $ npm test
817828
818829
Running a specific test:
819830
```sh
820-
$ mocha -g '<test name>'
831+
$ jest '<path to test>'
821832
```
822833
823834
## Open source @ IBM

lib/base_service.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,16 @@ export class BaseService {
176176
this._options.rejectUnauthorized = !options.disable_ssl_verification;
177177
}
178178

179+
/**
180+
* Set the URL of the service instance.
181+
*
182+
* @param {string} url - The url of the service instance
183+
* @returns {void}
184+
*/
185+
public setServiceUrl(url: string) {
186+
this._options.url = stripTrailingSlash(url);
187+
}
188+
179189
/**
180190
* Retrieve this service's credentials - useful for passing to the authorization service
181191
*
@@ -252,7 +262,7 @@ export class BaseService {
252262

253263
/**
254264
* Wrapper around `sendRequest` that determines whether or not IAM tokens
255-
* are being used to authenticate the request. If so, the token is
265+
* are being used to authenticate the request. If so, the token is
256266
* retrieved by the token manager.
257267
*
258268
* @param {Object} parameters - service request options passed in by user

test/unit/baseService.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ describe('BaseService', function() {
9090
expect(actual).toEqual(expected);
9191
});
9292

93+
it('should allow URL to be changed after service init', function() {
94+
const instance = new TestService({ username: 'user', password: 'pass' });
95+
const expected = 'https://gateway-wdc.watsonplatform.net/test/api';
96+
instance.setServiceUrl(expected);
97+
const actual = instance.getCredentials()['url'];
98+
expect(actual).toEqual(expected);
99+
});
100+
93101
it('should return credentials and url from the environment', function() {
94102
process.env.TEST_USERNAME = 'env_user';
95103
process.env.TEST_PASSWORD = 'env_pass';

0 commit comments

Comments
 (0)