Skip to content

Commit a6af35e

Browse files
authored
Merge pull request #901 from watson-developer-cloud/develop
Release v5.1.1
2 parents bf15fcb + 2184fbb commit a6af35e

File tree

27 files changed

+945
-533
lines changed

27 files changed

+945
-533
lines changed

.bumpversion.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ current_version = 5.1.0
33

44
[bumpversion:file:README.md]
55

6+
[bumpversion:file:assistant/README.md]
7+
68
[bumpversion:file:conversation/README.md]
79

810
[bumpversion:file:discovery/README.md]

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Java client library to use the [Watson APIs][wdc].
1616
* [Usage](#usage)
1717
* [Getting the Service Credentials](#getting-the-service-credentials)
1818
* IBM Watson Services
19-
* [Conversation](conversation)
19+
* [Assistant](assistant)
2020
* [Discovery](discovery)
2121
* [Language Translator](language-translator)
2222
* [Natural Language Classifier](natural-language-classifier)
@@ -71,10 +71,10 @@ All the services:
7171
'com.ibm.watson.developer_cloud:java-sdk:5.1.0'
7272
```
7373

74-
Only Conversation:
74+
Only Assistant:
7575

7676
```gradle
77-
'com.ibm.watson.developer_cloud:conversation:5.1.0'
77+
'com.ibm.watson.developer_cloud:assistant:5.0.1'
7878
```
7979

8080
##### Development Snapshots
@@ -143,7 +143,7 @@ Override the `configureHttpClient()` method and add the proxy using the `OkHttpC
143143
For example:
144144

145145
```java
146-
Conversation service = new Conversation("2018-02-16") {
146+
Assistant service = new Assistant("2018-02-16") {
147147
@Override
148148
protected OkHttpClient configureHttpClient() {
149149
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyHost", 8080));
@@ -196,7 +196,7 @@ For example, if you have the conversation service in Germany, the Endpoint may b
196196
You will need to call
197197

198198
```java
199-
Conversation service = new Conversation("2018-02-16");
199+
Assistant service = new Assistant("2018-02-16");
200200
service.sentEndPoint("https://gateway-fra.watsonplatform.net/conversation/api")
201201
```
202202

@@ -295,4 +295,5 @@ or [Stack Overflow](http://stackoverflow.com/questions/ask?tags=ibm-watson).
295295
[sonatype_snapshots]: https://oss.sonatype.org/content/repositories/snapshots/com/ibm/watson/developer_cloud/
296296
[vcap_services]: https://docs.run.pivotal.io/devguide/deploy-apps/environment-variable.html#VCAP-SERVICES
297297

298-
[jar]: https://github.com/watson-developer-cloud/java-sdk/releases/download/java-sdk-4.2.0/java-sdk-5.1.0-jar-with-dependencies.jar
298+
299+
[jar]: https://github.com/watson-developer-cloud/java-sdk/releases/download/java-sdk-5.1.0/java-sdk-5.1.0-jar-with-dependencies.jar

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

Lines changed: 175 additions & 84 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.google.gson.stream.JsonToken;
1919
import com.google.gson.stream.JsonWriter;
2020
import com.ibm.watson.developer_cloud.assistant.v1.model.LogPagination;
21-
import com.ibm.watson.developer_cloud.util.RequestUtils;
2221
import okhttp3.HttpUrl;
2322

2423
import java.io.IOException;
@@ -30,6 +29,7 @@ public class LogPaginationTypeAdapter extends TypeAdapter<LogPagination> {
3029
private static final String MATCHED = "matched";
3130
private static final String NEXT_URL = "next_url";
3231
private static final String CURSOR = "cursor";
32+
private static final String DEFAULT_ENDPOINT = "http://do.not.use";
3333

3434
/*
3535
* (non-Javadoc)
@@ -60,7 +60,7 @@ public LogPagination read(JsonReader reader) throws IOException {
6060
String name = reader.nextName();
6161
if (name.equals(NEXT_URL)) {
6262
String nextUrl = reader.nextString();
63-
HttpUrl url = HttpUrl.parse(RequestUtils.DEFAULT_ENDPOINT + nextUrl);
63+
HttpUrl url = HttpUrl.parse(DEFAULT_ENDPOINT + nextUrl);
6464
pagination.setCursor(url.queryParameter(CURSOR));
6565
pagination.setNextUrl(nextUrl);
6666
} else if (name.equals(MATCHED)) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.google.gson.stream.JsonToken;
1919
import com.google.gson.stream.JsonWriter;
2020
import com.ibm.watson.developer_cloud.assistant.v1.model.Pagination;
21-
import com.ibm.watson.developer_cloud.util.RequestUtils;
2221
import okhttp3.HttpUrl;
2322

2423
import java.io.IOException;
@@ -32,6 +31,7 @@ public class PaginationTypeAdapter extends TypeAdapter<Pagination> {
3231
private static final String NEXT_URL = "next_url";
3332
private static final String REFRESH_URL = "refresh_url";
3433
private static final String CURSOR = "cursor";
34+
private static final String DEFAULT_ENDPOINT = "http://do.not.use";
3535

3636
/*
3737
* (non-Javadoc)
@@ -66,7 +66,7 @@ public Pagination read(JsonReader reader) throws IOException {
6666
pagination.setRefreshUrl(reader.nextString());
6767
} else if (name.equals(NEXT_URL)) {
6868
String nextUrl = reader.nextString();
69-
HttpUrl url = HttpUrl.parse(RequestUtils.DEFAULT_ENDPOINT + nextUrl);
69+
HttpUrl url = HttpUrl.parse(DEFAULT_ENDPOINT + nextUrl);
7070
pagination.setCursor(url.queryParameter(CURSOR));
7171
pagination.setNextUrl(nextUrl);
7272
} else if (name.equals(TOTAL)) {

config.properties.enc

0 Bytes
Binary file not shown.

conversation/src/main/java/com/ibm/watson/developer_cloud/conversation/v1/Conversation.java

Lines changed: 176 additions & 84 deletions
Large diffs are not rendered by default.

conversation/src/main/java/com/ibm/watson/developer_cloud/conversation/v1/model/util/LogPaginationTypeAdapter.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,23 @@
1313
*/
1414
package com.ibm.watson.developer_cloud.conversation.v1.model.util;
1515

16-
import java.io.IOException;
17-
1816
import com.google.gson.TypeAdapter;
1917
import com.google.gson.stream.JsonReader;
2018
import com.google.gson.stream.JsonToken;
2119
import com.google.gson.stream.JsonWriter;
2220
import com.ibm.watson.developer_cloud.conversation.v1.model.LogPagination;
23-
import com.ibm.watson.developer_cloud.util.RequestUtils;
24-
2521
import okhttp3.HttpUrl;
2622

23+
import java.io.IOException;
24+
2725
/**
2826
* Type adapter to transform JSON into a {@link LogPagination} and vice versa.
2927
*/
3028
public class LogPaginationTypeAdapter extends TypeAdapter<LogPagination> {
3129
private static final String MATCHED = "matched";
3230
private static final String NEXT_URL = "next_url";
3331
private static final String CURSOR = "cursor";
32+
private static final String DEFAULT_ENDPOINT = "http://do.not.use";
3433

3534
/*
3635
* (non-Javadoc)
@@ -61,7 +60,7 @@ public LogPagination read(JsonReader reader) throws IOException {
6160
String name = reader.nextName();
6261
if (name.equals(NEXT_URL)) {
6362
String nextUrl = reader.nextString();
64-
HttpUrl url = HttpUrl.parse(RequestUtils.DEFAULT_ENDPOINT + nextUrl);
63+
HttpUrl url = HttpUrl.parse(DEFAULT_ENDPOINT + nextUrl);
6564
pagination.setCursor(url.queryParameter(CURSOR));
6665
pagination.setNextUrl(nextUrl);
6766
} else if (name.equals(MATCHED)) {

conversation/src/main/java/com/ibm/watson/developer_cloud/conversation/v1/model/util/PaginationTypeAdapter.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@
1313
*/
1414
package com.ibm.watson.developer_cloud.conversation.v1.model.util;
1515

16-
import java.io.IOException;
17-
1816
import com.google.gson.TypeAdapter;
1917
import com.google.gson.stream.JsonReader;
2018
import com.google.gson.stream.JsonToken;
2119
import com.google.gson.stream.JsonWriter;
2220
import com.ibm.watson.developer_cloud.conversation.v1.model.Pagination;
23-
import com.ibm.watson.developer_cloud.util.RequestUtils;
24-
2521
import okhttp3.HttpUrl;
2622

23+
import java.io.IOException;
24+
2725
/**
2826
* Type adapter to transform JSON into a {@link Pagination} and vice versa.
2927
*/
@@ -33,6 +31,7 @@ public class PaginationTypeAdapter extends TypeAdapter<Pagination> {
3331
private static final String NEXT_URL = "next_url";
3432
private static final String REFRESH_URL = "refresh_url";
3533
private static final String CURSOR = "cursor";
34+
private static final String DEFAULT_ENDPOINT = "http://do.not.use";
3635

3736
/*
3837
* (non-Javadoc)
@@ -67,7 +66,7 @@ public Pagination read(JsonReader reader) throws IOException {
6766
pagination.setRefreshUrl(reader.nextString());
6867
} else if (name.equals(NEXT_URL)) {
6968
String nextUrl = reader.nextString();
70-
HttpUrl url = HttpUrl.parse(RequestUtils.DEFAULT_ENDPOINT + nextUrl);
69+
HttpUrl url = HttpUrl.parse(DEFAULT_ENDPOINT + nextUrl);
7170
pagination.setCursor(url.queryParameter(CURSOR));
7271
pagination.setNextUrl(nextUrl);
7372
} else if (name.equals(TOTAL)) {

core/src/main/java/com/ibm/watson/developer_cloud/http/RequestBuilder.java

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,17 @@
1212
*/
1313
package com.ibm.watson.developer_cloud.http;
1414

15-
import java.util.ArrayList;
16-
import java.util.List;
17-
1815
import com.google.gson.JsonObject;
19-
import com.ibm.watson.developer_cloud.util.RequestUtils;
2016
import com.ibm.watson.developer_cloud.util.Validator;
21-
2217
import okhttp3.FormBody;
2318
import okhttp3.HttpUrl;
2419
import okhttp3.MediaType;
2520
import okhttp3.Request;
2621
import okhttp3.RequestBody;
2722

23+
import java.util.ArrayList;
24+
import java.util.List;
25+
2826
/**
2927
* Convenience class for constructing HTTP/HTTPS requests.
3028
*/
@@ -41,7 +39,7 @@ private enum HTTPMethod {
4139
*
4240
* @return this
4341
*/
44-
public static RequestBuilder delete(String url) {
42+
public static RequestBuilder delete(HttpUrl url) {
4543
return new RequestBuilder(HTTPMethod.DELETE, url);
4644
}
4745

@@ -52,7 +50,7 @@ public static RequestBuilder delete(String url) {
5250
*
5351
* @return this
5452
*/
55-
public static RequestBuilder get(String url) {
53+
public static RequestBuilder get(HttpUrl url) {
5654
return new RequestBuilder(HTTPMethod.GET, url);
5755
}
5856

@@ -64,7 +62,7 @@ public static RequestBuilder get(String url) {
6462
*
6563
* @return this
6664
*/
67-
public static RequestBuilder post(String url) {
65+
public static RequestBuilder post(HttpUrl url) {
6866
return new RequestBuilder(HTTPMethod.POST, url);
6967
}
7068

@@ -75,10 +73,44 @@ public static RequestBuilder post(String url) {
7573
*
7674
* @return this
7775
*/
78-
public static RequestBuilder put(String url) {
76+
public static RequestBuilder put(HttpUrl url) {
7977
return new RequestBuilder(HTTPMethod.PUT, url);
8078
}
8179

80+
/**
81+
* Creates a properly encoded HttpUrl object with no path parameters.
82+
*
83+
* @param endPoint the API end point
84+
* @param pathSegments the path segments for a specific API call
85+
* @return the HttpUrl object
86+
*/
87+
public static HttpUrl constructHttpUrl(String endPoint, String[] pathSegments) {
88+
HttpUrl.Builder httpUrlBuilder = HttpUrl.parse(endPoint).newBuilder();
89+
for (String segment : pathSegments) {
90+
httpUrlBuilder.addPathSegments(segment);
91+
}
92+
return httpUrlBuilder.build();
93+
}
94+
95+
/**
96+
* Creates a properly encoded HttpUrl object with path parameters.
97+
*
98+
* @param endPoint the API end point
99+
* @param pathSegments the path segments for a specific API call
100+
* @param pathParameters the path parameters for a specific API call
101+
* @return the HttpUrl object
102+
*/
103+
public static HttpUrl constructHttpUrl(String endPoint, String[] pathSegments, String[] pathParameters) {
104+
HttpUrl.Builder httpUrlBuilder = HttpUrl.parse(endPoint).newBuilder();
105+
for (int i = 0; i < pathSegments.length; i++) {
106+
httpUrlBuilder.addPathSegments(pathSegments[i]);
107+
if (i < pathParameters.length) {
108+
httpUrlBuilder.addPathSegment(pathParameters[i]);
109+
}
110+
}
111+
return httpUrlBuilder.build();
112+
}
113+
82114
private RequestBody body;
83115
private HttpUrl httpUrl;
84116
private final List<NameValue> formParams = new ArrayList<NameValue>();
@@ -92,17 +124,13 @@ public static RequestBuilder put(String url) {
92124
* @param method the method, PUT, POST, GET or DELETE
93125
* @param url the request URL
94126
*/
95-
private RequestBuilder(HTTPMethod method, String url) {
127+
private RequestBuilder(HTTPMethod method, HttpUrl url) {
96128
this.method = method;
97129
if (url == null) {
98130
throw new IllegalArgumentException("url cannot be null");
99131
}
100132

101-
// Since HttpUrl requires requires a http/s full url, add a default endpoint
102-
httpUrl = HttpUrl.parse(url);
103-
if (httpUrl == null) {
104-
httpUrl = HttpUrl.parse(RequestUtils.DEFAULT_ENDPOINT + url);
105-
}
133+
this.httpUrl = url;
106134
}
107135

108136
/**
@@ -119,7 +147,7 @@ private RequestBuilder(HTTPMethod method, String url) {
119147
* @param params the parameters
120148
* @param name the parameter name
121149
* @param value the value to set, will be obtained via {@link String#valueOf(boolean)}. If null, only the parameter is
122-
* set. It can also be a collection or array, in which case all elements are added as query parameters
150+
* set. It can also be a collection or array, in which case all elements are added as query parameters
123151
*
124152
* @return this
125153
*/
@@ -159,7 +187,6 @@ public Request build() {
159187
// URL
160188
builder.url(toUrl());
161189

162-
163190
if (method == HTTPMethod.GET) {
164191
Validator.isNull(body, "cannot send a RequestBody in a GET request");
165192
} else if (!formParams.isEmpty()) {
@@ -190,7 +217,6 @@ public Request build() {
190217

191218
/*
192219
* (non-Javadoc)
193-
*
194220
* @see java.lang.Object#toString()
195221
*/
196222
@Override
@@ -299,5 +325,4 @@ public RequestBuilder header(Object... args) {
299325
public RequestBuilder query(Object... args) {
300326
return with(queryParams, args);
301327
}
302-
303328
}

0 commit comments

Comments
 (0)