Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add new Twiml type to deal with constructor overloading issue #492

Merged
merged 2 commits into from
Nov 15, 2019
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
13 changes: 13 additions & 0 deletions src/main/java/com/twilio/converter/Promoter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.twilio.converter;

import com.twilio.type.PhoneNumber;
import com.twilio.type.Twiml;

import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -33,6 +34,18 @@ public static PhoneNumber phoneNumberFromString(final String pn) {
return new PhoneNumber(pn);
}

/**
* Create a @see com.twilio.types.Twiml from a string
*
* @param twiml Twiml to convert
* @return built @see com.twilio.types.Twiml
*/
public static Twiml twimlFromString(final String twiml) {
return new Twiml(twiml);
}



/**
* Create a list from a single element.
*
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/com/twilio/type/Twiml.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.twilio.type;

import java.util.Objects;

public class Twiml {
private final String rawTwiml;

public Twiml(String twiml) {
this.rawTwiml = twiml;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

Twiml other = (Twiml) o;
return Objects.equals(this.rawTwiml, other.rawTwiml);
}

@Override
public int hashCode() {
return Objects.hash(this.rawTwiml);
}

@Override
public String toString() {
return this.rawTwiml;
}
}
7 changes: 7 additions & 0 deletions src/test/java/com/twilio/converter/PromoterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.Lists;
import com.twilio.type.PhoneNumber;
import com.twilio.type.Twiml;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -27,6 +28,12 @@ public void testPhoneNumberFromString() {
Assert.assertEquals(new PhoneNumber("+12345678910"), pn);
}

@Test
public void testTwimlFromString() {
Twiml twiml = Promoter.twimlFromString("<Response><Say>Ahoy!</Say></Response>");
Assert.assertEquals(new Twiml("<Response><Say>Ahoy!</Say></Response>"), twiml);
}

@Test
public void testPromoteList() {
String s = "hi";
Expand Down