Skip to content

Commit

Permalink
feat: Add Rtc.signed_callbacks field
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Oct 17, 2024
1 parent 354d02b commit ffdcb11
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
37 changes: 37 additions & 0 deletions src/main/java/com/vonage/client/application/capabilities/Rtc.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,40 @@
*/
package com.vonage.client.application.capabilities;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.common.Webhook;

/**
* Rtc capability configuration settings.
*/
public final class Rtc extends Capability {
private Boolean signedCallbacks;

private Rtc() {
}

private Rtc(Builder builder) {
super(builder);
this.signedCallbacks = builder.signedCallbacks;
}

@Override
public Type getType() {
return Type.RTC;
}

/**
* Whether to use signed webhooks. This is a way of verifying that the request is coming from Vonage.
*
* @return {@code true} if signed webhooks are used, {@code false} if not and {@code null} if unknown.
*
* @since 8.12.0
*/
@JsonProperty("signed_callbacks")
public Boolean getSignedCallbacks() {
return signedCallbacks;
}

/**
* Entry point for constructing an instance of this class.
*
Expand All @@ -44,6 +59,28 @@ public static Builder builder() {
}

public static class Builder extends Capability.Builder<Rtc, Builder> {
private Boolean signedCallbacks;

/**
* Constructs a new Builder.
*
* @deprecated Use {@link #builder()} instead. This constructor will be made private in a future release.
*/
@Deprecated
public Builder() {
}

/**
* Set whether to use signed webhooks. This is a way of verifying that the request is coming from Vonage.
*
* @param signedCallbacks {@code true} if signed webhooks should be used.
* @return This builder.
* @since 8.12.0
*/
public Builder signedCallbacks(boolean signedCallbacks) {
this.signedCallbacks = signedCallbacks;
return this;
}

@Override
public Builder addWebhook(Webhook.Type type, Webhook webhook) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public class ApplicationClientTest extends AbstractClientTest<ApplicationClient>
" \"address\": \"https://example.com/webhooks/event\",\n" +
" \"http_method\": \"POST\"\n" +
" }\n" +
" }\n" +
" },\n" +
" \"signed_callbacks\": true\n" +
" },\n" +
" \"vbc\": {},\n" +
" \"verify\": {\n" +
Expand Down Expand Up @@ -147,6 +148,7 @@ static void assertEqualsSampleApplication(Application response) {
assertEquals(Capability.Type.RTC, rtc.getType());
assertEquals("https://example.com/webhooks/event", rtc.getWebhooks().get(Webhook.Type.EVENT).getAddress());
assertEquals(HttpMethod.POST, rtc.getWebhooks().get(Webhook.Type.EVENT).getMethod());
assertTrue(rtc.getSignedCallbacks());

Vbc vbc = capabilities.getVbc();
assertEquals(Capability.Type.VBC, vbc.getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ public void testEmpty() {

assertEquals(Capability.Type.RTC, rtc.getType());
assertNull(rtc.getWebhooks());
assertNull(rtc.getSignedCallbacks());
}

@Test
public void testEventWebhook() {
Rtc rtc = Rtc.builder().addWebhook(Webhook.Type.EVENT, new Webhook("https://example.com/event", HttpMethod.GET)).build();
Rtc rtc = Rtc.builder()
.addWebhook(Webhook.Type.EVENT, new Webhook("https://example.com/event", HttpMethod.GET))
.signedCallbacks(true).build();

assertEquals(Capability.Type.RTC, rtc.getType());
assertEquals("https://example.com/event", rtc.getWebhooks().get(Webhook.Type.EVENT).getAddress());
assertTrue(rtc.getSignedCallbacks());
assertEquals(HttpMethod.GET, rtc.getWebhooks().get(Webhook.Type.EVENT).getMethod());
}

Expand All @@ -43,9 +47,10 @@ public void testRemoveWebhook() {
Rtc rtc = Rtc.builder()
.addWebhook(Webhook.Type.EVENT, new Webhook("https://example.com/event", HttpMethod.POST))
.removeWebhook(Webhook.Type.EVENT)
.build();
.signedCallbacks(false).build();

assertEquals(Capability.Type.RTC, rtc.getType());
assertFalse(rtc.getSignedCallbacks());
assertNull(rtc.getWebhooks());
}
}

0 comments on commit ffdcb11

Please sign in to comment.