Skip to content

Commit ae10871

Browse files
committed
overlod
1 parent 674a4ba commit ae10871

File tree

3 files changed

+85
-18
lines changed

3 files changed

+85
-18
lines changed

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

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

3-
import ai.rev.helpers.RevAiApiDeploymentConfiguration;
43
import okhttp3.OkHttpClient;
54
import retrofit2.Retrofit;
65
import retrofit2.converter.gson.GsonConverterFactory;
@@ -17,6 +16,24 @@ public static OkHttpClient createOkHttpClient(String accessToken) {
1716
.build();
1817
}
1918

19+
public static Retrofit createRetrofitInstance(
20+
OkHttpClient client,
21+
String apiName,
22+
String apiVersion
23+
) {
24+
return new Retrofit.Builder()
25+
.baseUrl(String.format(
26+
"%s/%s/%s/",
27+
RevAiApiDeploymentConfiguration.getConfig(RevAiApiDeploymentConfiguration.RevAiApiDeployment.US).getBaseUrl(),
28+
apiName,
29+
apiVersion
30+
))
31+
.addConverterFactory(ScalarsConverterFactory.create())
32+
.addConverterFactory(GsonConverterFactory.create())
33+
.client(client)
34+
.build();
35+
}
36+
2037
public static Retrofit createRetrofitInstance(
2138
OkHttpClient client,
2239
String apiName,

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

+29-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
package ai.rev.languageid;
22

3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.IOException;
6+
import java.io.InputStream;
7+
import java.util.HashMap;
8+
import java.util.List;
9+
import java.util.Map;
10+
311
import ai.rev.helpers.ClientHelper;
412
import ai.rev.helpers.RevAiApiDeploymentConfiguration;
513
import ai.rev.languageid.models.LanguageIdJob;
@@ -12,14 +20,6 @@
1220
import okhttp3.RequestBody;
1321
import retrofit2.Retrofit;
1422

15-
import java.io.File;
16-
import java.io.FileInputStream;
17-
import java.io.IOException;
18-
import java.io.InputStream;
19-
import java.util.HashMap;
20-
import java.util.List;
21-
import java.util.Map;
22-
2323
/**
2424
* The LanguageIdClient object provides methods to send and retrieve information from all the
2525
* Rev AI Language Identification API endpoints using the Retrofit HTTP client.
@@ -58,6 +58,27 @@ public LanguageIdClient(String accessToken, String baseUrl) {
5858
this.apiInterface = retrofit.create(LanguageIdInterface.class);
5959
}
6060

61+
/**
62+
* Constructs the API client used to send HTTP requests to Rev AI. The user access token can be
63+
* generated on the website at <a
64+
* href="https://www.rev.ai/access_token">https://www.rev.ai/access_token</a>.
65+
*
66+
* @param accessToken Rev AI authorization token associate with the account.
67+
* @throws IllegalArgumentException If the access token is null or empty.
68+
*/
69+
public LanguageIdClient(String accessToken) {
70+
if (accessToken == null || accessToken.isEmpty()) {
71+
throw new IllegalArgumentException("Access token must be provided");
72+
}
73+
this.client = ClientHelper.createOkHttpClient(accessToken);
74+
Retrofit retrofit = ClientHelper.createRetrofitInstance(
75+
client,
76+
"languageid",
77+
"v1"
78+
);
79+
this.apiInterface = retrofit.create(LanguageIdInterface.class);
80+
}
81+
6182
/**
6283
* Manually closes the connection when the code is running in a JVM
6384
*/

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

+38-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
package ai.rev.speechtotext;
22

3-
import ai.rev.helpers.ClientHelper;
4-
import ai.rev.helpers.RevAiApiDeploymentConfiguration;
5-
import ai.rev.speechtotext.models.asynchronous.*;
6-
import okhttp3.MediaType;
7-
import okhttp3.MultipartBody;
8-
import okhttp3.OkHttpClient;
9-
import okhttp3.RequestBody;
10-
import retrofit2.Retrofit;
11-
123
import java.io.File;
134
import java.io.FileInputStream;
145
import java.io.IOException;
@@ -17,6 +8,20 @@
178
import java.util.List;
189
import java.util.Map;
1910

11+
import ai.rev.helpers.ClientHelper;
12+
import ai.rev.helpers.RevAiApiDeploymentConfiguration;
13+
import ai.rev.speechtotext.models.asynchronous.RevAiAccount;
14+
import ai.rev.speechtotext.models.asynchronous.RevAiCaptionType;
15+
import ai.rev.speechtotext.models.asynchronous.RevAiJob;
16+
import ai.rev.speechtotext.models.asynchronous.RevAiJobOptions;
17+
import ai.rev.speechtotext.models.asynchronous.RevAiTranscript;
18+
import ai.rev.speechtotext.models.asynchronous.Summary;
19+
import okhttp3.MediaType;
20+
import okhttp3.MultipartBody;
21+
import okhttp3.OkHttpClient;
22+
import okhttp3.RequestBody;
23+
import retrofit2.Retrofit;
24+
2025
/**
2126
* The ApiClient object provides methods to send and retrieve information from all the Rev AI API
2227
* endpoints using the Retrofit HTTP client.
@@ -53,6 +58,30 @@ public ApiClient(String accessToken, String baseUrl) {
5358
this.apiInterface = retrofit.create(ApiInterface.class);
5459
}
5560

61+
/**
62+
* Constructs the API client used to send HTTP requests to Rev AI. The user access token can be
63+
* generated on the website at <a
64+
* href="https://www.rev.ai/access_token">https://www.rev.ai/access_token</a>.
65+
*
66+
* @param accessToken Rev AI authorization token associate with the account.
67+
* @param baseUrl Optional url of the Rev AI API deployment to use, defaults to the US
68+
deployement, i.e. 'https://api.rev.ai', which can be referenced as
69+
RevAiApiDeploymentConfiguration.getConfig(RevAiApiDeploymentConfiguration.RevAiApiDeployment.US).getBaseUrl().
70+
* @throws IllegalArgumentException If the access token is null or empty.
71+
*/
72+
public ApiClient(String accessToken) {
73+
if (accessToken == null || accessToken.isEmpty()) {
74+
throw new IllegalArgumentException("Access token must be provided");
75+
}
76+
this.client = ClientHelper.createOkHttpClient(accessToken);
77+
Retrofit retrofit = ClientHelper.createRetrofitInstance(
78+
client,
79+
"speechtotext",
80+
"v1"
81+
);
82+
this.apiInterface = retrofit.create(ApiInterface.class);
83+
}
84+
5685
/** Manually closes the connection when the code is running in a JVM */
5786
public void closeConnection() {
5887
client.dispatcher().executorService().shutdown();

0 commit comments

Comments
 (0)