Skip to content

Commit 1d23ce0

Browse files
authored
Merge pull request #79 from guilhermehubner/list-recordings
feat(voice) list recordings
2 parents ea2d7a8 + 065fd28 commit 1d23ce0

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

voice/recording.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ func ReadRecording(c *messagebird.Client, callID, legID, id string) (*Recording,
8080
return json.Data[0], nil
8181
}
8282

83+
// Recordings returns a Paginator which iterates over Recordings.
84+
func Recordings(c *messagebird.Client, callID, legID string) *Paginator {
85+
return newPaginator(c, fmt.Sprintf("%s/v1/calls/%s/legs/%s/recordings", apiRoot, callID,
86+
legID), reflect.TypeOf(Recording{}))
87+
}
88+
8389
// UnmarshalJSON implements the json.Unmarshaler interface.
8490
func (rec *Recording) UnmarshalJSON(data []byte) error {
8591
recording := new(jsonRecording)

voice/recording_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,33 @@ func TestReadRecording(t *testing.T) {
5555

5656
mbtest.AssertEndpointCalled(t, http.MethodGet, "/v1/calls/callid/legs/legid/recordings/recid")
5757
}
58+
59+
func TestRecordings(t *testing.T) {
60+
mbtest.WillReturnTestdata(t, "recordingPaginatorObject.json", http.StatusOK)
61+
client := mbtest.Client(t)
62+
63+
paginator := Recordings(client, "callid", "legid")
64+
65+
data, err := paginator.NextPage()
66+
if err != nil {
67+
t.Fatalf("unexpected error read recording: %s", err)
68+
}
69+
70+
recordings := data.([]Recording)
71+
72+
if len(recordings) != 2 {
73+
t.Errorf("got %d recordings expect 1", len(recordings))
74+
}
75+
76+
if recordings[0].ID != "recid" {
77+
t.Errorf("expect %s got %s", "recid", recordings[0].ID)
78+
}
79+
if recordings[0].LegID != "legid" {
80+
t.Errorf("expect %s got %s", "legid", recordings[0].LegID)
81+
}
82+
if recordings[0].Status != RecordingStatusDone {
83+
t.Errorf("expect %s got %s", RecordingStatusDone, recordings[0].Status)
84+
}
85+
86+
mbtest.AssertEndpointCalled(t, http.MethodGet, "/v1/calls/callid/legs/legid/recordings")
87+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"_links": {
3+
"self": "/calls/callid/legs/legid/recordings"
4+
},
5+
"pagination": {
6+
"totalCount": 2,
7+
"pageCount": 1,
8+
"currentPage": 1,
9+
"perPage": 10
10+
},
11+
"data": [
12+
{
13+
"id": "recid",
14+
"format": "wav",
15+
"legId": "legid",
16+
"status": "done",
17+
"duration": 6,
18+
"type": "call",
19+
"createdAt": "2020-03-10T13:11:31Z",
20+
"updatedAt": "2020-03-10T13:11:38Z",
21+
"deletedAt": null,
22+
"_links": {
23+
"file": "/recordings/recid.wav",
24+
"self": "/recordings/recid"
25+
}
26+
},
27+
{
28+
"id": "recid",
29+
"format": "wav",
30+
"legId": "legid",
31+
"status": "done",
32+
"duration": 6,
33+
"type": "call",
34+
"createdAt": "2020-03-10T13:11:31Z",
35+
"updatedAt": "2020-03-10T13:11:38Z",
36+
"deletedAt": null,
37+
"_links": {
38+
"file": "/recordings/recid.wav",
39+
"self": "/recordings/recid"
40+
}
41+
}
42+
]
43+
}

0 commit comments

Comments
 (0)