Skip to content

Commit e5c7eb9

Browse files
kayhubaaiham
authored andcommitted
support listArchives with sessionId, fixes #122 (#132)
* [#122] listArchives with sessionId now supported * [#122] Fixed indentation / code formatting
1 parent 35383b1 commit e5c7eb9

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/main/java/com/opentok/OpenTok.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,23 @@ public ArchiveList listArchives(int offset, int count) throws OpenTokException {
340340
}
341341
}
342342

343+
/***
344+
* Returns a List of {@link Archive} objects, representing archives that are both both completed and in-progress,
345+
* for your API key.
346+
*
347+
* @param sessionId
348+
* The sessionId for which archives should be retrieved.
349+
* @return A List of {@link Archive} objects.
350+
*/
351+
public ArchiveList listArchives(String sessionId) throws RequestException {
352+
String archives = this.client.getArchives(sessionId);
353+
try {
354+
return archiveListReader.readValue(archives);
355+
} catch (Exception e) {
356+
throw new RequestException("Exception mapping json: " + e.getMessage());
357+
}
358+
}
359+
343360
/**
344361
* Starts archiving an OpenTok session. This version of the <code>startArchive()</code> method
345362
* lets you disable audio or video recording.

src/main/java/com/opentok/util/HttpClient.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,28 @@ public String getArchives(int offset, int count) throws RequestException {
133133
return responseString;
134134
}
135135

136+
public String getArchives(String sessionId) throws RequestException {
137+
String url = this.apiUrl + "/v2/project/" + this.apiKey + "/archive?sessionId=" + sessionId;
138+
139+
Future<Response> request = this.prepareGet(url).execute();
140+
try {
141+
Response response = request.get();
142+
switch (response.getStatusCode()) {
143+
case 200:
144+
return response.getResponseBody();
145+
case 403:
146+
throw new RequestException("Could not get OpenTok Archives. The request was not authorized.");
147+
case 500:
148+
throw new RequestException("Could not get OpenTok Archives. A server error occurred.");
149+
default:
150+
throw new RequestException("Could not get an OpenTok Archive. The server response was invalid."
151+
+ " response code: " + response.getStatusCode());
152+
}
153+
} catch (InterruptedException | ExecutionException | IOException e) {
154+
throw new RequestException("Could not get OpenTok Archives", e);
155+
}
156+
}
157+
136158
public String startArchive(String sessionId, ArchiveProperties properties)
137159
throws OpenTokException {
138160
String responseString = null;

0 commit comments

Comments
 (0)