1414
1515import com .google .gson .JsonObject ;
1616import com .ibm .cloud .sdk .core .http .RequestBuilder ;
17+ import com .ibm .cloud .sdk .core .http .ResponseConverter ;
1718import com .ibm .cloud .sdk .core .http .ServiceCall ;
19+ import com .ibm .cloud .sdk .core .security .AuthenticatorConfig ;
1820import com .ibm .cloud .sdk .core .service .BaseService ;
19- import com .ibm .cloud .sdk .core .service .security .IamOptions ;
2021import com .ibm .cloud .sdk .core .util .GsonSingleton ;
2122import com .ibm .cloud .sdk .core .util .RequestUtils ;
2223import com .ibm .cloud .sdk .core .util .ResponseConverterUtils ;
@@ -54,7 +55,9 @@ public class ToneAnalyzer extends BaseService {
5455 *
5556 * @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API
5657 * calls from failing when the service introduces breaking changes.
58+ * @deprecated Use ToneAnalyzer(String versionDate, AuthenticatorConfig authenticatorConfig) instead
5759 */
60+ @ Deprecated
5861 public ToneAnalyzer (String versionDate ) {
5962 super (SERVICE_NAME );
6063 if ((getEndPoint () == null ) || getEndPoint ().isEmpty ()) {
@@ -73,32 +76,36 @@ public ToneAnalyzer(String versionDate) {
7376 * calls from failing when the service introduces breaking changes.
7477 * @param username the username
7578 * @param password the password
79+ * @deprecated Use ToneAnalyzer(String versionDate, AuthenticatorConfig authenticatorConfig) instead
7680 */
81+ @ Deprecated
7782 public ToneAnalyzer (String versionDate , String username , String password ) {
7883 this (versionDate );
7984 setUsernameAndPassword (username , password );
8085 }
8186
8287 /**
83- * Instantiates a new `ToneAnalyzer` with IAM. Note that if the access token is specified in the
84- * iamOptions, you accept responsibility for managing the access token yourself. You must set a new access token
85- * before this
86- * one expires or after receiving a 401 error from the service. Failing to do so will result in authentication errors
87- * after this token expires.
88+ * Instantiates a new `ToneAnalyzer` with the specified authentication configuration.
8889 *
8990 * @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API
9091 * calls from failing when the service introduces breaking changes.
91- * @param iamOptions the options for authenticating through IAM
92+ * @param authenticatorConfig the authentication configuration for this service
9293 */
93- public ToneAnalyzer (String versionDate , IamOptions iamOptions ) {
94- this (versionDate );
95- setIamCredentials (iamOptions );
94+ public ToneAnalyzer (String versionDate , AuthenticatorConfig authenticatorConfig ) {
95+ super (SERVICE_NAME );
96+ if ((getEndPoint () == null ) || getEndPoint ().isEmpty ()) {
97+ setEndPoint (URL );
98+ }
99+ setAuthenticator (authenticatorConfig );
100+
101+ Validator .isTrue ((versionDate != null ) && !versionDate .isEmpty (), "version cannot be null." );
102+ this .versionDate = versionDate ;
96103 }
97104
98105 /**
99106 * Analyze general tone.
100107 *
101- * Use the general purpose endpoint to analyze the tone of your input content. The service analyzes the content for
108+ * Use the general- purpose endpoint to analyze the tone of your input content. The service analyzes the content for
102109 * emotional and language tones. The method always analyzes the tone of the full document; by default, it also
103110 * analyzes the tone of each individual sentence of the content.
104111 *
@@ -113,7 +120,7 @@ public ToneAnalyzer(String versionDate, IamOptions iamOptions) {
113120 * service removes HTML tags and analyzes only the textual content.
114121 *
115122 * **See also:** [Using the general-purpose
116- * endpoint](https://cloud.ibm.com/docs/services/tone-analyzer/using- tone.html#using-the-general-purpose-endpoint ).
123+ * endpoint](https://cloud.ibm.com/docs/services/tone-analyzer?topic= tone-analyzer-utgpe#utgpe ).
117124 *
118125 * @param toneOptions the {@link ToneOptions} containing the options for the call
119126 * @return a {@link ServiceCall} with a response type of {@link ToneAnalysis}
@@ -144,13 +151,16 @@ public ServiceCall<ToneAnalysis> tone(ToneOptions toneOptions) {
144151 builder .query ("tones" , RequestUtils .join (toneOptions .tones (), "," ));
145152 }
146153 builder .bodyContent (toneOptions .contentType (), toneOptions .toneInput (), null , toneOptions .body ());
147- return createServiceCall (builder .build (), ResponseConverterUtils .getObject (ToneAnalysis .class ));
154+ ResponseConverter <ToneAnalysis > responseConverter = ResponseConverterUtils .getValue (
155+ new com .google .gson .reflect .TypeToken <ToneAnalysis >() {
156+ }.getType ());
157+ return createServiceCall (builder .build (), responseConverter );
148158 }
149159
150160 /**
151- * Analyze customer engagement tone.
161+ * Analyze customer- engagement tone.
152162 *
153- * Use the customer engagement endpoint to analyze the tone of customer service and customer support conversations.
163+ * Use the customer- engagement endpoint to analyze the tone of customer service and customer support conversations.
154164 * For each utterance of a conversation, the method reports the most prevalent subset of the following seven tones:
155165 * sad, frustrated, satisfied, excited, polite, impolite, and sympathetic.
156166 *
@@ -161,8 +171,7 @@ public ServiceCall<ToneAnalysis> tone(ToneOptions toneOptions) {
161171 * UTF-8.
162172 *
163173 * **See also:** [Using the customer-engagement
164- * endpoint]
165- * (https://cloud.ibm.com/docs/services/tone-analyzer/using-tone-chat.html#using-the-customer-engagement-endpoint).
174+ * endpoint](https://cloud.ibm.com/docs/services/tone-analyzer?topic=tone-analyzer-utco#utco).
166175 *
167176 * @param toneChatOptions the {@link ToneChatOptions} containing the options for the call
168177 * @return a {@link ServiceCall} with a response type of {@link UtteranceAnalyses}
@@ -186,7 +195,10 @@ public ServiceCall<UtteranceAnalyses> toneChat(ToneChatOptions toneChatOptions)
186195 final JsonObject contentJson = new JsonObject ();
187196 contentJson .add ("utterances" , GsonSingleton .getGson ().toJsonTree (toneChatOptions .utterances ()));
188197 builder .bodyJson (contentJson );
189- return createServiceCall (builder .build (), ResponseConverterUtils .getObject (UtteranceAnalyses .class ));
198+ ResponseConverter <UtteranceAnalyses > responseConverter = ResponseConverterUtils .getValue (
199+ new com .google .gson .reflect .TypeToken <UtteranceAnalyses >() {
200+ }.getType ());
201+ return createServiceCall (builder .build (), responseConverter );
190202 }
191203
192204}
0 commit comments