Skip to content

Commit bbeb590

Browse files
authored
Merge pull request #930 from watson-developer-cloud/develop
v5.4.0 Release
2 parents adaf4b2 + 2a1f307 commit bbeb590

File tree

150 files changed

+2609
-1125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+2609
-1125
lines changed

README.md

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ Java client library to use the [Watson APIs][wdc].
1515
* [Gradle](#gradle)
1616
* [Usage](#usage)
1717
* [Running in IBM Cloud](#running-in-ibm-cloud)
18-
* [Getting the Service Credentials](#getting-the-service-credentials)
18+
* [Authentication](#authentication)
19+
* [Username and Password](#username-and-password)
20+
* [API Key](#api-key)
21+
* [Using IAM](#using-iam)
1922
* IBM Watson Services
2023
* [Assistant](assistant)
2124
* [Discovery](discovery)
@@ -123,17 +126,92 @@ credentials; the library will get them for you by looking at the [`VCAP_SERVICES
123126
When running in IBM Cloud (or other platforms based on Cloud Foundry), the library will automatically get the credentials from [`VCAP_SERVICES`][vcap_services].
124127
If you have more than one plan, you can use `CredentialUtils` to get the service credentials for an specific plan.
125128

126-
## Getting the Service Credentials
129+
## Authentication
127130

128-
You will need the `username` and `password` (`api_key` for Visual Recognition) credentials, and the API endpoint for each service. Service credentials are different from your IBM Cloud account username and password.
131+
There are three ways to authenticate with IBM Cloud through the SDK: using a `username` and `password`, using an `api_key`, and with IAM.
129132

130-
To get your service credentials, follow these steps:
133+
Getting the credentials necessary for authentication is the same process for all methods. To get them, follow these steps:
131134

132135
1. Log in to [IBM Cloud](https://console.bluemix.net/catalog?category=watson)
133136
1. In the IBM Cloud **Catalog**, select the service you want to use.
134137
1. Click **Create**.
135138
1. On the left side of the page, click **Service Credentials**, and then **View credentials** to view your service credentials.
136-
1. Copy `url`, `username` and `password`(`api_key` for AlchemyAPI or Visual Recognition).
139+
1. Copy the necessary credentials (`url`, `username`, `password`, `api_key`, `apikey`, etc.).
140+
141+
In your code, you can use these values in the service constructor or with a method call after instantiating your service. Here are some examples:
142+
143+
### Username and Password
144+
145+
```java
146+
// in the constructor
147+
Discovery service = new Discovery("2017-11-07", "<username>", "<password>");
148+
```
149+
150+
```java
151+
// after instantiation
152+
Discovery service = new Discovery("2017-11-07");
153+
service.setUsernameAndPassword("<username>", "<password>");
154+
```
155+
156+
### API Key
157+
158+
_Note: This version of instantiation only works with Visual Recognition, as it's the only service that uses an API key rather than a username and password._
159+
160+
```java
161+
// in the constructor
162+
VisualRecognition service = new VisualRecognition("2016-05-20", "<api_key>");
163+
```
164+
165+
```java
166+
// after instantiation
167+
VisualRecognition service = new VisualRecognition("2016-05-20");
168+
service.setApiKey("<api_key>");
169+
```
170+
171+
### Using IAM
172+
173+
When authenticating with IAM, you have the option of passing in:
174+
- the IAM API key and, optionally, the IAM service URL
175+
- an IAM access token
176+
177+
**Be aware that passing in an access token means that you're assuming responsibility for maintaining that token's lifecycle.** If you instead pass in an IAM API key, the SDK will manage it for you.
178+
179+
```java
180+
// in the constructor, letting the SDK manage the IAM token
181+
IamOptions options = new IamOptions.Builder()
182+
.apiKey("<iam_api_key>")
183+
.url("<iam_url>") // optional - the default value is https://iam.ng.bluemix.net/identity/token
184+
.build();
185+
Discovery service = new Discovery("2017-11-07", options);
186+
```
187+
188+
```java
189+
// after instantiation, letting the SDK manage the IAM token
190+
Discovery service = new Discovery("2017-11-07");
191+
IamOptions options = new IamOptions.Builder()
192+
.apiKey("<iam_api_key>")
193+
.build();
194+
service.setIamCredentials(options);
195+
```
196+
197+
```java
198+
// in the constructor, assuming control of managing IAM token
199+
IamOptions options = new IamOptions.Builder()
200+
.accessToken("<access_token>")
201+
.build();
202+
Discovery service = new Discovery("2017-11-07", options);
203+
```
204+
205+
```java
206+
// after instantiation, assuming control of managing IAM token
207+
Discovery service = new Discovery("2017-11-07");
208+
IamOptions options = new IamOptions.Builder()
209+
.accessToken("<access_token>")
210+
.build();
211+
service.setIamCredentials(options);
212+
```
213+
214+
If at any time you would like to let the SDK take over managing your IAM token, simply override your stored IAM credentials with an IAM API key by calling the `setIamCredentials()` method again.
137215

138216
## Android
139217

assistant/src/main/java/com/ibm/watson/developer_cloud/assistant/v1/Assistant.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
import com.ibm.watson.developer_cloud.http.RequestBuilder;
8282
import com.ibm.watson.developer_cloud.http.ServiceCall;
8383
import com.ibm.watson.developer_cloud.service.WatsonService;
84+
import com.ibm.watson.developer_cloud.service.security.IamOptions;
8485
import com.ibm.watson.developer_cloud.util.GsonSingleton;
8586
import com.ibm.watson.developer_cloud.util.ResponseConverterUtils;
8687
import com.ibm.watson.developer_cloud.util.Validator;
@@ -129,6 +130,20 @@ public Assistant(String versionDate, String username, String password) {
129130
setUsernameAndPassword(username, password);
130131
}
131132

133+
/**
134+
* Instantiates a new `Assistant` with IAM. Note that if the access token is specified in the iamOptions,
135+
* you accept responsibility for managing the access token yourself. You must set a new access token before this one
136+
* expires. Failing to do so will result in authentication errors after this token expires.
137+
*
138+
* @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API
139+
* calls from failing when the service introduces breaking changes.
140+
* @param iamOptions the options for authenticating through IAM
141+
*/
142+
public Assistant(String versionDate, IamOptions iamOptions) {
143+
this(versionDate);
144+
setIamCredentials(iamOptions);
145+
}
146+
132147
/**
133148
* Get a response to a user's input. There is no rate limit for this operation.
134149
*
@@ -278,8 +293,8 @@ public ServiceCall<WorkspaceExport> getWorkspace(GetWorkspaceOptions getWorkspac
278293
/**
279294
* List workspaces.
280295
*
281-
* List the workspaces associated with an Assistant service instance. This operation is limited to 500 requests per 30
282-
* minutes. For more information, see **Rate limiting**.
296+
* List the workspaces associated with a Watson Assistant service instance. This operation is limited to 500 requests
297+
* per 30 minutes. For more information, see **Rate limiting**.
283298
*
284299
* @param listWorkspacesOptions the {@link ListWorkspacesOptions} containing the options for the call
285300
* @return a {@link ServiceCall} with a response type of {@link WorkspaceCollection}
@@ -311,8 +326,8 @@ public ServiceCall<WorkspaceCollection> listWorkspaces(ListWorkspacesOptions lis
311326
/**
312327
* List workspaces.
313328
*
314-
* List the workspaces associated with an Assistant service instance. This operation is limited to 500 requests per 30
315-
* minutes. For more information, see **Rate limiting**.
329+
* List the workspaces associated with a Watson Assistant service instance. This operation is limited to 500 requests
330+
* per 30 minutes. For more information, see **Rate limiting**.
316331
*
317332
* @return a {@link ServiceCall} with a response type of {@link WorkspaceCollection}
318333
*/

assistant/src/main/java/com/ibm/watson/developer_cloud/assistant/v1/model/CreateDialogNode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
*/
1313
package com.ibm.watson.developer_cloud.assistant.v1.model;
1414

15-
import com.google.gson.annotations.SerializedName;
16-
import com.ibm.watson.developer_cloud.service.model.GenericModel;
17-
import com.ibm.watson.developer_cloud.util.Validator;
18-
1915
import java.util.ArrayList;
2016
import java.util.List;
2117
import java.util.Map;
2218

19+
import com.google.gson.annotations.SerializedName;
20+
import com.ibm.watson.developer_cloud.service.model.GenericModel;
21+
import com.ibm.watson.developer_cloud.util.Validator;
22+
2323
/**
2424
* CreateDialogNode.
2525
*/

assistant/src/main/java/com/ibm/watson/developer_cloud/assistant/v1/model/DialogNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
*/
1313
package com.ibm.watson.developer_cloud.assistant.v1.model;
1414

15-
import com.google.gson.annotations.SerializedName;
16-
import com.ibm.watson.developer_cloud.service.model.GenericModel;
17-
1815
import java.util.Date;
1916
import java.util.List;
2017
import java.util.Map;
2118

19+
import com.google.gson.annotations.SerializedName;
20+
import com.ibm.watson.developer_cloud.service.model.GenericModel;
21+
2222
/**
2323
* DialogNode.
2424
*/

assistant/src/main/java/com/ibm/watson/developer_cloud/assistant/v1/model/DialogNodeVisitedDetails.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class DialogNodeVisitedDetails extends GenericModel {
2323
@SerializedName("dialog_node")
2424
private String dialogNode;
2525
private String title;
26+
private String conditions;
2627

2728
/**
2829
* Gets the dialogNode.
@@ -46,6 +47,17 @@ public String getTitle() {
4647
return title;
4748
}
4849

50+
/**
51+
* Gets the conditions.
52+
*
53+
* The conditions that trigger the dialog node.
54+
*
55+
* @return the conditions
56+
*/
57+
public String getConditions() {
58+
return conditions;
59+
}
60+
4961
/**
5062
* Sets the dialogNode.
5163
*
@@ -63,4 +75,13 @@ public void setDialogNode(final String dialogNode) {
6375
public void setTitle(final String title) {
6476
this.title = title;
6577
}
78+
79+
/**
80+
* Sets the conditions.
81+
*
82+
* @param conditions the new conditions
83+
*/
84+
public void setConditions(final String conditions) {
85+
this.conditions = conditions;
86+
}
6687
}

assistant/src/main/java/com/ibm/watson/developer_cloud/assistant/v1/model/ListAllLogsOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public Long pageLimit() {
167167
/**
168168
* Gets the cursor.
169169
*
170-
* A token identifying the last object from the previous page of results.
170+
* A token identifying the page of results to retrieve.
171171
*
172172
* @return the cursor
173173
*/

assistant/src/main/java/com/ibm/watson/developer_cloud/assistant/v1/model/ListCounterexamplesOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public String sort() {
205205
/**
206206
* Gets the cursor.
207207
*
208-
* A token identifying the last object from the previous page of results.
208+
* A token identifying the page of results to retrieve.
209209
*
210210
* @return the cursor
211211
*/

assistant/src/main/java/com/ibm/watson/developer_cloud/assistant/v1/model/ListDialogNodesOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public String sort() {
205205
/**
206206
* Gets the cursor.
207207
*
208-
* A token identifying the last object from the previous page of results.
208+
* A token identifying the page of results to retrieve.
209209
*
210210
* @return the cursor
211211
*/

assistant/src/main/java/com/ibm/watson/developer_cloud/assistant/v1/model/ListEntitiesOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public String sort() {
232232
/**
233233
* Gets the cursor.
234234
*
235-
* A token identifying the last object from the previous page of results.
235+
* A token identifying the page of results to retrieve.
236236
*
237237
* @return the cursor
238238
*/

assistant/src/main/java/com/ibm/watson/developer_cloud/assistant/v1/model/ListExamplesOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public String sort() {
234234
/**
235235
* Gets the cursor.
236236
*
237-
* A token identifying the last object from the previous page of results.
237+
* A token identifying the page of results to retrieve.
238238
*
239239
* @return the cursor
240240
*/

0 commit comments

Comments
 (0)