Skip to content

Commit b5137d7

Browse files
authored
feat(endpoint): Added Recordings Endpoint
Added a new endpoint to query Recordings from a RestComm Connect server. Closes BS-128
1 parent b914339 commit b5137d7

File tree

7 files changed

+195
-14
lines changed

7 files changed

+195
-14
lines changed

src/main/java/org/restcomm/sdk/RestcommClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public RestEndpoints<CallPage> getCallsEndpoint() {
2929
return getEndpoints("calls", baseRestcommUrl + "/Calls.json", CallPage.class);
3030
}
3131

32+
public RestEndpoints<RecordingPage> getRecordingsEndpoint() {
33+
return getEndpoints("recordings", baseRestcommUrl + "/Recordings.json", RecordingPage.class);
34+
}
35+
3236
public RestEndpoints<Client> getClientsEndpoints() {
3337
return getEndpoints("clients", baseRestcommUrl + "/Clients.json", Client.class);
3438
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.restcomm.sdk.domain;
2+
3+
import lombok.Getter;
4+
import lombok.ToString;
5+
6+
/**
7+
* Common content of a paginated result entry.
8+
*
9+
* @author Henrique Rosa ([email protected]) created on 22/05/2018
10+
*/
11+
@Getter
12+
@ToString
13+
public abstract class AbstractPageHeader {
14+
15+
protected int page;
16+
protected int numPages;
17+
protected int pageSize;
18+
protected int total;
19+
protected int start;
20+
protected int end;
21+
protected String uri;
22+
protected String firstPageUri;
23+
protected String previousPageUri;
24+
protected String nextPageUri;
25+
protected String lastPageUri;
26+
27+
}

src/main/java/org/restcomm/sdk/domain/CallPage.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,16 @@
77
import java.util.List;
88

99
/**
10-
* Represents a paginated Calls result.
10+
* Represents a paginated set of Calls bound to an Account.
1111
*
1212
* @author Henrique Rosa ([email protected]) created on 21/05/2018
13-
*
1413
* @see <a href=https://www.restcomm.com/docs/connect/api/calls-api.html#paging-information>Calls API</a>
1514
*/
1615
@Builder(toBuilder = true)
1716
@Getter
1817
@ToString
19-
public class CallPage {
18+
public class CallPage extends AbstractPageHeader {
2019

21-
private int page;
22-
private int numPages;
23-
private int pageSize;
24-
private int total;
25-
private int start;
26-
private int end;
27-
private String uri;
28-
private String firstPageUri;
29-
private String previousPageUri;
30-
private String nextPageUri;
31-
private String lastPageUri;
3220
private List<Call> calls;
3321

3422
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.restcomm.sdk.domain;
2+
3+
import lombok.Builder;
4+
import lombok.Getter;
5+
import lombok.ToString;
6+
7+
/**
8+
* Represents a Recording bound to a Call.
9+
*
10+
* @author Henrique Rosa ([email protected]) created on 22/05/2018
11+
* @see <a href=https://www.restcomm.com/docs/connect/api/recordings-api.html#Recordings>Calls API</a>
12+
*/
13+
@Builder(toBuilder = true)
14+
@Getter
15+
@ToString
16+
public class Recording {
17+
18+
private String sid;
19+
private String dateCreated;
20+
private String dateUpdated;
21+
private String accountSid;
22+
private String callSid;
23+
private double duration;
24+
private String apiVersion;
25+
private String uri;
26+
private String fileUri;
27+
28+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.restcomm.sdk.domain;
2+
3+
import lombok.Builder;
4+
import lombok.Getter;
5+
import lombok.ToString;
6+
7+
import java.util.List;
8+
9+
/**
10+
* Represents a paginated set of Recording bound to an Account.
11+
*
12+
* @author Henrique Rosa ([email protected]) created on 22/05/2018
13+
* @see <a href=https://www.restcomm.com/docs/connect/api/recordings-api.html#paging-information>Recordings API</a>
14+
*/
15+
@Builder(toBuilder = true)
16+
@Getter
17+
@ToString
18+
public class RecordingPage extends AbstractPageHeader {
19+
20+
private List<Recording> recordings;
21+
22+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package org.restcomm.sdk.endpoints;
2+
3+
import com.github.tomakehurst.wiremock.junit.WireMockRule;
4+
import org.junit.Rule;
5+
import org.junit.Test;
6+
import org.restcomm.sdk.RestcommClient;
7+
import org.restcomm.sdk.RestcommClientConfiguration;
8+
import org.restcomm.sdk.domain.Recording;
9+
import org.restcomm.sdk.domain.RecordingPage;
10+
11+
import java.io.File;
12+
import java.io.IOException;
13+
import java.nio.file.Files;
14+
import java.util.Collections;
15+
import java.util.List;
16+
17+
import static com.github.tomakehurst.wiremock.client.WireMock.*;
18+
import static org.junit.Assert.assertEquals;
19+
import static org.junit.Assert.assertNotNull;
20+
21+
/**
22+
* @author Henrique Rosa ([email protected]) created on 22/05/2018
23+
*/
24+
public class RecordingsEndpointTest {
25+
26+
@Rule
27+
public WireMockRule wireMock = new WireMockRule();
28+
29+
@Test
30+
public void testGetRecordingPage() throws IOException {
31+
// given
32+
final String username = "username";
33+
final String password = "password";
34+
final String baseUrl = "http://localhost:" + wireMock.port();
35+
final RestcommClient client = new RestcommClient(RestcommClientConfiguration.builder().accountSid(username).accountToken(password).baseUrl(baseUrl).build());
36+
final RestEndpoints<RecordingPage> endpoint = client.getRecordingsEndpoint();
37+
38+
final File file = new File("src/test/resources/responses/recordings-response.json");
39+
final String response = new String(Files.readAllBytes(file.toPath()));
40+
41+
stubFor(get(urlPathEqualTo("/restcomm/2012-04-24/Accounts/" + username + "/Recordings.json"))
42+
.withBasicAuth(username, password)
43+
.willReturn(okJson(response)));
44+
45+
// when
46+
final RecordingPage resultPage = endpoint.findOne(Collections.emptyMap());
47+
48+
// then
49+
assertNotNull(resultPage);
50+
assertEquals(0, resultPage.getPage());
51+
assertEquals(397, resultPage.getNumPages());
52+
assertEquals(50, resultPage.getPageSize());
53+
assertEquals(19858, resultPage.getTotal());
54+
assertEquals(0, resultPage.getStart());
55+
assertEquals(49, resultPage.getEnd());
56+
assertEquals("/restcomm/2012-04-24/Accounts/AC12345/Recordings", resultPage.getUri());
57+
assertEquals("/restcomm/2012-04-24/Accounts/AC12345/Recordings?Page\u003d0\u0026PageSize\u003d50", resultPage.getFirstPageUri());
58+
assertEquals("null", resultPage.getPreviousPageUri());
59+
assertEquals("/restcomm/2012-04-24/Accounts/AC12345/Recordings?Page\u003d1\u0026PageSize\u003d50\u0026AfterSid\u003dRE22222", resultPage.getNextPageUri());
60+
assertEquals("/restcomm/2012-04-24/Accounts/AC12345/Recordings?Page\u003d397\u0026PageSize\u003d50", resultPage.getLastPageUri());
61+
final List<Recording> recordings = resultPage.getRecordings();
62+
assertNotNull(recordings);
63+
assertEquals(2, recordings.size());
64+
assertEquals("RE11111", recordings.get(0).getSid());
65+
assertEquals("Fri, 25 Sep 2015 15:59:56 +0000", recordings.get(0).getDateCreated());
66+
assertEquals("Fri, 25 Sep 2015 15:59:56 +0000", recordings.get(0).getDateUpdated());
67+
assertEquals("AC12345", recordings.get(0).getAccountSid());
68+
assertEquals("CA11111", recordings.get(0).getCallSid());
69+
assertEquals(9.72275, recordings.get(0).getDuration(), 0);
70+
assertEquals("2012-04-24", recordings.get(0).getApiVersion());
71+
assertEquals("/2012-04-24/Accounts/AC12345/Recordings/RE11111.json", recordings.get(0).getUri());
72+
assertEquals("https://some.domain.com/restcomm/2012-04-24/Accounts/AC12345/Recordings/RE11111.wav", recordings.get(0).getFileUri());
73+
}
74+
75+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"page": 0,
3+
"num_pages": 397,
4+
"page_size": 50,
5+
"total": 19858,
6+
"start": "0",
7+
"end": "49",
8+
"uri": "/restcomm/2012-04-24/Accounts/AC12345/Recordings",
9+
"first_page_uri": "/restcomm/2012-04-24/Accounts/AC12345/Recordings?Page\u003d0\u0026PageSize\u003d50",
10+
"previous_page_uri": "null",
11+
"next_page_uri": "/restcomm/2012-04-24/Accounts/AC12345/Recordings?Page\u003d1\u0026PageSize\u003d50\u0026AfterSid\u003dRE22222",
12+
"last_page_uri": "/restcomm/2012-04-24/Accounts/AC12345/Recordings?Page\u003d397\u0026PageSize\u003d50",
13+
"recordings": [
14+
{
15+
"sid": "RE11111",
16+
"date_created": "Fri, 25 Sep 2015 15:59:56 +0000",
17+
"date_updated": "Fri, 25 Sep 2015 15:59:56 +0000",
18+
"account_sid": "AC12345",
19+
"call_sid": "CA11111",
20+
"duration": "9.72275",
21+
"api_version": "2012-04-24",
22+
"uri": "/2012-04-24/Accounts/AC12345/Recordings/RE11111.json",
23+
"file_uri": "https://some.domain.com/restcomm/2012-04-24/Accounts/AC12345/Recordings/RE11111.wav"
24+
},
25+
{
26+
"sid": "RE22222",
27+
"date_created": "Wed, 4 Nov 2015 19:00:47 +0000",
28+
"date_updated": "Wed, 19 Jul 2017 08:24:26 +0000",
29+
"account_sid": "AC12345",
30+
"call_sid": "CA22222",
31+
"duration": "10.10275",
32+
"api_version": "2012-04-24",
33+
"uri": "/2012-04-24/Accounts/AC12345/Recordings/RE22222.json",
34+
"file_uri": "https://some.domain.com/restcomm/2012-04-24/Accounts/AC12345/Recordings/RE22222.wav"
35+
}
36+
]
37+
}

0 commit comments

Comments
 (0)