diff --git a/src/main/java/com/twilio/type/RecordingRule.java b/src/main/java/com/twilio/type/RecordingRule.java
new file mode 100644
index 0000000000..986398da08
--- /dev/null
+++ b/src/main/java/com/twilio/type/RecordingRule.java
@@ -0,0 +1,195 @@
+package com.twilio.type;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.ToString;
+
+import java.util.Objects;
+
+/**
+ * Recording Rule
+ *
+ *
+ * For more information see:
+ * Specifying Recording Rules
+ *
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+@ToString
+public class RecordingRule implements Rule {
+
+ private static final RecordingRule recordAll = builder().withType(Type.INCLUDE).withAll().build();
+ private static final RecordingRule recordNone = builder().withType(Type.EXCLUDE).withAll().build();
+
+ @JsonProperty("type")
+ private final Type type;
+
+ @JsonProperty("all")
+ private final Boolean all;
+
+ @JsonProperty("publisher")
+ private final String publisher;
+
+ @JsonProperty("track")
+ private final String track;
+
+ @JsonProperty("kind")
+ private final Kind kind;
+
+ public RecordingRule(@JsonProperty("type") final Type type,
+ @JsonProperty("all") final Boolean all,
+ @JsonProperty("publisher") final String publisher,
+ @JsonProperty("track") final String track,
+ @JsonProperty("kind") final Kind kind) {
+ this.type = type;
+ this.all = all;
+ this.publisher = publisher;
+ this.track = track;
+ this.kind = kind;
+ }
+
+ public RecordingRule() {
+ this.type = null;
+ this.all = null;
+ this.publisher = null;
+ this.track = null;
+ this.kind = null;
+ }
+
+ public static BuilderStart builder() {
+ return new Builder();
+ }
+
+ public interface BuilderStart {
+ BuilderMiddle withType(final Type type);
+ }
+
+ public interface BuilderMiddle {
+ BuilderMiddleBuild withPublisher(final String publisher);
+ BuilderMiddleBuild withKind(final Kind kind);
+ BuilderMiddleBuild withTrack(final String track);
+ BuilderBuild withAll();
+ }
+
+ public interface BuilderMiddleBuild {
+ BuilderMiddleBuild withPublisher(final String publisher);
+ BuilderMiddleBuild withKind(final Kind kind);
+ BuilderMiddleBuild withTrack(final String track);
+ RecordingRule build();
+ }
+
+ public interface BuilderBuild {
+ RecordingRule build();
+ }
+
+ public static class Builder implements
+ BuilderStart,
+ BuilderMiddle,
+ BuilderMiddleBuild,
+ BuilderBuild {
+ private Type type;
+ private Boolean all;
+ private String publisher;
+ private Kind kind;
+ private String track;
+
+ private Builder() {
+ }
+
+ public BuilderMiddle withType(final Type type) {
+ this.type = type;
+ return this;
+ }
+
+ public BuilderBuild withAll() {
+ this.all = true;
+ return this;
+ }
+ public BuilderMiddleBuild withPublisher(final String publisher) {
+ this.publisher = publisher;
+ return this;
+ }
+ public BuilderMiddleBuild withKind(final Kind kind) {
+ this.kind = kind;
+ return this;
+ }
+ public BuilderMiddleBuild withTrack(final String track) {
+ this.track = track;
+ return this;
+ }
+
+ private boolean hasOneFilter() {
+ // at least one filter must be set
+ return this.kind != null
+ || this.all != null
+ || this.track != null
+ || this.publisher != null;
+ }
+
+ private boolean hasType() {
+ // every rule must have a type
+ return this.type != null;
+ }
+
+ public RecordingRule build() {
+ if (!hasType()) {
+ throw new IllegalArgumentException("Recording Rule must have a type");
+ }
+ if (!hasOneFilter()) {
+ throw new IllegalArgumentException("Recording Rule must have at least one filter");
+ }
+
+ return new RecordingRule(this.type, this.all, this.publisher, this.track, this.kind);
+ }
+ }
+
+ @Override
+ public Type getType() {
+ return type;
+ }
+
+ @Override
+ public Boolean getAll() {
+ return all;
+ }
+
+ @Override
+ public String getPublisher() {
+ return publisher;
+ }
+
+ @Override
+ public String getTrack() {
+ return track;
+ }
+
+ @Override
+ public Kind getKind() {
+ return kind;
+ }
+
+ public static RecordingRule all() {
+ return recordAll;
+ }
+
+ public static RecordingRule none() {
+ return recordNone;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof RecordingRule)) return false;
+ RecordingRule that = (RecordingRule) o;
+ return getType() == that.getType() &&
+ Objects.equals(getAll(), that.getAll()) &&
+ Objects.equals(getPublisher(), that.getPublisher()) &&
+ Objects.equals(getTrack(), that.getTrack()) &&
+ getKind() == that.getKind();
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getType(), getAll(), getPublisher(), getTrack(), getKind());
+ }
+}
diff --git a/src/main/java/com/twilio/type/RecordingRulesUpdate.java b/src/main/java/com/twilio/type/RecordingRulesUpdate.java
new file mode 100644
index 0000000000..11c0da14d4
--- /dev/null
+++ b/src/main/java/com/twilio/type/RecordingRulesUpdate.java
@@ -0,0 +1,45 @@
+package com.twilio.type;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.ToString;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Recording Rule Update - Used to update the list of Recording Rules
+ *
+ *
+ * For more information see:
+ * Specifying Recording Rules
+ *
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+@ToString
+public class RecordingRulesUpdate {
+
+ @JsonProperty("rules")
+ private final List rules;
+
+ public RecordingRulesUpdate(@JsonProperty("rules") final List rules) {
+ this.rules = rules;
+ }
+
+ public List getRules() {
+ return rules;
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ final com.twilio.type.RecordingRulesUpdate that = (com.twilio.type.RecordingRulesUpdate) o;
+ return Objects.equals(getRules(), that.getRules());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getRules());
+ }
+}
diff --git a/src/main/java/com/twilio/type/Rule.java b/src/main/java/com/twilio/type/Rule.java
new file mode 100644
index 0000000000..ea37f70786
--- /dev/null
+++ b/src/main/java/com/twilio/type/Rule.java
@@ -0,0 +1,98 @@
+package com.twilio.type;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+import com.twilio.converter.Promoter;
+
+public interface Rule {
+
+ Type getType();
+
+ Boolean getAll();
+
+ String getPublisher();
+
+ String getTrack();
+
+ Kind getKind();
+
+ enum Type {
+ INCLUDE("include"),
+ EXCLUDE("exclude");
+
+ private final String value;
+
+ Type(final String value) {
+ this.value = value;
+ }
+
+ @JsonCreator
+ public static Type forValue(final String value) {
+ return Promoter.enumFromString(value, Rule.Type.values());
+ }
+
+ @JsonValue
+ public String value() {
+ return this.value;
+ }
+
+ @Override
+ public String toString() {
+ return value;
+ }
+ }
+
+ enum Kind {
+ AUDIO("audio"),
+ DATA("data"),
+ VIDEO("video");
+
+ private final String value;
+
+ Kind(final String value) {
+ this.value = value;
+ }
+
+ @JsonCreator
+ public static Kind forValue(final String value) {
+ return Promoter.enumFromString(value, Rule.Kind.values());
+ }
+
+ @JsonValue
+ public String value() {
+ return this.value;
+ }
+
+ @Override
+ public String toString() {
+ return value;
+ }
+ }
+
+ enum Priority {
+ LOW("low"),
+ STANDARD("standard"),
+ HIGH("high");
+
+ private final String value;
+
+ Priority(final String value) {
+ this.value = value;
+ }
+
+ @JsonCreator
+ public static Priority forValue(final String value) {
+ return Promoter.enumFromString(value, Priority.values());
+ }
+
+ @JsonValue
+ public String value() {
+ return this.value;
+ }
+
+ @Override
+ public String toString() {
+ return value;
+ }
+ }
+}
diff --git a/src/main/java/com/twilio/type/SubscribeRule.java b/src/main/java/com/twilio/type/SubscribeRule.java
index 1045b45f56..ee2b505596 100644
--- a/src/main/java/com/twilio/type/SubscribeRule.java
+++ b/src/main/java/com/twilio/type/SubscribeRule.java
@@ -1,10 +1,7 @@
package com.twilio.type;
-import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonValue;
-import com.twilio.converter.Promoter;
import lombok.ToString;
import java.util.Objects;
@@ -19,86 +16,7 @@
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@ToString
-public class SubscribeRule {
- public enum Type {
- INCLUDE("include"),
- EXCLUDE("exclude");
-
- private final String value;
-
- Type(final String value) {
- this.value = value;
- }
-
- @JsonCreator
- public static Type forValue(final String value) {
- return Promoter.enumFromString(value, Type.values());
- }
-
- @JsonValue
- public String value() {
- return this.value;
- }
-
- @Override
- public String toString() {
- return value;
- }
- }
-
- public enum Kind {
- AUDIO("audio"),
- DATA("data"),
- VIDEO("video");
-
- private final String value;
-
- Kind(final String value) {
- this.value = value;
- }
-
- @JsonCreator
- public static Kind forValue(final String value) {
- return Promoter.enumFromString(value, Kind.values());
- }
-
- @JsonValue
- public String value() {
- return this.value;
- }
-
- @Override
- public String toString() {
- return value;
- }
- }
-
- public enum Priority {
- LOW("low"),
- STANDARD("standard"),
- HIGH("high");
-
- private final String value;
-
- Priority(final String value) {
- this.value = value;
- }
-
- @JsonCreator
- public static Priority forValue(final String value) {
- return Promoter.enumFromString(value, Priority.values());
- }
-
- @JsonValue
- public String value() {
- return this.value;
- }
-
- @Override
- public String toString() {
- return value;
- }
- }
+public class SubscribeRule implements Rule {
private static final SubscribeRule subscribeAll = builder().withType(Type.INCLUDE).withAll().build();
private static final SubscribeRule subscribeNone = builder().withType(Type.EXCLUDE).withAll().build();
@@ -122,11 +40,11 @@ public String toString() {
private final Priority priority;
public SubscribeRule(@JsonProperty("type") final Type type,
- @JsonProperty("all") final Boolean all,
- @JsonProperty("publisher") final String publisher,
- @JsonProperty("track") final String track,
- @JsonProperty("kind") final Kind kind,
- @JsonProperty("priority") final Priority priority) {
+ @JsonProperty("all") final Boolean all,
+ @JsonProperty("publisher") final String publisher,
+ @JsonProperty("track") final String track,
+ @JsonProperty("kind") final Kind kind,
+ @JsonProperty("priority") final Priority priority) {
this.type = type;
this.all = all;
this.publisher = publisher;
@@ -148,31 +66,60 @@ public static BuilderStart builder() {
return new Builder();
}
+ @Override
+ public Type getType() {
+ return type;
+ }
+
+ @Override
+ public Boolean getAll() {
+ return all;
+ }
+
+ @Override
+ public String getPublisher() {
+ return publisher;
+ }
+
+ @Override
+ public String getTrack() {
+ return track;
+ }
+
+ @Override
+ public Kind getKind() {
+ return kind;
+ }
+
+ public Priority getPriority() {
+ return priority;
+ }
+
+ public static SubscribeRule all() {
+ return subscribeAll;
+ }
+
+ public static SubscribeRule none() {
+ return subscribeNone;
+ }
+
public interface BuilderStart {
BuilderMiddle withType(final Type type);
}
public interface BuilderMiddle {
BuilderMiddleBuild withPublisher(final String publisher);
-
BuilderMiddleBuild withKind(final Kind kind);
-
BuilderMiddleBuild withTrack(final String track);
-
BuilderMiddleBuild withPriority(final Priority priority);
-
BuilderBuild withAll();
}
public interface BuilderMiddleBuild {
BuilderMiddleBuild withPublisher(final String publisher);
-
BuilderMiddleBuild withKind(final Kind kind);
-
BuilderMiddleBuild withTrack(final String track);
-
BuilderMiddleBuild withPriority(final Priority priority);
-
SubscribeRule build();
}
@@ -181,10 +128,10 @@ public interface BuilderBuild {
}
public static class Builder implements
- BuilderStart,
- BuilderMiddle,
- BuilderMiddleBuild,
- BuilderBuild {
+ BuilderStart,
+ BuilderMiddle,
+ BuilderMiddleBuild,
+ BuilderBuild {
private Type type;
private Boolean all;
private String publisher;
@@ -204,22 +151,18 @@ public BuilderBuild withAll() {
this.all = true;
return this;
}
-
public BuilderMiddleBuild withPublisher(final String publisher) {
this.publisher = publisher;
return this;
}
-
public BuilderMiddleBuild withKind(final Kind kind) {
this.kind = kind;
return this;
}
-
public BuilderMiddleBuild withTrack(final String track) {
this.track = track;
return this;
}
-
public BuilderMiddleBuild withPriority(final Priority priority) {
this.priority = priority;
return this;
@@ -228,10 +171,10 @@ public BuilderMiddleBuild withPriority(final Priority priority) {
private boolean hasOneFilter() {
// at least one filter must be set
return this.kind != null
- || this.all != null
- || this.track != null
- || this.publisher != null
- || this.priority != null;
+ || this.all != null
+ || this.track != null
+ || this.publisher != null
+ || this.priority != null;
}
private boolean hasType() {
@@ -251,49 +194,17 @@ public SubscribeRule build() {
}
}
- public Type getType() {
- return type;
- }
-
- public Boolean getAll() {
- return all;
- }
-
- public String getPublisher() {
- return publisher;
- }
-
- public String getTrack() {
- return track;
- }
-
- public Kind getKind() {
- return kind;
- }
-
- public Priority getPriority() {
- return priority;
- }
-
- public static SubscribeRule all() {
- return subscribeAll;
- }
-
- public static SubscribeRule none() {
- return subscribeNone;
- }
-
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SubscribeRule)) return false;
SubscribeRule that = (SubscribeRule) o;
return getType() == that.getType() &&
- Objects.equals(getAll(), that.getAll()) &&
- Objects.equals(getPublisher(), that.getPublisher()) &&
- Objects.equals(getTrack(), that.getTrack()) &&
- getKind() == that.getKind() &&
- getPriority() == that.getPriority();
+ Objects.equals(getAll(), that.getAll()) &&
+ Objects.equals(getPublisher(), that.getPublisher()) &&
+ Objects.equals(getTrack(), that.getTrack()) &&
+ getKind() == that.getKind() &&
+ getPriority() == that.getPriority();
}
@Override
diff --git a/src/test/java/com/twilio/type/RecordingRuleTest.java b/src/test/java/com/twilio/type/RecordingRuleTest.java
new file mode 100644
index 0000000000..51865aa6ef
--- /dev/null
+++ b/src/test/java/com/twilio/type/RecordingRuleTest.java
@@ -0,0 +1,82 @@
+package com.twilio.type;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+import static org.junit.Assert.fail;
+
+public class RecordingRuleTest extends TypeTest {
+ @Test
+ public void testBuilderOneFilter() {
+ try {
+ RecordingRule.builder().withType(RecordingRule.Type.INCLUDE).withPublisher(null).build();
+ } catch (IllegalArgumentException e) {
+ return;
+ }
+ fail("Rule builder should enforce a filter");
+ }
+
+ @Test
+ public void testBuilderMustHaveType() {
+ try {
+ RecordingRule.builder().withType(null).withPublisher("alice").build();
+ } catch (IllegalArgumentException e) {
+ return;
+ }
+ fail("Rule builder should enforce setting a type");
+ }
+
+ @Test
+ public void testAllExclusive() throws IOException {
+ String json = "{\n" +
+ " \"type\": \"include\",\n" +
+ " \"all\": true\n" +
+ "}";
+
+ RecordingRule r = fromJson(json, RecordingRule.class);
+ Assert.assertEquals(RecordingRule.Type.INCLUDE, r.getType());
+ Assert.assertEquals(true, r.getAll());
+
+ Assert.assertTrue(convertsToAndFromJson(r, RecordingRule.class));
+ }
+
+ @Test
+ public void testFilters() throws IOException {
+ String json = "{\n" +
+ " \"type\": \"exclude\",\n" +
+ " \"track\": \"screen\",\n" +
+ " \"kind\": \"video\",\n" +
+ " \"publisher\": \"alice\"\n" +
+ "}";
+
+ RecordingRule r = fromJson(json, RecordingRule.class);
+ Assert.assertEquals(RecordingRule.Type.EXCLUDE, r.getType());
+ Assert.assertEquals(RecordingRule.Kind.VIDEO, r.getKind());
+ Assert.assertEquals("alice", r.getPublisher());
+ Assert.assertNull(r.getAll());
+
+ Assert.assertTrue(convertsToAndFromJson(r, RecordingRule.class));
+ }
+
+ @Test
+ public void testUpdate() throws IOException {
+ final RecordingRule allAudio = RecordingRule.builder()
+ .withType(RecordingRule.Type.INCLUDE)
+ .withKind(RecordingRule.Kind.AUDIO)
+ .build();
+ final RecordingRule presenterVideo = RecordingRule.builder()
+ .withType(RecordingRule.Type.INCLUDE)
+ .withKind(RecordingRule.Kind.VIDEO)
+ .withPublisher("presenter")
+ .build();
+
+ final RecordingRulesUpdate update = new RecordingRulesUpdate(Arrays.asList(
+ allAudio, presenterVideo
+ ));
+
+ Assert.assertTrue(convertsToAndFromJson(update, RecordingRulesUpdate.class));
+ }
+}