Skip to content

Commit

Permalink
AISDK-190: Update sdks to support notification_config and source_conf…
Browse files Browse the repository at this point in the history
…ig (#46)
  • Loading branch information
aaron-wilson-rev authored May 10, 2022
1 parent 3dd0183 commit 31a0c5a
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 19 deletions.
2 changes: 0 additions & 2 deletions src/main/java/ai/rev/helpers/ClientHelper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package ai.rev.helpers;

import ai.rev.helpers.ApiInterceptor;
import ai.rev.helpers.ErrorInterceptor;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package ai.rev.sentimentanalysis;

import ai.rev.helpers.ClientHelper;
import ai.rev.speechtotext.ApiClient;
import ai.rev.speechtotext.models.asynchronous.RevAiJob;
import ai.rev.speechtotext.models.asynchronous.RevAiJobOptions;
import ai.rev.sentimentanalysis.models.Sentiment;
import ai.rev.sentimentanalysis.models.SentimentAnalysisJob;
import ai.rev.sentimentanalysis.models.SentimentAnalysisJobOptions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package ai.rev.sentimentanalysis.models;

import ai.rev.speechtotext.models.CustomerUrlData;
import ai.rev.speechtotext.models.asynchronous.RevAiTranscript;

import com.google.gson.annotations.SerializedName;

import java.util.Map;

/**
* A SentimentAnalysisJobOptions object represents parameters that are submitted along a new job.
*
Expand All @@ -24,11 +26,17 @@ public class SentimentAnalysisJobOptions {
private RevAiTranscript json;

/**
* The callback url that Rev AI will send a POST to when the job has finished.
* The callback url that Rev AI will send a POST to when the job has finished.
* @deprecated Use notification_config instead
*/
@SerializedName("callback_url")
@Deprecated
private String callbackUrl;


/** Object containing information on the callback url that Rev AI will send a POST to when the job has finished. */
@SerializedName("notification_config")
private CustomerUrlData notificationConfig;

/**
* Optional information that can be provided.
*/
Expand Down Expand Up @@ -81,7 +89,9 @@ public void setJson(RevAiTranscript json) {
* Returns the callback url.
*
* @return the callback url.
* @deprecated Use notificationConfig and getNotificationConfig instead
*/
@Deprecated
public String getCallbackUrl() {
return callbackUrl;
}
Expand All @@ -91,11 +101,41 @@ public String getCallbackUrl() {
* property is optional.
*
* @param callbackUrl The url to POST to when job processing is complete.
* @deprecated Use setNotificationConfig instead
*/
@Deprecated
public void setCallbackUrl(String callbackUrl) {
this.callbackUrl = callbackUrl;
}


/**
* Returns the notification config object.
*
* @return the notification config.
*/
public CustomerUrlData getNotificationConfig() {
return notificationConfig;
}

/**
* Optional property to specify the callback url that Rev AI will POST to when job processing is complete
*
* @param callbackUrl The url to POST to when job processing is complete.
* @param authHeaders Optional parameter to authenticate access to the callback url
*/
public void setNotificationConfig(String callbackUrl, Map<String, String> authHeaders) {
this.notificationConfig = new CustomerUrlData(callbackUrl, authHeaders);
}

/**
* Optional property to specify the callback url that Rev AI will POST to when job processing is complete
*
* @param callbackUrl The url to POST to when job processing is complete.
*/
public void setNotificationConfig(String callbackUrl) {
setNotificationConfig(callbackUrl, null);
}

/**
* Returns the metadata.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public class RevAiJobOptions {
* @return The media url.
* @deprecated Set sourceConfig and use getSourceConfig instead
*/
@Deprecated
public String getMediaUrl() {
return mediaUrl;
}
Expand All @@ -141,6 +142,7 @@ public String getMediaUrl() {
* @param mediaUrl The direct download url to the file.
* @deprecated Use setSourceConfig instead
*/
@Deprecated
public void setMediaUrl(String mediaUrl) {
this.mediaUrl = mediaUrl;
}
Expand Down Expand Up @@ -180,8 +182,9 @@ public void setSourceConfig(String sourceMediaUrl) {
* Returns the callback url.
*
* @return the callback url.
* @deprecated Set the notificationConfig option with setNotificationConfig, then use getNotificationConfig instead
* @deprecated Use notificationConfig and getNotificationConfig instead
*/
@Deprecated
public String getCallbackUrl() {
return callbackUrl;
}
Expand All @@ -193,6 +196,7 @@ public String getCallbackUrl() {
* @param callbackUrl The url to POST to when job processing is complete.
* @deprecated Use setNotificationConfig instead
*/
@Deprecated
public void setCallbackUrl(String callbackUrl) {
this.callbackUrl = callbackUrl;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package ai.rev.topicextraction;

import ai.rev.helpers.ClientHelper;
import ai.rev.speechtotext.ApiClient;
import ai.rev.speechtotext.models.asynchronous.RevAiJob;
import ai.rev.speechtotext.models.asynchronous.RevAiJobOptions;
import ai.rev.topicextraction.models.TopicExtractionJob;
import ai.rev.topicextraction.models.TopicExtractionJobOptions;
import ai.rev.topicextraction.models.TopicExtractionResult;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package ai.rev.topicextraction.models;

import ai.rev.speechtotext.models.CustomerUrlData;
import ai.rev.speechtotext.models.asynchronous.RevAiTranscript;

import com.google.gson.annotations.SerializedName;

import java.util.Map;

/**
* A TopicExtractionJobOptions object represents parameters that are submitted along a new job.
*
Expand All @@ -22,12 +24,18 @@ public class TopicExtractionJobOptions {
*/
@SerializedName("json")
private RevAiTranscript json;

/**
* The callback url that Rev AI will send a POST to when the job has finished.

/**
* The callback url that Rev AI will send a POST to when the job has finished.
* @deprecated Use notification_config instead
*/
@SerializedName("callback_url")
@Deprecated
private String callbackUrl;

/** Object containing information on the callback url that Rev AI will send a POST to when the job has finished. */
@SerializedName("notification_config")
private CustomerUrlData notificationConfig;

/**
* Optional information that can be provided.
Expand Down Expand Up @@ -76,12 +84,14 @@ public RevAiTranscript getJson() {
public void setJson(RevAiTranscript json) {
this.json = json;
}

/**
* Returns the callback url.
*
* @return the callback url.
* @deprecated Use notificationConfig and getNotificationConfig instead
*/
@Deprecated
public String getCallbackUrl() {
return callbackUrl;
}
Expand All @@ -91,10 +101,40 @@ public String getCallbackUrl() {
* property is optional.
*
* @param callbackUrl The url to POST to when job processing is complete.
* @deprecated Use setNotificationConfig instead
*/
@Deprecated
public void setCallbackUrl(String callbackUrl) {
this.callbackUrl = callbackUrl;
}

/**
* Returns the notification config object.
*
* @return the notification config.
*/
public CustomerUrlData getNotificationConfig() {
return notificationConfig;
}

/**
* Optional property to specify the callback url that Rev AI will POST to when job processing is complete
*
* @param callbackUrl The url to POST to when job processing is complete.
* @param authHeaders Optional parameter to authenticate access to the callback url
*/
public void setNotificationConfig(String callbackUrl, Map<String, String> authHeaders) {
this.notificationConfig = new CustomerUrlData(callbackUrl, authHeaders);
}

/**
* Optional property to specify the callback url that Rev AI will POST to when job processing is complete
*
* @param callbackUrl The url to POST to when job processing is complete.
*/
public void setNotificationConfig(String callbackUrl) {
setNotificationConfig(callbackUrl, null);
}

/**
* Returns the metadata.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class SubmitJobTest {
(new Gson()).fromJson(
getFileContents(Paths.get("./src/test/java/ai/rev/sentimentanalysis/resources/sample.json")),
RevAiTranscript.class);
private final String CALLBACK_URL = "https://example.com";
private static SentimentAnalysisClient apiClient;

@Rule public TestName testName = new TestName();
Expand All @@ -46,6 +47,19 @@ public void SubmitJobText_TextAndOptionsSpecified_ReturnsJobInProgress()
assertSentimentAnalysisJob(job);
}

@Test
public void SubmitJobText_TextAndOptionsWithNotificationConfig_ReturnsJobInProgress()
throws IOException {
SentimentAnalysisJobOptions jobOptions = getJobOptions();
jobOptions.setCallbackUrl(null);
jobOptions.setNotificationConfig(CALLBACK_URL);

SentimentAnalysisJob job = apiClient.submitJobText(TEXT_SOURCE, jobOptions);

assertSentimentAnalysisJob(job);
assert job.getCallbackUrl() == null;
}

@Test
public void SubmitJobText_OnlyTextIsSpecified_ReturnsJobInProgress()
throws IOException {
Expand Down Expand Up @@ -81,7 +95,7 @@ public void assertSentimentAnalysisJob(SentimentAnalysisJob job) {
private SentimentAnalysisJobOptions getJobOptions() {
SentimentAnalysisJobOptions revAiJobOptions = new SentimentAnalysisJobOptions();
revAiJobOptions.setMetadata(testName.getMethodName());
revAiJobOptions.setCallbackUrl("https://example.com");
revAiJobOptions.setCallbackUrl(CALLBACK_URL);
revAiJobOptions.setDeleteAfterSeconds(0);
return revAiJobOptions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class SubmitJobTest {
(new Gson()).fromJson(
getFileContents(Paths.get("./src/test/java/ai/rev/topicextraction/resources/sample.json")),
RevAiTranscript.class);
private final String CALLBACK_URL ="https://example.com";
private static TopicExtractionClient apiClient;

@Rule public TestName testName = new TestName();
Expand All @@ -46,6 +47,19 @@ public void SubmitJobText_TextAndOptionsSpecified_ReturnsJobInProgress()
assertTopicExtractionJob(job);
}

@Test
public void SubmitJobText_TextAndOptionsWithNotificationConfig_ReturnsJobInProgress()
throws IOException {
TopicExtractionJobOptions jobOptions = getJobOptions();
jobOptions.setCallbackUrl(null);
jobOptions.setNotificationConfig(CALLBACK_URL);

TopicExtractionJob job = apiClient.submitJobText(TEXT_SOURCE, jobOptions);

assertTopicExtractionJob(job);
assert job.getCallbackUrl() == null;
}

@Test
public void SubmitJobText_OnlyTextIsSpecified_ReturnsJobInProgress()
throws IOException {
Expand Down

0 comments on commit 31a0c5a

Please sign in to comment.