Skip to content

Commit

Permalink
Merge pull request #1036 from watson-developer-cloud/analytics-headers
Browse files Browse the repository at this point in the history
Add headers for analytics
  • Loading branch information
lpatino10 authored Feb 1, 2019
2 parents de4b9f8 + cdb81da commit eb7fd84
Show file tree
Hide file tree
Showing 14 changed files with 364 additions and 5 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public ServiceCall<SessionResponse> createSession(CreateSessionOptions createSes
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
pathParameters));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=conversation;service_version=v2;operation_id=createSession");
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(SessionResponse.class));
}

Expand All @@ -120,6 +122,8 @@ public ServiceCall<Void> deleteSession(DeleteSessionOptions deleteSessionOptions
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
pathParameters));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=conversation;service_version=v2;operation_id=deleteSession");
return createServiceCall(builder.build(), ResponseConverterUtils.getVoid());
}

Expand All @@ -140,6 +144,7 @@ public ServiceCall<MessageResponse> message(MessageOptions messageOptions) {
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
pathParameters));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics", "service_name=conversation;service_version=v2;operation_id=message");
final JsonObject contentJson = new JsonObject();
if (messageOptions.input() != null) {
contentJson.add("input", GsonSingleton.getGson().toJsonTree(messageOptions.input()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public ServiceCall<HTMLReturn> convertToHtml(ConvertToHtmlOptions convertToHtmlO
String[] pathSegments = { "v1/html_conversion" };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=compare-comply;service_version=v1;operation_id=convertToHtml");
if (convertToHtmlOptions.modelId() != null) {
builder.query("model_id", convertToHtmlOptions.modelId());
}
Expand All @@ -130,6 +132,8 @@ public ServiceCall<ClassifyReturn> classifyElements(ClassifyElementsOptions clas
String[] pathSegments = { "v1/element_classification" };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=compare-comply;service_version=v1;operation_id=classifyElements");
if (classifyElementsOptions.modelId() != null) {
builder.query("model_id", classifyElementsOptions.modelId());
}
Expand All @@ -155,6 +159,8 @@ public ServiceCall<TableReturn> extractTables(ExtractTablesOptions extractTables
String[] pathSegments = { "v1/tables" };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=compare-comply;service_version=v1;operation_id=extractTables");
if (extractTablesOptions.modelId() != null) {
builder.query("model_id", extractTablesOptions.modelId());
}
Expand All @@ -181,6 +187,8 @@ public ServiceCall<CompareReturn> compareDocuments(CompareDocumentsOptions compa
String[] pathSegments = { "v1/comparison" };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=compare-comply;service_version=v1;operation_id=compareDocuments");
if (compareDocumentsOptions.file1Label() != null) {
builder.query("file_1_label", compareDocumentsOptions.file1Label());
}
Expand Down Expand Up @@ -217,6 +225,8 @@ public ServiceCall<FeedbackReturn> addFeedback(AddFeedbackOptions addFeedbackOpt
String[] pathSegments = { "v1/feedback" };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=compare-comply;service_version=v1;operation_id=addFeedback");
final JsonObject contentJson = new JsonObject();
if (addFeedbackOptions.userId() != null) {
contentJson.addProperty("user_id", addFeedbackOptions.userId());
Expand All @@ -242,6 +252,8 @@ public ServiceCall<Void> deleteFeedback(DeleteFeedbackOptions deleteFeedbackOpti
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
pathParameters));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=compare-comply;service_version=v1;operation_id=deleteFeedback");
if (deleteFeedbackOptions.modelId() != null) {
builder.query("model_id", deleteFeedbackOptions.modelId());
}
Expand All @@ -261,6 +273,8 @@ public ServiceCall<GetFeedback> getFeedback(GetFeedbackOptions getFeedbackOption
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
pathParameters));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=compare-comply;service_version=v1;operation_id=getFeedback");
if (getFeedbackOptions.modelId() != null) {
builder.query("model_id", getFeedbackOptions.modelId());
}
Expand All @@ -277,6 +291,8 @@ public ServiceCall<FeedbackList> listFeedback(ListFeedbackOptions listFeedbackOp
String[] pathSegments = { "v1/feedback" };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=compare-comply;service_version=v1;operation_id=listFeedback");
if (listFeedbackOptions != null) {
if (listFeedbackOptions.feedbackType() != null) {
builder.query("feedback_type", listFeedbackOptions.feedbackType());
Expand Down Expand Up @@ -357,6 +373,8 @@ public ServiceCall<BatchStatus> createBatch(CreateBatchOptions createBatchOption
String[] pathSegments = { "v1/batches" };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=compare-comply;service_version=v1;operation_id=createBatch");
builder.query("function", createBatchOptions.function());
if (createBatchOptions.modelId() != null) {
builder.query("model_id", createBatchOptions.modelId());
Expand Down Expand Up @@ -394,6 +412,7 @@ public ServiceCall<BatchStatus> getBatch(GetBatchOptions getBatchOptions) {
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
pathParameters));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics", "service_name=compare-comply;service_version=v1;operation_id=getBatch");
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(BatchStatus.class));
}

Expand All @@ -409,6 +428,8 @@ public ServiceCall<Batches> listBatches(ListBatchesOptions listBatchesOptions) {
String[] pathSegments = { "v1/batches" };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=compare-comply;service_version=v1;operation_id=listBatches");
if (listBatchesOptions != null) {
}
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Batches.class));
Expand Down Expand Up @@ -441,6 +462,8 @@ public ServiceCall<BatchStatus> updateBatch(UpdateBatchOptions updateBatchOption
RequestBuilder builder = RequestBuilder.put(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
pathParameters));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=compare-comply;service_version=v1;operation_id=updateBatch");
builder.query("action", updateBatchOptions.action());
if (updateBatchOptions.modelId() != null) {
builder.query("model_id", updateBatchOptions.modelId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class RequestUtils {
private static final Logger LOG = Logger.getLogger(RequestUtils.class.getName());

private static final String[] properties =
new String[] { "java.vendor", "java.version", "os.arch", "os.name", "os.version" };
new String[] { "os.name", "os.version", "java.vendor", "java.version" };
private static String userAgent;

private RequestUtils() {
Expand Down Expand Up @@ -175,10 +175,10 @@ private static String loadSdkVersion() {
private static String buildUserAgent() {
final List<String> details = new ArrayList<String>();
for (String propertyName : properties) {
details.add(propertyName + "=" + System.getProperty(propertyName));
details.add(System.getProperty(propertyName));
}

return "watson-apis-java-sdk/" + loadSdkVersion() + " (" + RequestUtils.join(details, "; ") + ")";
return "watson-apis-java-sdk-" + loadSdkVersion() + " " + RequestUtils.join(details, " ");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public void testSpecialCharacterQuery() {
@Test
public void testUserAgent() {
assertNotNull(RequestUtils.getUserAgent());
assertTrue(RequestUtils.getUserAgent().startsWith("watson-apis-java-sdk/"));
assertTrue(RequestUtils.getUserAgent().startsWith("watson-apis-java-sdk-"));
}

}
Loading

0 comments on commit eb7fd84

Please sign in to comment.