Skip to content

Commit 73d527f

Browse files
committed
wip
1 parent 1b58d4f commit 73d527f

File tree

5 files changed

+96
-7
lines changed

5 files changed

+96
-7
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ given Access Token:
3434
```
3535
// Initialize your client with your Rev AI access token
3636
String accessToken = "Your Access Token";
37-
ApiClient apiClient = new ApiClient(accessToken);
37+
// Optionally set the Rev AI deployment base url to use
38+
String baseUrl = RevAiApiDeploymentConfiguration.getConfig(RevAiApiDeploymentConfiguration.RevAiApiDeployment.US).getBaseUrl();
39+
ApiClient apiClient = new ApiClient(accessToken, baseUrl);
3840
```
3941

4042
### Checking credits remaining

src/main/java/ai/rev/helpers/ClientHelper.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ai.rev.helpers;
22

3+
import ai.rev.helpers.RevAiApiDeploymentConfiguration;
34
import okhttp3.OkHttpClient;
45
import retrofit2.Retrofit;
56
import retrofit2.converter.gson.GsonConverterFactory;
@@ -19,10 +20,16 @@ public static OkHttpClient createOkHttpClient(String accessToken) {
1920
public static Retrofit createRetrofitInstance(
2021
OkHttpClient client,
2122
String apiName,
22-
String apiVersion
23+
String apiVersion,
24+
String baseUrl
2325
) {
2426
return new Retrofit.Builder()
25-
.baseUrl(String.format("https://api.rev.ai/%s/%s/", apiName, apiVersion))
27+
.baseUrl(String.format(
28+
"%s/%s/%s/",
29+
baseUrl != null ? baseUrl : RevAiApiDeploymentConfiguration.getConfig(RevAiApiDeploymentConfiguration.RevAiApiDeployment.US).getBaseUrl(),
30+
apiName,
31+
apiVersion
32+
))
2633
.addConverterFactory(ScalarsConverterFactory.create())
2734
.addConverterFactory(GsonConverterFactory.create())
2835
.client(client)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package ai.rev.helpers;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class RevAiApiDeploymentConfiguration {
7+
8+
// Enum for API deployment regions
9+
public enum RevAiApiDeployment {
10+
US("US"),
11+
EU("EU");
12+
13+
private final String value;
14+
15+
RevAiApiDeployment(String value) {
16+
this.value = value;
17+
}
18+
19+
public String getValue() {
20+
return value;
21+
}
22+
}
23+
24+
// Configuration map for deployment URLs
25+
private static final Map<RevAiApiDeployment, DeploymentConfig> RevAiApiDeploymentConfigMap;
26+
27+
static {
28+
RevAiApiDeploymentConfigMap = new HashMap<>();
29+
RevAiApiDeploymentConfigMap.put(
30+
RevAiApiDeployment.US,
31+
new DeploymentConfig("https://api.rev.ai", "wss://api.rev.ai")
32+
);
33+
RevAiApiDeploymentConfigMap.put(
34+
RevAiApiDeployment.EU,
35+
new DeploymentConfig("https://ec1.api.rev.ai", "wss://ec1.api.rev.ai")
36+
);
37+
}
38+
39+
// Inner class for deployment configurations
40+
public static class DeploymentConfig {
41+
private final String baseUrl;
42+
private final String baseWebsocketUrl;
43+
44+
public DeploymentConfig(String baseUrl, String baseWebsocketUrl) {
45+
this.baseUrl = baseUrl;
46+
this.baseWebsocketUrl = baseWebsocketUrl;
47+
}
48+
49+
public String getBaseUrl() {
50+
return baseUrl;
51+
}
52+
53+
public String getBaseWebsocketUrl() {
54+
return baseWebsocketUrl;
55+
}
56+
}
57+
58+
// Method to get the configuration for a specific deployment
59+
public static DeploymentConfig getConfig(RevAiApiDeployment deployment) {
60+
return RevAiApiDeploymentConfigMap.get(deployment);
61+
}
62+
}

src/main/java/ai/rev/languageid/LanguageIdClient.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ai.rev.languageid;
22

33
import ai.rev.helpers.ClientHelper;
4+
import ai.rev.helpers.RevAiApiDeploymentConfiguration;
45
import ai.rev.languageid.models.LanguageIdJob;
56
import ai.rev.languageid.models.LanguageIdJobOptions;
67
import ai.rev.languageid.models.LanguageIdResult;
@@ -38,14 +39,22 @@ public class LanguageIdClient {
3839
* href="https://www.rev.ai/access_token">https://www.rev.ai/access_token</a>.
3940
*
4041
* @param accessToken Rev AI authorization token associate with the account.
42+
* @param baseUrl Optional url of the Rev AI API deployment to use, defaults to the US
43+
deployement, i.e. 'https://api.rev.ai', which can be referenced as
44+
RevAiApiDeploymentConfiguration.getConfig(RevAiApiDeploymentConfiguration.RevAiApiDeployment.US).getBaseUrl().
4145
* @throws IllegalArgumentException If the access token is null or empty.
4246
*/
43-
public LanguageIdClient(String accessToken) {
47+
public LanguageIdClient(String accessToken, String baseUrl) {
4448
if (accessToken == null || accessToken.isEmpty()) {
4549
throw new IllegalArgumentException("Access token must be provided");
4650
}
4751
this.client = ClientHelper.createOkHttpClient(accessToken);
48-
Retrofit retrofit = ClientHelper.createRetrofitInstance(client, "languageid", "v1");
52+
Retrofit retrofit = ClientHelper.createRetrofitInstance(
53+
client,
54+
"languageid",
55+
"v1",
56+
baseUrl != null ? baseUrl : RevAiApiDeploymentConfiguration.getConfig(RevAiApiDeploymentConfiguration.RevAiApiDeployment.US).getBaseUrl()
57+
);
4958
this.apiInterface = retrofit.create(LanguageIdInterface.class);
5059
}
5160

src/main/java/ai/rev/speechtotext/ApiClient.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ai.rev.speechtotext;
22

33
import ai.rev.helpers.ClientHelper;
4+
import ai.rev.helpers.RevAiApiDeploymentConfiguration;
45
import ai.rev.speechtotext.models.asynchronous.*;
56
import okhttp3.MediaType;
67
import okhttp3.MultipartBody;
@@ -33,14 +34,22 @@ public class ApiClient {
3334
* href="https://www.rev.ai/access_token">https://www.rev.ai/access_token</a>.
3435
*
3536
* @param accessToken Rev AI authorization token associate with the account.
37+
* @param baseUrl Optional url of the Rev AI API deployment to use, defaults to the US
38+
deployement, i.e. 'https://api.rev.ai', which can be referenced as
39+
RevAiApiDeploymentConfiguration.getConfig(RevAiApiDeploymentConfiguration.RevAiApiDeployment.US).getBaseUrl().
3640
* @throws IllegalArgumentException If the access token is null or empty.
3741
*/
38-
public ApiClient(String accessToken) {
42+
public ApiClient(String accessToken, String baseUrl) {
3943
if (accessToken == null || accessToken.isEmpty()) {
4044
throw new IllegalArgumentException("Access token must be provided");
4145
}
4246
this.client = ClientHelper.createOkHttpClient(accessToken);
43-
Retrofit retrofit = ClientHelper.createRetrofitInstance(client, "speechtotext", "v1");
47+
Retrofit retrofit = ClientHelper.createRetrofitInstance(
48+
client,
49+
"speechtotext",
50+
"v1",
51+
baseUrl != null ? baseUrl : RevAiApiDeploymentConfiguration.getConfig(RevAiApiDeploymentConfiguration.RevAiApiDeployment.US).getBaseUrl()
52+
);
4453
this.apiInterface = retrofit.create(ApiInterface.class);
4554
}
4655

0 commit comments

Comments
 (0)