Skip to content

Commit

Permalink
Merge pull request #39 from sinch/MSLRES-5299-mms-mo-support
Browse files Browse the repository at this point in the history
MSLRES-5299: Update SDK with MMS MO feature support
  • Loading branch information
thomasf147 authored Apr 29, 2024
2 parents 4b4c611 + e16b442 commit 340cb1c
Show file tree
Hide file tree
Showing 6 changed files with 346 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.sinch</groupId>
<artifactId>sdk-sms</artifactId>
<version>2.0.2-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SDK for Sinch SMS</name>
<description>Library providing a Java API for the Sinch HTTP REST Messaging API.</description>
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/com/sinch/xms/api/MoMms.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*-
* #%L
* SDK for Sinch SMS
* %%
* Copyright (C) 2016 Sinch
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.sinch.xms.api;

import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import javax.annotation.Nonnull;
import org.immutables.value.Value;

/** A mobile originated MMS message. */
@Value.Immutable
@ValueStylePackage
@JsonDeserialize(as = MoMmsImpl.class)
@JsonTypeName("mo_media")
public abstract class MoMms extends MoSms {

/** A builder of mms MO messages. */
public static final class Builder extends MoMmsImpl.Builder {

Builder() {}
}

/**
* Creates a builder of {@link MoMms} instances.
*
* @return a builder
*/
@Nonnull
public static final MoMms.Builder builder() {
return new Builder();
}

/**
* The MMS message body.
*
* @return an object containing the body
*/
@Nonnull
public abstract MoMmsBody body();
}
73 changes: 73 additions & 0 deletions src/main/java/com/sinch/xms/api/MoMmsBody.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*-
* #%L
* SDK for Sinch SMS
* %%
* Copyright (C) 2016 Sinch
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.sinch.xms.api;

import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.immutables.value.Value;

/** A mobile originated MMS message. */
@Value.Immutable
@ValueStylePackage
@JsonDeserialize(as = MoMmsBodyImpl.class)
@JsonTypeName("mo_media")
public abstract class MoMmsBody {

/** A builder of mms MO messages. */
public static final class Builder extends MoMmsBodyImpl.Builder {

Builder() {}
}

/**
* Creates a builder of {@link MoMmsBody} instances.
*
* @return a builder
*/
@Nonnull
public static final MoMmsBody.Builder builder() {
return new Builder();
}

/**
* The message subject, if available.
*
* @return the message subject
*/
@Nullable
public abstract String subject();
/**
* The textual message body, if available.
*
* @return the message body or `null` if not available.
*/
@Nullable
public abstract String message();
/**
* The list of attached media.
*
* @return the list of media objects
*/
@Nonnull
public abstract List<MoMmsMedia> media();
}
100 changes: 100 additions & 0 deletions src/main/java/com/sinch/xms/api/MoMmsMedia.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*-
* #%L
* SDK for Sinch SMS
* %%
* Copyright (C) 2016 Sinch
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.sinch.xms.api;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.immutables.value.Value;

/** A mobile originated MMS message. */
@Value.Immutable
@ValueStylePackage
@JsonDeserialize(as = MoMmsMediaImpl.class)
@JsonTypeName("mo_media")
public abstract class MoMmsMedia {

/** A builder of mms MO messages. */
public static final class Builder extends MoMmsMediaImpl.Builder {

Builder() {}
}

/**
* Creates a builder of {@link MoMmsMedia} instances.
*
* @return a builder
*/
@Nonnull
public static final MoMmsMedia.Builder builder() {
return new Builder();
}

/**
* URL to be used to download attachment.
*
* @return the media url
*/
@Nullable
public abstract String url();
/**
* The content type of provided media. For example, 'image/jpeg'
*
* @return the content type
* @see <a
* href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types">Content
* types</a>
*/
@Nonnull
@JsonProperty("content_type")
public abstract String contentType();
/**
* The status received while media upload to storage. Possible values are: Uploaded or Failed.
*
* @return the media status
*/
@Nonnull
public abstract MediaStatus status();
/**
* Error code in case of failure or 0 for success.
*
* @return the status code
*/
@Nonnull
public abstract int code();

public enum MediaStatus {
Uploaded("Uploaded"),
Failed("Failed");

private final String publicName;

MediaStatus(String publicName) {
this.publicName = publicName;
}

@Override
public String toString() {
return publicName;
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/sinch/xms/api/MoSms.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@

/**
* Base class for mobile originated messages. A mobile originated message can have either a {@link
* MoTextSms textual} or a {@link MoBinarySms binary} message payload.
* MoTextSms textual} or a {@link MoBinarySms binary} or a {@link MoMms} message payload.
*/
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes({@Type(MoTextSms.class), @Type(MoBinarySms.class)})
@JsonSubTypes({@Type(MoTextSms.class), @Type(MoBinarySms.class), @Type(MoMms.class)})
public abstract class MoSms {

MoSms() {
Expand Down
113 changes: 113 additions & 0 deletions src/test/java/com/sinch/xms/api/MoMmsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*-
* #%L
* SDK for Sinch SMS
* %%
* Copyright (C) 2016 Sinch
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.sinch.xms.api;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import com.sinch.testsupport.TestUtils;
import com.sinch.xms.ApiObjectMapper;
import com.sinch.xms.Utils;
import java.time.Clock;
import java.time.OffsetDateTime;
import java.util.Arrays;
import org.junit.Test;

public class MoMmsTest {

private final ApiObjectMapper json = new ApiObjectMapper();

@Test
public void canSerializeJson() throws Exception {
String smsId = TestUtils.freshSmsId();
OffsetDateTime receivedAt = OffsetDateTime.now(Clock.systemUTC());
String receivedAtString = json.writeValueAsString(receivedAt);

MoSms input =
new MoMms.Builder()
.recipient("12345")
.sender("987654321")
.id(smsId)
.receivedAt(receivedAt)
.body(
new MoMmsBody.Builder()
.subject("Test subject")
.message("Test message")
.media(
Arrays.asList(
MoMmsMedia.builder()
.url("Test url")
.contentType("text/txt")
.status(MoMmsMedia.MediaStatus.Uploaded)
.code(0)
.build()))
.build())
.build();

String expected =
Utils.join(
"\n",
"{",
" \"type\": \"mo_media\",",
" \"body\":{\"subject\":\"Test subject\",\"message\":\"Test message\",\"media\":[{\"url\":\"Test url\",\"content_type\":\"text/txt\",\"status\":\"Uploaded\",\"code\":0}]},",
" \"to\": \"12345\",",
" \"from\": \"987654321\",",
" \"id\": \"" + smsId + "\",",
" \"received_at\": " + receivedAtString,
"}");

String actual = json.writeValueAsString(input);

assertThat(actual, is(TestUtils.jsonEqualTo(expected)));
}

@Test
public void canDeserializeJson() throws Exception {
String smsId = TestUtils.freshSmsId();
OffsetDateTime receivedAt = OffsetDateTime.now(Clock.systemUTC());

MoSms expected =
new MoMms.Builder()
.recipient("12345")
.sender("987654321")
.id(smsId)
.receivedAt(receivedAt)
.body(
new MoMmsBody.Builder()
.subject("Test subject")
.message("Test message")
.media(
Arrays.asList(
MoMmsMedia.builder()
.url("Test url")
.contentType("text/txt")
.status(MoMmsMedia.MediaStatus.Uploaded)
.code(200)
.build()))
.build())
.build();

String input = json.writeValueAsString(expected);

MoSms actual = json.readValue(input, MoSms.class);

assertThat(actual, is(expected));
}
}

0 comments on commit 340cb1c

Please sign in to comment.