Skip to content

Commit

Permalink
feat (Mailgun/Email): Simplify some fields as Boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
JPPortier committed Dec 11, 2024
1 parent cc471f3 commit 22ab465
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 487 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.sinch.sdk.domains.mailgun.api.v1.adapters;

import com.sinch.sdk.core.databind.FormSerializer;
import java.util.Map;

public class BooleanFormSerializer extends FormSerializer<Boolean> {

@Override
public void serialize(Boolean in, String fieldName, Map<String, Object> out) {
if (null != in) {
out.put(fieldName, format(in));
}
}

private static String format(Boolean value) {
return String.format("%s", value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.sinch.sdk.domains.mailgun.api.v1.adapters;

import static org.junit.jupiter.api.Assertions.*;

import com.sinch.sdk.core.TestHelpers;
import java.util.HashMap;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class BooleanFormSerializerTest {
BooleanFormSerializer serializer = new BooleanFormSerializer();

@Test
void serializeTrue() {

HashMap<String, Object> map = new HashMap<>();

serializer.serialize(true, "key name", map);

TestHelpers.recursiveEquals("true", map.get("key name"));
}

@Test
void serializeFalse() {

HashMap<String, Object> map = new HashMap<>();

serializer.serialize(false, "key name", map);

TestHelpers.recursiveEquals("false", map.get("key name"));
}

@Test
void serializeNull() {

HashMap<String, Object> map = new HashMap<>();

serializer.serialize(null, "key name", map);

Assertions.assertNull(map.get("key name"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,36 +114,12 @@ public interface SendEmailRequest extends AdditionalProperties {
*/
String getTemplateVersion();

/** Render template in case of template sending */
public class TemplateTextEnum extends EnumDynamic<String, TemplateTextEnum> {
public static final TemplateTextEnum YES = new TemplateTextEnum("yes");

private static final EnumSupportDynamic<String, TemplateTextEnum> ENUM_SUPPORT =
new EnumSupportDynamic<>(TemplateTextEnum.class, TemplateTextEnum::new, Arrays.asList(YES));

private TemplateTextEnum(String value) {
super(value);
}

public static Stream<TemplateTextEnum> values() {
return ENUM_SUPPORT.values();
}

public static TemplateTextEnum from(String value) {
return ENUM_SUPPORT.from(value);
}

public static String valueOf(TemplateTextEnum e) {
return ENUM_SUPPORT.valueOf(e);
}
}

/**
* Render template in case of template sending
*
* @return templateText
*/
TemplateTextEnum getTemplateText();
Boolean getTemplateText();

/**
* A valid JSON-encoded dictionary used as the input for template variable expansion. See <a
Expand All @@ -163,40 +139,12 @@ public static String valueOf(TemplateTextEnum e) {
*/
List<String> getTag();

/** Enables/disables DKIM signatures on a per-message basis */
public class DkimSignatureEnum extends EnumDynamic<String, DkimSignatureEnum> {
public static final DkimSignatureEnum YES = new DkimSignatureEnum("yes");
public static final DkimSignatureEnum NO = new DkimSignatureEnum("no");
public static final DkimSignatureEnum TRUE = new DkimSignatureEnum("true");
public static final DkimSignatureEnum FALSE = new DkimSignatureEnum("false");

private static final EnumSupportDynamic<String, DkimSignatureEnum> ENUM_SUPPORT =
new EnumSupportDynamic<>(
DkimSignatureEnum.class, DkimSignatureEnum::new, Arrays.asList(YES, NO, TRUE, FALSE));

private DkimSignatureEnum(String value) {
super(value);
}

public static Stream<DkimSignatureEnum> values() {
return ENUM_SUPPORT.values();
}

public static DkimSignatureEnum from(String value) {
return ENUM_SUPPORT.from(value);
}

public static String valueOf(DkimSignatureEnum e) {
return ENUM_SUPPORT.valueOf(e);
}
}

/**
* Enables/disables DKIM signatures on a per-message basis
*
* @return enableDkimSignature
*/
DkimSignatureEnum getEnableDkimSignature();
Boolean getEnableDkimSignature();

/**
* Specify a second domain key to sign the email with. The value is formatted as <code>
Expand Down Expand Up @@ -253,42 +201,14 @@ public static String valueOf(DkimSignatureEnum e) {
*/
String getTimezoneLocalize();

/**
* Enables sending in test mode. See <a
* href="https://documentation.mailgun.com/docs/mailgun/user-manual/sending-messages/#sending-in-test-mode">Sending
* in Test Mode</a>
*/
public class TestModeEnum extends EnumDynamic<String, TestModeEnum> {
public static final TestModeEnum YES = new TestModeEnum("yes");

private static final EnumSupportDynamic<String, TestModeEnum> ENUM_SUPPORT =
new EnumSupportDynamic<>(TestModeEnum.class, TestModeEnum::new, Arrays.asList(YES));

private TestModeEnum(String value) {
super(value);
}

public static Stream<TestModeEnum> values() {
return ENUM_SUPPORT.values();
}

public static TestModeEnum from(String value) {
return ENUM_SUPPORT.from(value);
}

public static String valueOf(TestModeEnum e) {
return ENUM_SUPPORT.valueOf(e);
}
}

/**
* Enables sending in test mode. See <a
* href="https://documentation.mailgun.com/docs/mailgun/user-manual/sending-messages/#sending-in-test-mode">Sending
* in Test Mode</a>
*
* @return testMode
*/
TestModeEnum getTestMode();
Boolean getTestMode();

/**
* Toggles both click and open tracking on a per-message basis, see <a
Expand Down Expand Up @@ -376,81 +296,14 @@ public static String valueOf(TrackingClicksEnum e) {
*/
TrackingClicksEnum getTrackingClicks();

/**
* Toggles opens tracking on a per-message basis, see <a
* href="https://documentation.mailgun.com/docs/mailgun/user-manual/tracking-messages/#tracking-opens">Tracking
* Opens</a>. Has higher priority than domain-level setting.
*/
public class TrackingOpensEnum extends EnumDynamic<String, TrackingOpensEnum> {
public static final TrackingOpensEnum YES = new TrackingOpensEnum("yes");
public static final TrackingOpensEnum NO = new TrackingOpensEnum("no");
public static final TrackingOpensEnum TRUE = new TrackingOpensEnum("true");
public static final TrackingOpensEnum FALSE = new TrackingOpensEnum("false");

private static final EnumSupportDynamic<String, TrackingOpensEnum> ENUM_SUPPORT =
new EnumSupportDynamic<>(
TrackingOpensEnum.class, TrackingOpensEnum::new, Arrays.asList(YES, NO, TRUE, FALSE));

private TrackingOpensEnum(String value) {
super(value);
}

public static Stream<TrackingOpensEnum> values() {
return ENUM_SUPPORT.values();
}

public static TrackingOpensEnum from(String value) {
return ENUM_SUPPORT.from(value);
}

public static String valueOf(TrackingOpensEnum e) {
return ENUM_SUPPORT.valueOf(e);
}
}

/**
* Toggles opens tracking on a per-message basis, see <a
* href="https://documentation.mailgun.com/docs/mailgun/user-manual/tracking-messages/#tracking-opens">Tracking
* Opens</a>. Has higher priority than domain-level setting.
*
* @return trackingOpens
*/
TrackingOpensEnum getTrackingOpens();

/**
* Requires the message only be sent over a TLS connection, see <a
* href="https://documentation.mailgun.com/docs/mailgun/user-manual/tls-sending/">TLS Sending
* Connection Settings</a>. If a TLS connection can not be established, Mailgun will not deliver
* the message. If set to <code>false</code> or <code>no</code>, Mailgun will still try and
* upgrade the connection, but if Mailgun cannot, the message will be delivered over a plaintext
* SMTP connection. The default is <code>false</code>
*/
public class RequireTlsEnum extends EnumDynamic<String, RequireTlsEnum> {
public static final RequireTlsEnum YES = new RequireTlsEnum("yes");
public static final RequireTlsEnum NO = new RequireTlsEnum("no");
public static final RequireTlsEnum TRUE = new RequireTlsEnum("true");
public static final RequireTlsEnum FALSE = new RequireTlsEnum("false");

private static final EnumSupportDynamic<String, RequireTlsEnum> ENUM_SUPPORT =
new EnumSupportDynamic<>(
RequireTlsEnum.class, RequireTlsEnum::new, Arrays.asList(YES, NO, TRUE, FALSE));

private RequireTlsEnum(String value) {
super(value);
}

public static Stream<RequireTlsEnum> values() {
return ENUM_SUPPORT.values();
}

public static RequireTlsEnum from(String value) {
return ENUM_SUPPORT.from(value);
}

public static String valueOf(RequireTlsEnum e) {
return ENUM_SUPPORT.valueOf(e);
}
}
Boolean getTrackingOpens();

/**
* Requires the message only be sent over a TLS connection, see <a
Expand All @@ -462,42 +315,7 @@ public static String valueOf(RequireTlsEnum e) {
*
* @return requireTls
*/
RequireTlsEnum getRequireTls();

/**
* If <code>skip</code> activated, the certificate and hostname of the resolved MX Host will not
* be verified when trying to establish a TLS connection. If not, Mailgun will verify the
* certificate and hostname. If either one can not be verified, a TLS connection will not be
* established. The default is <code>false</code>
*/
public class SkipVerificationEnum extends EnumDynamic<String, SkipVerificationEnum> {
public static final SkipVerificationEnum YES = new SkipVerificationEnum("yes");
public static final SkipVerificationEnum NO = new SkipVerificationEnum("no");
public static final SkipVerificationEnum TRUE = new SkipVerificationEnum("true");
public static final SkipVerificationEnum FALSE = new SkipVerificationEnum("false");

private static final EnumSupportDynamic<String, SkipVerificationEnum> ENUM_SUPPORT =
new EnumSupportDynamic<>(
SkipVerificationEnum.class,
SkipVerificationEnum::new,
Arrays.asList(YES, NO, TRUE, FALSE));

private SkipVerificationEnum(String value) {
super(value);
}

public static Stream<SkipVerificationEnum> values() {
return ENUM_SUPPORT.values();
}

public static SkipVerificationEnum from(String value) {
return ENUM_SUPPORT.from(value);
}

public static String valueOf(SkipVerificationEnum e) {
return ENUM_SUPPORT.valueOf(e);
}
}
Boolean getRequireTls();

/**
* If <code>skip</code> activated, the certificate and hostname of the resolved MX Host will not
Expand All @@ -507,7 +325,7 @@ public static String valueOf(SkipVerificationEnum e) {
*
* @return skipVerification
*/
SkipVerificationEnum getSkipVerification();
Boolean getSkipVerification();

/**
* Used to specify an IP Address to send an email that is owned by your account
Expand Down Expand Up @@ -668,7 +486,7 @@ interface Builder extends AdditionalProperties.Builder {
* @return Current builder
* @see #getTemplateText
*/
Builder setTemplateText(TemplateTextEnum templateText);
Builder setTemplateText(Boolean templateText);

/**
* see getter
Expand All @@ -695,7 +513,7 @@ interface Builder extends AdditionalProperties.Builder {
* @return Current builder
* @see #getEnableDkimSignature
*/
Builder setEnableDkimSignature(DkimSignatureEnum enableDkimSignature);
Builder setEnableDkimSignature(Boolean enableDkimSignature);

/**
* see getter
Expand Down Expand Up @@ -749,7 +567,7 @@ interface Builder extends AdditionalProperties.Builder {
* @return Current builder
* @see #getTestMode
*/
Builder setTestMode(TestModeEnum testMode);
Builder setTestMode(Boolean testMode);

/**
* see getter
Expand All @@ -776,7 +594,7 @@ interface Builder extends AdditionalProperties.Builder {
* @return Current builder
* @see #getTrackingOpens
*/
Builder setTrackingOpens(TrackingOpensEnum trackingOpens);
Builder setTrackingOpens(Boolean trackingOpens);

/**
* see getter
Expand All @@ -785,7 +603,7 @@ interface Builder extends AdditionalProperties.Builder {
* @return Current builder
* @see #getRequireTls
*/
Builder setRequireTls(RequireTlsEnum requireTls);
Builder setRequireTls(Boolean requireTls);

/**
* see getter
Expand All @@ -794,7 +612,7 @@ interface Builder extends AdditionalProperties.Builder {
* @return Current builder
* @see #getSkipVerification
*/
Builder setSkipVerification(SkipVerificationEnum skipVerification);
Builder setSkipVerification(Boolean skipVerification);

/**
* see getter
Expand Down
Loading

0 comments on commit 22ab465

Please sign in to comment.