diff --git a/src/main/java/com/sinch/xms/api/MediaBody.java b/src/main/java/com/sinch/xms/api/MediaBody.java index ebb6ec0..ce30ae1 100644 --- a/src/main/java/com/sinch/xms/api/MediaBody.java +++ b/src/main/java/com/sinch/xms/api/MediaBody.java @@ -61,6 +61,14 @@ public static final MediaBody.Builder builder() { return new MediaBody.Builder(); } + /** + * The subject of the message. + * + * @return a subject + */ + @Nullable + public abstract String subject(); + /** * The text message. * diff --git a/src/main/java/com/sinch/xms/api/MtBatchMmsResult.java b/src/main/java/com/sinch/xms/api/MtBatchMmsResult.java index cf1fc63..b960a91 100644 --- a/src/main/java/com/sinch/xms/api/MtBatchMmsResult.java +++ b/src/main/java/com/sinch/xms/api/MtBatchMmsResult.java @@ -56,8 +56,9 @@ public static final MtBatchMmsResult.Builder builder() { } /** - * The message body including message text or template (optional) and the media content url. If - * this describes a template then {@link #parameters()} describes the parameter substitutions. + * The message body including message text or template and/or subject (optional) and the media + * content url. If this describes a template then {@link #parameters()} describes the parameter + * substitutions. * *
See {@link MtBatchMmsCreate#body()} for a more thorough description of this field. * diff --git a/src/test/java/com/sinch/xms/api/MtBatchMmsCreateTest.java b/src/test/java/com/sinch/xms/api/MtBatchMmsCreateTest.java index 8d74436..fbedaf3 100644 --- a/src/test/java/com/sinch/xms/api/MtBatchMmsCreateTest.java +++ b/src/test/java/com/sinch/xms/api/MtBatchMmsCreateTest.java @@ -117,6 +117,58 @@ public void canDeserializeWithMessageContent() throws Exception { assertThat(actual, is(expected)); } + @Test + public void canSerializeWithSubject() throws Exception { + MtBatchMmsCreate input = + SinchSMSApi.batchMms() + .sender("1234") + .addRecipient("987654321") + .body( + SinchSMSApi.mediaBody() + .url("http://my.test.url/image.jpg") + .subject("the text") + .build()) + .build(); + + String expected = + Utils.join( + "\n", + "{", + " 'type': 'mt_media',", + " 'from': '1234',", + " 'to': [ '987654321' ],", + " 'body': {", + " 'url':'http://my.test.url/image.jpg',", + " 'subject':'the text'", + " }", + "}") + .replace('\'', '"'); + + String actual = json.writeValueAsString(input); + + assertThat(actual, is(TestUtils.jsonEqualTo(expected))); + } + + @Test + public void canDeserializeWithSubject() throws Exception { + MtBatchMmsCreate expected = + SinchSMSApi.batchMms() + .sender("1234") + .addRecipient("987654321") + .body( + SinchSMSApi.mediaBody() + .url("http://my.test.url/image.jpg") + .subject("the text") + .build()) + .build(); + + String input = json.writeValueAsString(expected); + + MtBatchMmsCreate actual = json.readValue(input, MtBatchMmsCreate.class); + + assertThat(actual, is(expected)); + } + @Test(expected = IllegalStateException.class) public void requiresUrl() { SinchSMSApi.batchMms() diff --git a/src/test/java/com/sinch/xms/api/MtBatchMmsResultTest.java b/src/test/java/com/sinch/xms/api/MtBatchMmsResultTest.java index b5566f4..ff33137 100644 --- a/src/test/java/com/sinch/xms/api/MtBatchMmsResultTest.java +++ b/src/test/java/com/sinch/xms/api/MtBatchMmsResultTest.java @@ -77,6 +77,7 @@ public void canSerializeWithParameters() throws Exception { SinchSMSApi.mediaBody() .url("http://my.test.url/image.jpg") .message("the text") + .subject("subject text") .build()) .putParameter( "param1", @@ -95,6 +96,7 @@ public void canSerializeWithParameters() throws Exception { " 'to': [ '987654321' ],", " 'body': {", " 'url':'http://my.test.url/image.jpg',", + " 'subject':'subject text',", " 'message':'the text'", " },", " 'canceled': false,", diff --git a/src/test/java/com/sinch/xms/api/MtBatchMmsUpdateTest.java b/src/test/java/com/sinch/xms/api/MtBatchMmsUpdateTest.java index 6a8966f..c346479 100644 --- a/src/test/java/com/sinch/xms/api/MtBatchMmsUpdateTest.java +++ b/src/test/java/com/sinch/xms/api/MtBatchMmsUpdateTest.java @@ -60,6 +60,7 @@ public void canSerializeWithUpdatedParameters() throws Exception { SinchSMSApi.mediaBody() .url("http://my.test.url/image.jpg") .message("the text") + .subject("subject text") .build()) .parameters(UpdateValue.set(params)) .build(); @@ -73,7 +74,8 @@ public void canSerializeWithUpdatedParameters() throws Exception { " 'to_add': [ '987654321' ],", " 'body': {", " 'url':'http://my.test.url/image.jpg',", - " 'message':'the text'", + " 'message':'the text',", + " 'subject':'subject text'", " },", " 'parameters': { 'newparam': { 'key1': 'value1' } }", "}")