Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/main/java/com/twilio/twiml/FaxResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@

package com.twilio.twiml;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.twilio.twiml.TwiMLException;
import com.twilio.twiml.fax.Receive;

/**
* TwiML wrapper for {@code <Response>}
*/
@JsonDeserialize(builder = FaxResponse.Builder.class)
public class FaxResponse extends TwiML {
/**
* For XML Serialization/Deserialization
Expand All @@ -31,9 +36,24 @@ private FaxResponse(Builder b) {
* Create a new {@code <Response>} element
*/
public static class Builder extends TwiML.Builder<Builder> {
/**
* Create and return a {@code <FaxResponse.Builder>} from an XML string
*/
public static Builder fromXml(final String xml) throws TwiMLException {
try {
return OBJECT_MAPPER.readValue(xml, Builder.class);
} catch (final JsonProcessingException jpe) {
throw new TwiMLException(
"Failed to deserialize a FaxResponse.Builder from the provided XML string: " + jpe.getMessage());
} catch (final Exception e) {
throw new TwiMLException("Unhandled exception: " + e.getMessage());
}
}

/**
* Add a child {@code <Receive>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Receive")
public Builder receive(Receive receive) {
this.children.add(receive);
return this;
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/twilio/twiml/MessagingResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@

package com.twilio.twiml;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.twilio.twiml.TwiMLException;
import com.twilio.twiml.messaging.Message;
import com.twilio.twiml.messaging.Redirect;

/**
* TwiML wrapper for {@code <Response>}
*/
@JsonDeserialize(builder = MessagingResponse.Builder.class)
public class MessagingResponse extends TwiML {
/**
* For XML Serialization/Deserialization
Expand All @@ -32,9 +37,24 @@ private MessagingResponse(Builder b) {
* Create a new {@code <Response>} element
*/
public static class Builder extends TwiML.Builder<Builder> {
/**
* Create and return a {@code <MessagingResponse.Builder>} from an XML string
*/
public static Builder fromXml(final String xml) throws TwiMLException {
try {
return OBJECT_MAPPER.readValue(xml, Builder.class);
} catch (final JsonProcessingException jpe) {
throw new TwiMLException(
"Failed to deserialize a MessagingResponse.Builder from the provided XML string: " + jpe.getMessage());
} catch (final Exception e) {
throw new TwiMLException("Unhandled exception: " + e.getMessage());
}
}

/**
* Add a child {@code <Message>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Message")
public Builder message(Message message) {
this.children.add(message);
return this;
Expand All @@ -43,6 +63,7 @@ public Builder message(Message message) {
/**
* Add a child {@code <Redirect>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Redirect")
public Builder redirect(Redirect redirect) {
this.children.add(redirect);
return this;
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/com/twilio/twiml/VoiceResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

package com.twilio.twiml;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.twilio.twiml.TwiMLException;
import com.twilio.twiml.voice.Connect;
import com.twilio.twiml.voice.Dial;
import com.twilio.twiml.voice.Echo;
Expand All @@ -31,6 +35,7 @@
/**
* TwiML wrapper for {@code <Response>}
*/
@JsonDeserialize(builder = VoiceResponse.Builder.class)
public class VoiceResponse extends TwiML {
/**
* For XML Serialization/Deserialization
Expand All @@ -50,9 +55,24 @@ private VoiceResponse(Builder b) {
* Create a new {@code <Response>} element
*/
public static class Builder extends TwiML.Builder<Builder> {
/**
* Create and return a {@code <VoiceResponse.Builder>} from an XML string
*/
public static Builder fromXml(final String xml) throws TwiMLException {
try {
return OBJECT_MAPPER.readValue(xml, Builder.class);
} catch (final JsonProcessingException jpe) {
throw new TwiMLException(
"Failed to deserialize a VoiceResponse.Builder from the provided XML string: " + jpe.getMessage());
} catch (final Exception e) {
throw new TwiMLException("Unhandled exception: " + e.getMessage());
}
}

/**
* Add a child {@code <Connect>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Connect")
public Builder connect(Connect connect) {
this.children.add(connect);
return this;
Expand All @@ -61,6 +81,7 @@ public Builder connect(Connect connect) {
/**
* Add a child {@code <Dial>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Dial")
public Builder dial(Dial dial) {
this.children.add(dial);
return this;
Expand All @@ -69,6 +90,7 @@ public Builder dial(Dial dial) {
/**
* Add a child {@code <Echo>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Echo")
public Builder echo(Echo echo) {
this.children.add(echo);
return this;
Expand All @@ -77,6 +99,7 @@ public Builder echo(Echo echo) {
/**
* Add a child {@code <Enqueue>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Enqueue")
public Builder enqueue(Enqueue enqueue) {
this.children.add(enqueue);
return this;
Expand All @@ -85,6 +108,7 @@ public Builder enqueue(Enqueue enqueue) {
/**
* Add a child {@code <Gather>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Gather")
public Builder gather(Gather gather) {
this.children.add(gather);
return this;
Expand All @@ -93,6 +117,7 @@ public Builder gather(Gather gather) {
/**
* Add a child {@code <Hangup>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Hangup")
public Builder hangup(Hangup hangup) {
this.children.add(hangup);
return this;
Expand All @@ -101,6 +126,7 @@ public Builder hangup(Hangup hangup) {
/**
* Add a child {@code <Leave>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Leave")
public Builder leave(Leave leave) {
this.children.add(leave);
return this;
Expand All @@ -109,6 +135,7 @@ public Builder leave(Leave leave) {
/**
* Add a child {@code <Pause>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Pause")
public Builder pause(Pause pause) {
this.children.add(pause);
return this;
Expand All @@ -117,6 +144,7 @@ public Builder pause(Pause pause) {
/**
* Add a child {@code <Play>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Play")
public Builder play(Play play) {
this.children.add(play);
return this;
Expand All @@ -125,6 +153,7 @@ public Builder play(Play play) {
/**
* Add a child {@code <Queue>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Queue")
public Builder queue(Queue queue) {
this.children.add(queue);
return this;
Expand All @@ -133,6 +162,7 @@ public Builder queue(Queue queue) {
/**
* Add a child {@code <Record>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Record")
public Builder record(Record record) {
this.children.add(record);
return this;
Expand All @@ -141,6 +171,7 @@ public Builder record(Record record) {
/**
* Add a child {@code <Redirect>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Redirect")
public Builder redirect(Redirect redirect) {
this.children.add(redirect);
return this;
Expand All @@ -149,6 +180,7 @@ public Builder redirect(Redirect redirect) {
/**
* Add a child {@code <Reject>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Reject")
public Builder reject(Reject reject) {
this.children.add(reject);
return this;
Expand All @@ -157,6 +189,7 @@ public Builder reject(Reject reject) {
/**
* Add a child {@code <Say>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Say")
public Builder say(Say say) {
this.children.add(say);
return this;
Expand All @@ -165,6 +198,7 @@ public Builder say(Say say) {
/**
* Add a child {@code <Sms>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Sms")
public Builder sms(Sms sms) {
this.children.add(sms);
return this;
Expand All @@ -173,6 +207,7 @@ public Builder sms(Sms sms) {
/**
* Add a child {@code <Pay>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Pay")
public Builder pay(Pay pay) {
this.children.add(pay);
return this;
Expand All @@ -181,6 +216,7 @@ public Builder pay(Pay pay) {
/**
* Add a child {@code <Prompt>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Prompt")
public Builder prompt(Prompt prompt) {
this.children.add(prompt);
return this;
Expand All @@ -189,6 +225,7 @@ public Builder prompt(Prompt prompt) {
/**
* Add a child {@code <Start>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Start")
public Builder start(Start start) {
this.children.add(start);
return this;
Expand All @@ -197,6 +234,7 @@ public Builder start(Start start) {
/**
* Add a child {@code <Stop>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Stop")
public Builder stop(Stop stop) {
this.children.add(stop);
return this;
Expand All @@ -205,6 +243,7 @@ public Builder stop(Stop stop) {
/**
* Add a child {@code <Refer>} element
*/
@JacksonXmlProperty(isAttribute = false, localName = "Refer")
public Builder refer(Refer refer) {
this.children.add(refer);
return this;
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/twilio/twiml/fax/Receive.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@

package com.twilio.twiml.fax;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.twilio.converter.Promoter;
import com.twilio.http.HttpMethod;
import com.twilio.twiml.TwiML;
import com.twilio.twiml.TwiMLException;

import java.net.URI;
import java.util.HashMap;
Expand All @@ -18,6 +22,7 @@
/**
* TwiML wrapper for {@code <Receive>}
*/
@JsonDeserialize(builder = Receive.Builder.class)
public class Receive extends TwiML {
public enum MediaType {
APPLICATION_PDF("application/pdf"),
Expand Down Expand Up @@ -152,6 +157,20 @@ public Boolean isStoreMedia() {
* Create a new {@code <Receive>} element
*/
public static class Builder extends TwiML.Builder<Builder> {
/**
* Create and return a {@code <Receive.Builder>} from an XML string
*/
public static Builder fromXml(final String xml) throws TwiMLException {
try {
return OBJECT_MAPPER.readValue(xml, Builder.class);
} catch (final JsonProcessingException jpe) {
throw new TwiMLException(
"Failed to deserialize a Receive.Builder from the provided XML string: " + jpe.getMessage());
} catch (final Exception e) {
throw new TwiMLException("Unhandled exception: " + e.getMessage());
}
}

private URI action;
private HttpMethod method;
private Receive.MediaType mediaType;
Expand All @@ -161,6 +180,7 @@ public static class Builder extends TwiML.Builder<Builder> {
/**
* Receive action URL
*/
@JacksonXmlProperty(isAttribute = true, localName = "action")
public Builder action(URI action) {
this.action = action;
return this;
Expand All @@ -177,6 +197,7 @@ public Builder action(String action) {
/**
* Receive action URL method
*/
@JacksonXmlProperty(isAttribute = true, localName = "method")
public Builder method(HttpMethod method) {
this.method = method;
return this;
Expand All @@ -185,6 +206,7 @@ public Builder method(HttpMethod method) {
/**
* The media type used to store media in the fax media store
*/
@JacksonXmlProperty(isAttribute = true, localName = "mediaType")
public Builder mediaType(Receive.MediaType mediaType) {
this.mediaType = mediaType;
return this;
Expand All @@ -193,6 +215,7 @@ public Builder mediaType(Receive.MediaType mediaType) {
/**
* What size to interpret received pages as
*/
@JacksonXmlProperty(isAttribute = true, localName = "pageSize")
public Builder pageSize(Receive.PageSize pageSize) {
this.pageSize = pageSize;
return this;
Expand All @@ -201,6 +224,7 @@ public Builder pageSize(Receive.PageSize pageSize) {
/**
* Whether or not to store received media in the fax media store
*/
@JacksonXmlProperty(isAttribute = true, localName = "storeMedia")
public Builder storeMedia(Boolean storeMedia) {
this.storeMedia = storeMedia;
return this;
Expand Down
Loading