Skip to content

Commit 8c4de0e

Browse files
authored
Merge pull request #103 from messagebird/deleteVoiceRecording
delete voice recording
2 parents db04bcb + b555b90 commit 8c4de0e

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

api/src/main/java/com/messagebird/MessageBirdClient.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,38 @@ public RecordingResponse listRecordings(String callID, String legId, final Integ
13451345
return messageBirdService.requestList(url, offset, limit, RecordingResponse.class);
13461346
}
13471347

1348+
/**
1349+
* Deletes a voice recording
1350+
*
1351+
* @param callID Voice call ID
1352+
* @param legID Leg ID
1353+
* @param recordingID Recording ID
1354+
* @throws UnauthorizedException if client is unauthorized
1355+
* @throws GeneralException general exception
1356+
*/
1357+
public void deleteRecording(final String callID, final String legID, final String recordingID)
1358+
throws NotFoundException, GeneralException, UnauthorizedException {
1359+
if (callID == null) {
1360+
throw new IllegalArgumentException("Call ID must be specified.");
1361+
}
1362+
if (legID == null) {
1363+
throw new IllegalArgumentException("Leg ID must be specified.");
1364+
}
1365+
if (recordingID == null) {
1366+
throw new IllegalArgumentException("Recording ID must be specified.");
1367+
}
1368+
String url = String.format(
1369+
"%s%s/%s%s/%s%s",
1370+
VOICE_CALLS_BASE_URL,
1371+
VOICECALLSPATH,
1372+
callID,
1373+
LEGSPATH,
1374+
legID,
1375+
RECORDINGPATH
1376+
);
1377+
messageBirdService.deleteByID(url, recordingID);
1378+
}
1379+
13481380
/**
13491381
* Function to view recording by call id , leg id and recording id
13501382
*

api/src/test/java/com/messagebird/MessageBirdClientTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,4 +938,20 @@ public void deletePurchasedNumber() throws UnauthorizedException, GeneralExcept
938938
verify(messageBirdServiceMock, times(1)).deleteByID(url, phoneNumber);
939939
}
940940

941+
@Test
942+
public void testDeleteRecording() throws NotFoundException, GeneralException, UnauthorizedException {
943+
MessageBirdService messageBirdServiceMock = mock(MessageBirdService.class);
944+
MessageBirdClient messageBirdClientMock = new MessageBirdClient(messageBirdServiceMock);
945+
String url = String.format(
946+
"%s%s/%s%s/%s%s",
947+
VOICE_CALLS_BASE_URL,
948+
VOICECALLSPATH,
949+
"ANY_CALL_ID",
950+
LEGSPATH,
951+
"ANY_LEG_ID",
952+
RECORDINGPATH
953+
);
954+
messageBirdClientMock.deleteRecording("ANY_CALL_ID", "ANY_LEG_ID","recordingID");
955+
verify(messageBirdServiceMock, times(1)).deleteByID(url , "recordingID");
956+
}
941957
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import com.messagebird.MessageBirdClient;
2+
import com.messagebird.MessageBirdService;
3+
import com.messagebird.MessageBirdServiceImpl;
4+
import com.messagebird.exceptions.GeneralException;
5+
import com.messagebird.exceptions.NotFoundException;
6+
import com.messagebird.exceptions.UnauthorizedException;
7+
8+
public class ExampleDeleteRecording {
9+
public static void main(String[] args) {
10+
11+
if (args.length < 3) {
12+
System.out.println("Please specify your access key and a call_id, leg_id, and recording_id to delete: java -jar <this jar file> <test_accesskey> <call_id> <leg_id> <recording_id>" );
13+
return;
14+
}
15+
16+
// First create your service object
17+
final MessageBirdService wsr = new MessageBirdServiceImpl(args[0]);
18+
19+
// Add the service to the client
20+
final MessageBirdClient messageBirdClient = new MessageBirdClient(wsr);
21+
22+
try {
23+
// Deleting message by id
24+
System.out.println("Delete recording:");
25+
messageBirdClient.deleteRecording(args[1],args[2],args[3]);
26+
System.out.println("Recording ID ["+args[3]+"] deleted.");
27+
28+
} catch (UnauthorizedException | GeneralException | NotFoundException exception) {
29+
if (exception.getErrors() != null) {
30+
System.out.println(exception.getErrors().toString());
31+
}
32+
exception.printStackTrace();
33+
}
34+
}
35+
}

examples/src/main/java/ExampleSendVoiceCall.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public static void main(String[] args) {
3131
final VoiceCall voiceCall = new VoiceCall();
3232
voiceCall.setSource("31644556677");
3333
voiceCall.setDestination(args[1]);
34+
voiceCall.setWebhook("https://example.com/","foobar");
3435

3536
//Title and steps are required fields for creating callFlow
3637
final VoiceCallFlow voiceCallFlow = new VoiceCallFlow();

0 commit comments

Comments
 (0)