diff --git a/.gitignore b/.gitignore
index c5a30075..42f72dc9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,5 @@ hs_err_pid*
# The various target folders
*target/
+*.iml
+.idea
diff --git a/README.md b/README.md
index 30aa3a82..c653441b 100644
--- a/README.md
+++ b/README.md
@@ -28,7 +28,7 @@ If you are using maven simply add the messagebird API to your dependencies like
*
* Initialise this class with a MessageBirdService * // First create your service object @@ -24,7 +23,7 @@ * Then read your balance like this: * final Balance balance = messageBirdClient.getBalance(); *- * + *
* Created by rvt on 1/5/15.
*/
public class MessageBirdClient {
@@ -32,6 +31,7 @@ public class MessageBirdClient {
private static final String HLRPATH = "/hlr";
private static final String MESSAGESPATH = "/messages";
private static final String VOICEMESSAGESPATH = "/voicemessages";
+ private static final String VERIFYPATH = "/verify";
private MessageBirdService messageBirdService;
public MessageBirdClient(final MessageBirdService messageBirdService) {
@@ -308,4 +308,81 @@ public VoiceMessageList listVoiceMessages(final Integer offset, final Integer li
return messageBirdService.requestList(VOICEMESSAGESPATH, offset, limit, VoiceMessageList.class);
}
+ /**
+ * @param verifyRequest
+ * @return Verify object
+ * @throws UnauthorizedException
+ * @throws GeneralException
+ */
+ public Verify sendVerifyToken(VerifyRequest verifyRequest) throws UnauthorizedException, GeneralException {
+ if (verifyRequest == null) {
+ throw new IllegalArgumentException("Verify request cannot be null");
+ } else if (verifyRequest.getRecipient() == null || verifyRequest.getRecipient().isEmpty()) {
+ throw new IllegalArgumentException("Recipient cannot be empty for verify");
+ }
+ return messageBirdService.sendPayLoad(VERIFYPATH, verifyRequest, Verify.class);
+ }
+
+ /**
+ * @param recipient
+ * @return Verify object
+ * @throws UnauthorizedException
+ * @throws GeneralException
+ */
+ public Verify sendVerifyToken(String recipient) throws UnauthorizedException, GeneralException {
+ if (recipient == null || recipient.isEmpty()) {
+ throw new IllegalArgumentException("Recipient cannot be empty for verify");
+ }
+ VerifyRequest verifyRequest = new VerifyRequest(recipient);
+ return this.sendVerifyToken(verifyRequest);
+ }
+
+ /**
+ *
+ * @param id
+ * @param token
+ * @return Verify object
+ * @throws NotFoundException
+ * @throws GeneralException
+ * @throws UnauthorizedException
+ */
+ public Verify verifyToken(String id, String token) throws NotFoundException, GeneralException, UnauthorizedException {
+ if (id == null || id.isEmpty()) {
+ throw new IllegalArgumentException("ID cannot be empty for verify");
+ } else if (token == null || token.isEmpty()) {
+ throw new IllegalArgumentException("ID cannot be empty for verify");
+ }
+ final Map HttpURLConnection getConnection(final String serviceUrl, final P post
final String json = mapper.writeValueAsString(postData);
connection.getOutputStream().write(json.getBytes("UTF-8"));
+ } else if ("DELETE".equals(requestType)) {
+ // could have just used rquestType as it is
+ connection.setDoOutput(false);
+ connection.setRequestMethod("DELETE");
+ connection.setRequestProperty("Content-Type", "application/text");
} else {
connection.setDoOutput(false);
connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type:", "application/text");
+ connection.setRequestProperty("Content-Type", "application/text");
}
return connection;
diff --git a/api/src/main/java/com/messagebird/objects/Gender.java b/api/src/main/java/com/messagebird/objects/Gender.java
new file mode 100644
index 00000000..21df1830
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/Gender.java
@@ -0,0 +1,21 @@
+package com.messagebird.objects;
+
+/**
+ * Created by faizan on 09/12/15.
+ */
+public enum Gender {
+
+ MALE("male"),
+ FEMALE("female");
+
+ private String code;
+
+ Gender(String code) {
+ this.code = code;
+ }
+
+ public String toString() {
+ return this.code;
+ }
+}
+
diff --git a/api/src/main/java/com/messagebird/objects/Language.java b/api/src/main/java/com/messagebird/objects/Language.java
new file mode 100644
index 00000000..6ce76027
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/Language.java
@@ -0,0 +1,37 @@
+package com.messagebird.objects;
+
+/**
+ * Created by faizan on 09/12/15.
+ */
+public enum Language {
+
+ NL_NL("nl-nl"),
+ DE_DE("de-de"),
+ EN_GB("en-gb"),
+ EN_US("en-us"),
+ ES_ES("es-es"),
+ FR_FR("fr-fr"),
+ RU_RU("ru_ru"),
+ ZH_CN("zh-cn"),
+ EN_AU("en-au"),
+ ES_MX("es-mx"),
+ ES_US("es-us"),
+ FR_CA("fr-ca"),
+ IS_IS("is-is"),
+ IT_IT("it-it"),
+ JA_JP("ja-jp"),
+ KO_KR("ko-kr"),
+ PL_PL("pl-pl"),
+ PT_BR("pt-br"),
+ RO_RO("ro-ro");
+
+ private String code;
+
+ Language(String code) {
+ this.code = code;
+ }
+
+ public String toString() {
+ return this.code;
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/Messages.java b/api/src/main/java/com/messagebird/objects/Messages.java
new file mode 100644
index 00000000..3319d81d
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/Messages.java
@@ -0,0 +1,24 @@
+package com.messagebird.objects;
+
+import java.io.Serializable;
+
+/**
+ * Created by faizan on 09/12/15.
+ */
+public class Messages implements Serializable {
+ private String href;
+
+ public String getHref() {
+ return href;
+ }
+
+ public void setHref(String href) {
+ this.href = href;
+ }
+
+ public String toString() {
+ return "Messages{" +
+ "href=" + this.href +
+ "}";
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/Verify.java b/api/src/main/java/com/messagebird/objects/Verify.java
new file mode 100644
index 00000000..346847c2
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/Verify.java
@@ -0,0 +1,86 @@
+package com.messagebird.objects;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * Created by faizan on 09/12/15.
+ */
+public class Verify implements Serializable {
+
+ private String id;
+ private String href;
+ private String recipient;
+ private Messages messages;
+ private String status;
+ private Date createdDatetime;
+ private Date validUntilDatetime;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getHref() {
+ return href;
+ }
+
+ public void setHref(String href) {
+ this.href = href;
+ }
+
+ public String getRecipient() {
+ return recipient;
+ }
+
+ public void setRecipient(String recipient) {
+ this.recipient = recipient;
+ }
+
+ public Messages getMessages() {
+ return messages;
+ }
+
+ public void setMessages(Messages messages) {
+ this.messages = messages;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public Date getCreatedDatetime() {
+ return createdDatetime;
+ }
+
+ public void setCreatedDatetime(Date createdDatetime) {
+ this.createdDatetime = createdDatetime;
+ }
+
+ public Date getValidUntilDatetime() {
+ return validUntilDatetime;
+ }
+
+ public void setValidUntilDatetime(Date validUntilDatetime) {
+ this.validUntilDatetime = validUntilDatetime;
+ }
+
+ public String toString() {
+ return "Verify {" + " " +
+ "id=" + this.id + " " +
+ "href=" + this.href + " " +
+ "recipient=" + this.recipient + " " +
+ "messages=" + this.messages + " " +
+ "status=" + this.status + " " +
+ "createdDatetime=" + this.createdDatetime + " " +
+ "validUntilDatetime=" + this.validUntilDatetime+ " " +
+ "}";
+ }
+}
diff --git a/api/src/main/java/com/messagebird/objects/VerifyRequest.java b/api/src/main/java/com/messagebird/objects/VerifyRequest.java
new file mode 100644
index 00000000..80db049a
--- /dev/null
+++ b/api/src/main/java/com/messagebird/objects/VerifyRequest.java
@@ -0,0 +1,96 @@
+package com.messagebird.objects;
+
+import java.io.Serializable;
+
+/**
+ * Created by faizan on 09/12/15.
+ */
+public class VerifyRequest implements Serializable {
+
+ private String recipient;
+ private String originator;
+ private String reference;
+ private MsgType type;
+ private String template;
+ private Integer timeout;
+ private Integer tokenLength;
+ private Gender voice;
+ private Language language;
+
+
+ public VerifyRequest(String recipient) {
+ this.recipient = recipient;
+ }
+
+ public String getRecipient() {
+ return recipient;
+ }
+
+ public void setRecipient(String recipient) {
+ this.recipient = recipient;
+ }
+
+ public String getOriginator() {
+ return originator;
+ }
+
+ public void setOriginator(String originator) {
+ this.originator = originator;
+ }
+
+ public String getReference() {
+ return reference;
+ }
+
+ public void setReference(String reference) {
+ this.reference = reference;
+ }
+
+ public MsgType getType() {
+ return type;
+ }
+
+ public void setType(MsgType type) {
+ this.type = type;
+ }
+
+ public String getTemplate() {
+ return template;
+ }
+
+ public void setTemplate(String template) {
+ this.template = template;
+ }
+
+ public Integer getTimeout() {
+ return timeout;
+ }
+
+ public void setTimeout(Integer timeout) {
+ this.timeout = timeout;
+ }
+
+ public Integer getTokenLength() {
+ return tokenLength;
+ }
+
+ public void setTokenLength(Integer tokenLength) {
+ this.tokenLength = tokenLength;
+ }
+
+ public Gender getVoice() {
+ return voice;
+ }
+
+ public void setVoice(Gender voice) {
+ this.voice = voice;
+ }
+
+ public Language getLanguage() {
+ return language;
+ }
+
+ public void setLanguage(Language language) {
+ this.language = language;
+ }
+}
diff --git a/api/src/test/java/com/messagebird/MessageBirdClientTest.java b/api/src/test/java/com/messagebird/MessageBirdClientTest.java
index 2d42a91a..75e6f50f 100644
--- a/api/src/test/java/com/messagebird/MessageBirdClientTest.java
+++ b/api/src/test/java/com/messagebird/MessageBirdClientTest.java
@@ -8,11 +8,13 @@
import org.junit.BeforeClass;
import org.junit.Test;
+import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;
-import java.util.Map;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
@@ -327,4 +329,51 @@ public void testDeleteVoiceMessage() throws Exception {
messageBirdClient.deleteVoiceMessage("Foo");
}
+ @Test
+ public void testSendVerifyToken1() throws UnauthorizedException, GeneralException {
+ final String reference = "5551234";
+ VerifyRequest verifyRequest = new VerifyRequest(this.messageBirdMSISDN.toString());
+ verifyRequest.setOriginator("Code");
+ verifyRequest.setReference(reference);
+ verifyRequest.setLanguage(Language.NL_NL);
+ verifyRequest.setType(MsgType.sms);
+ verifyRequest.setTimeout(30);
+ verifyRequest.setTokenLength(6);
+ verifyRequest.setVoice(Gender.FEMALE);
+ Verify verify = messageBirdClient.sendVerifyToken(verifyRequest);
+ assertFalse("href is empty", verify.getHref().isEmpty());
+ }
+
+ @Test
+ public void testSendVerifyTokenAndGetVerifyObject() throws UnauthorizedException, GeneralException, NotFoundException {
+ Verify verify = messageBirdClient.sendVerifyToken(this.messageBirdMSISDN.toString());
+ assertFalse("href is empty", verify.getHref().isEmpty());
+ assertFalse("id is empty", verify.getId().isEmpty());
+
+ verify = messageBirdClient.getVerifyObject(verify.getId());
+ assertFalse("href is empty", verify.getHref().isEmpty());
+ assertFalse("id is empty", verify.getId().isEmpty());
+ }
+
+ @Test
+ public void testVerifyToken() throws UnauthorizedException, GeneralException, NotFoundException, UnsupportedEncodingException {
+ Verify verify = messageBirdClient.sendVerifyToken(this.messageBirdMSISDN.toString());
+ assertFalse("href is empty", verify.getHref().isEmpty());
+
+ try {
+ messageBirdClient.verifyToken(verify.getId(), "123456");
+ } catch (GeneralException e) {
+ // we expect only one error about token and nothing else
+ assertEquals("token", e.getErrors().get(0).getParameter());
+ assertTrue(e.getErrors().size() == 1);
+ }
+ }
+
+ @Test
+ public void testDeleteVerifyToken() throws UnauthorizedException, GeneralException, NotFoundException, UnsupportedEncodingException {
+ Verify verify = messageBirdClient.sendVerifyToken(this.messageBirdMSISDN.toString());
+ assertFalse("href is empty", verify.getHref().isEmpty());
+
+ messageBirdClient.deleteVerifyObject(verify.getId());
+ }
}
diff --git a/examples/pom.xml b/examples/pom.xml
index e9bfaee1..7f476f7c 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -20,7 +20,7 @@