-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Generic
getResponse
method for LeMUR
- Loading branch information
1 parent
27de673
commit 3293359
Showing
6 changed files
with
67 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.assemblyai.api; | ||
|
||
import com.assemblyai.api.core.ApiError; | ||
import com.assemblyai.api.core.ClientOptions; | ||
import com.assemblyai.api.core.ObjectMappers; | ||
import com.assemblyai.api.core.RequestOptions; | ||
import com.assemblyai.api.resources.lemur.LemurClient; | ||
import com.assemblyai.api.resources.lemur.types.ILemurBaseResponse; | ||
import okhttp3.*; | ||
|
||
import java.io.IOException; | ||
|
||
public final class EnhancedLemurClient extends LemurClient { | ||
public EnhancedLemurClient(ClientOptions clientOptions) { | ||
super(clientOptions); | ||
} | ||
|
||
/** | ||
* Retrieve a LeMUR response that was previously generated. | ||
*/ | ||
public <T extends ILemurBaseResponse> T getResponse(String requestId, Class<T> responseType) { | ||
return this.getResponse(requestId, responseType, null); | ||
} | ||
|
||
/** | ||
* Retrieve a LeMUR response that was previously generated. | ||
*/ | ||
public <T extends ILemurBaseResponse> T getResponse(String requestId, Class<T> responseType, RequestOptions requestOptions) { | ||
HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) | ||
.newBuilder() | ||
.addPathSegments("lemur/v3") | ||
.addPathSegment(requestId) | ||
.build(); | ||
Request okhttpRequest = new Request.Builder() | ||
.url(httpUrl) | ||
.method("GET", null) | ||
.headers(Headers.of(clientOptions.headers(requestOptions))) | ||
.addHeader("Content-Type", "application/json") | ||
.build(); | ||
try { | ||
OkHttpClient client = clientOptions.httpClient(); | ||
if (requestOptions != null && requestOptions.getTimeout().isPresent()) { | ||
client = clientOptions.httpClientWithTimeout(requestOptions); | ||
} | ||
Response response = client.newCall(okhttpRequest).execute(); | ||
ResponseBody responseBody = response.body(); | ||
if (response.isSuccessful()) { | ||
return ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), responseType); | ||
} | ||
throw new ApiError( | ||
response.code(), | ||
ObjectMappers.JSON_MAPPER.readValue( | ||
responseBody != null ? responseBody.string() : "{}", Object.class)); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.assemblyai.api.core; | ||
|
||
public class Constants { | ||
public static final String SDK_VERSION = "1.1.3"; | ||
public static final String SDK_VERSION = "2.0.0"; | ||
} |