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

Subject field support in mms mt batch #41

Merged
merged 2 commits into from
Jun 4, 2024
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
8 changes: 8 additions & 0 deletions src/main/java/com/sinch/xms/api/MediaBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/sinch/xms/api/MtBatchMmsResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>See {@link MtBatchMmsCreate#body()} for a more thorough description of this field.
*
Expand Down
52 changes: 52 additions & 0 deletions src/test/java/com/sinch/xms/api/MtBatchMmsCreateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/sinch/xms/api/MtBatchMmsResultTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,",
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/com/sinch/xms/api/MtBatchMmsUpdateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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' } }",
"}")
Expand Down
Loading