|
1 | 1 | package ai.rev.speechtotext;
|
2 | 2 |
|
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 |
| - |
12 | 3 | import java.io.File;
|
13 | 4 | import java.io.FileInputStream;
|
14 | 5 | import java.io.IOException;
|
|
17 | 8 | import java.util.List;
|
18 | 9 | import java.util.Map;
|
19 | 10 |
|
| 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 | + |
20 | 25 | /**
|
21 | 26 | * The ApiClient object provides methods to send and retrieve information from all the Rev AI API
|
22 | 27 | * endpoints using the Retrofit HTTP client.
|
@@ -53,6 +58,30 @@ public ApiClient(String accessToken, String baseUrl) {
|
53 | 58 | this.apiInterface = retrofit.create(ApiInterface.class);
|
54 | 59 | }
|
55 | 60 |
|
| 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 | + |
56 | 85 | /** Manually closes the connection when the code is running in a JVM */
|
57 | 86 | public void closeConnection() {
|
58 | 87 | client.dispatcher().executorService().shutdown();
|
|
0 commit comments