Skip to content

Commit 0d30bcd

Browse files
committed
refactor(Tone Analyzer): Update service class based on new core version
1 parent 05d7f61 commit 0d30bcd

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

‎tone-analyzer/src/main/java/com/ibm/watson/tone_analyzer/v3/ToneAnalyzer.java‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.ibm.cloud.sdk.core.http.ResponseConverter;
1818
import com.ibm.cloud.sdk.core.http.ServiceCall;
1919
import com.ibm.cloud.sdk.core.security.Authenticator;
20+
import com.ibm.cloud.sdk.core.security.ConfigBasedAuthenticatorFactory;
2021
import com.ibm.cloud.sdk.core.service.BaseService;
2122
import com.ibm.cloud.sdk.core.util.RequestUtils;
2223
import com.ibm.cloud.sdk.core.util.ResponseConverterUtils;
@@ -44,10 +45,20 @@
4445
public class ToneAnalyzer extends BaseService {
4546

4647
private static final String SERVICE_NAME = "tone_analyzer";
47-
private static final String URL = "https://gateway.watsonplatform.net/tone-analyzer/api";
48+
private static final String SERVICE_URL = "https://gateway.watsonplatform.net/tone-analyzer/api";
4849

4950
private String versionDate;
5051

52+
/**
53+
* Constructs a new `ToneAnalyzer` client.
54+
*
55+
* @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API
56+
* calls from failing when the service introduces breaking changes.
57+
*/
58+
public ToneAnalyzer(String versionDate) {
59+
this(versionDate, ConfigBasedAuthenticatorFactory.getAuthenticator(SERVICE_NAME));
60+
}
61+
5162
/**
5263
* Constructs a new `ToneAnalyzer` client with the specified Authenticator.
5364
*
@@ -57,8 +68,8 @@ public class ToneAnalyzer extends BaseService {
5768
*/
5869
public ToneAnalyzer(String versionDate, Authenticator authenticator) {
5970
super(SERVICE_NAME, authenticator);
60-
if ((getEndPoint() == null) || getEndPoint().isEmpty()) {
61-
setEndPoint(URL);
71+
if ((getServiceUrl() == null) || getServiceUrl().isEmpty()) {
72+
setServiceUrl(SERVICE_URL);
6273
}
6374
com.ibm.cloud.sdk.core.util.Validator.isTrue((versionDate != null) && !versionDate.isEmpty(),
6475
"version cannot be null.");
@@ -92,7 +103,7 @@ public ServiceCall<ToneAnalysis> tone(ToneOptions toneOptions) {
92103
com.ibm.cloud.sdk.core.util.Validator.notNull(toneOptions,
93104
"toneOptions cannot be null");
94105
String[] pathSegments = { "v3/tone" };
95-
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
106+
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getServiceUrl(), pathSegments));
96107
builder.query("version", versionDate);
97108
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("tone_analyzer", "v3", "tone");
98109
for (Entry<String, String> header : sdkHeaders.entrySet()) {
@@ -145,7 +156,7 @@ public ServiceCall<UtteranceAnalyses> toneChat(ToneChatOptions toneChatOptions)
145156
com.ibm.cloud.sdk.core.util.Validator.notNull(toneChatOptions,
146157
"toneChatOptions cannot be null");
147158
String[] pathSegments = { "v3/tone_chat" };
148-
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
159+
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getServiceUrl(), pathSegments));
149160
builder.query("version", versionDate);
150161
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("tone_analyzer", "v3", "toneChat");
151162
for (Entry<String, String> header : sdkHeaders.entrySet()) {

0 commit comments

Comments
 (0)