Skip to content

Commit

Permalink
feat: Add Voice.leg_persistence_time field
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Oct 17, 2024
1 parent ffdcb11 commit 787b071
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public final class Voice extends Capability {
private Region region;
private Boolean signedCallbacks;
private Integer conversationsTtl;
private Integer conversationsTtl, legPersistenceTime;

private Voice() {
}
Expand All @@ -36,6 +36,9 @@ private Voice(Builder builder) {
if ((conversationsTtl = builder.conversationsTtl) != null && (conversationsTtl < 0 || conversationsTtl > 744)) {
throw new IllegalArgumentException("Conversations TTL cannot be negative.");
}
if ((legPersistenceTime = builder.legPersistenceTime) != null && (legPersistenceTime < 0 || legPersistenceTime > 31)) {
throw new IllegalArgumentException("Leg persistence time must be positive and less than 31 days.");
}
}

/**
Expand Down Expand Up @@ -77,6 +80,18 @@ public Integer getConversationsTtl() {
return conversationsTtl;
}

/**
* Persistence duration for conversation legs, in days. Maximum value is 31, default is 7.
*
* @return The leg persistence time in dats as an integer, or {@code null} if unknown.
*
* @since 8.12.0
*/
@JsonProperty("leg_persistence_time")
public Integer getLegPersistenceTime() {
return legPersistenceTime;
}

@Override
public Type getType() {
return Type.VOICE;
Expand All @@ -94,7 +109,7 @@ public static Builder builder() {
public static class Builder extends Capability.Builder<Voice, Builder> {
private Region region;
private Boolean signedCallbacks;
private Integer conversationsTtl;
private Integer conversationsTtl, legPersistenceTime;

/**
* Selecting a region means all inbound, programmable SIP and SIP connect calls will be sent to the selected
Expand Down Expand Up @@ -140,6 +155,19 @@ public Builder conversationsTtl(int ttl) {
return this;
}

/**
* Persistence duration for conversation legs, in days. Maximum value is 31, default is 7.
*
* @param legPersistenceTime The leg persistence time in days.
*
* @return This builder.
* @since 8.12.0
*/
public Builder legPersistenceTime(int legPersistenceTime) {
this.legPersistenceTime = legPersistenceTime;
return this;
}

@Override
public Builder addWebhook(Webhook.Type type, Webhook webhook) {
return super.addWebhook(type, webhook);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class ApplicationClientTest extends AbstractClientTest<ApplicationClient>
" \"payment_enabled\": false,\n" +
" \"signed_callbacks\": true,\n" +
" \"conversations_ttl\": 24,\n" +
" \"leg_persistence_time\": 7,\n" +
" \"region\": \"eu-west\",\n" +
" \"payments\": {\n" +
" \"gateways\": []\n" +
Expand Down Expand Up @@ -130,6 +131,7 @@ static void assertEqualsSampleApplication(Application response) {
assertEquals(3000, fallback.getSocketTimeout().intValue());
assertEquals(Region.EU_WEST, voice.getRegion());
assertEquals(24, voice.getConversationsTtl().intValue());
assertEquals(7, voice.getLegPersistenceTime().intValue());
assertTrue(voice.getSignedCallbacks());

Messages message = capabilities.getMessages();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public void testEmpty() {

assertEquals(Capability.Type.VOICE, voice.getType());
assertNull(voice.getWebhooks());
assertNull(voice.getRegion());
assertNull(voice.getSignedCallbacks());
assertNull(voice.getConversationsTtl());
assertNull(voice.getLegPersistenceTime());
}

@Test
Expand Down Expand Up @@ -70,11 +74,15 @@ public void testRemoveWebhook() {
.addWebhook(Webhook.Type.ANSWER, new Webhook("https://example.com/answer", HttpMethod.POST))
.addWebhook(Webhook.Type.EVENT, new Webhook("https://example.com/event", HttpMethod.GET))
.removeWebhook(Webhook.Type.ANSWER)
.legPersistenceTime(3).signedCallbacks(false)
.build();

assertEquals(Capability.Type.VOICE, voice.getType());
assertEquals("https://example.com/event", voice.getWebhooks().get(Webhook.Type.EVENT).getAddress());
assertEquals(HttpMethod.GET, voice.getWebhooks().get(Webhook.Type.EVENT).getMethod());
assertNull(voice.getWebhooks().get(Webhook.Type.ANSWER));
assertEquals(3, voice.getLegPersistenceTime());
assertFalse(voice.getSignedCallbacks());
}

@Test
Expand Down Expand Up @@ -119,13 +127,18 @@ public void testWebhookProperties() {
@Test
public void testSerializeAdditionalFields() {
Voice request = Voice.builder()
.conversationsTtl(51).signedCallbacks(false).region(Region.APAC_SNG).build();
.conversationsTtl(51)
.signedCallbacks(false)
.region(Region.APAC_SNG)
.legPersistenceTime(14)
.build();

class Internal implements Jsonable {
@JsonProperty final Voice voice = request;
}
String expectedJson = "{\"voice\":{" +
"\"region\":\"apac-sng\",\"signed_callbacks\":false,\"conversations_ttl\":51}}";
"\"region\":\"apac-sng\",\"signed_callbacks\":false,\"conversations_ttl\":51" +
",\"leg_persistence_time\":14}}";
assertEquals(expectedJson, new Internal().toJson());
}

Expand All @@ -137,4 +150,13 @@ public void testConversationsTtlBounds() {
assertThrows(IllegalArgumentException.class, () -> Voice.builder().conversationsTtl(min-1).build());
assertThrows(IllegalArgumentException.class, () -> Voice.builder().conversationsTtl(max+1).build());
}

@Test
public void testLegPersistenceTimeBounds() {
Integer min = 0, max = 31;
assertEquals(min, Voice.builder().legPersistenceTime(min).build().getLegPersistenceTime());
assertEquals(max, Voice.builder().legPersistenceTime(max).build().getLegPersistenceTime());
assertThrows(IllegalArgumentException.class, () -> Voice.builder().legPersistenceTime(min-1).build());
assertThrows(IllegalArgumentException.class, () -> Voice.builder().legPersistenceTime(max+1).build());
}
}

0 comments on commit 787b071

Please sign in to comment.