Skip to content

Commit

Permalink
refactor (Mailgun/Emails): Apply common SDKs naming to 'Emails'
Browse files Browse the repository at this point in the history
  • Loading branch information
JPPortier committed Nov 29, 2024
1 parent d279f09 commit e24be7a
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
*/
public interface EmailsService {

SendEmailResponse send(String domain, SendEmailRequest request);
SendEmailResponse sendEmail(String domain, SendEmailRequest request);

SendEmailResponse sendMime(String domain, SendMimeEmailRequest request);
SendEmailResponse sendMimeEmail(String domain, SendMimeEmailRequest request);

GetStoredEmailResponse get(String domain, String storageKey);
GetStoredEmailResponse getStoredEmail(String domain, String storageKey);

SendingQueuesStatusResponse getSendingQueuesStatus(String domain);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ protected EmailsApi getApi() {
return this.api;
}

public SendEmailResponse send(String domain, SendEmailRequest request) {
public SendEmailResponse sendEmail(String domain, SendEmailRequest request) {
return getApi().sendEmail(domain, request);
}

public SendEmailResponse sendMime(String domain, SendMimeEmailRequest request) {
public SendEmailResponse sendMimeEmail(String domain, SendMimeEmailRequest request) {
return getApi().sendMimeEmail(domain, request);
}

public GetStoredEmailResponse get(String domain, String storageKey) {
public GetStoredEmailResponse getStoredEmail(String domain, String storageKey) {
return getApi().getStoredEmail(domain, storageKey);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ void send() {
when(api.sendEmail(eq(domainName), eq(SendEmailRequestTest.sendEmailRequest)))
.thenReturn(SendEmailResponseTest.expectedSendEmailResponse);

SendEmailResponse response = service.send(domainName, SendEmailRequestTest.sendEmailRequest);
SendEmailResponse response =
service.sendEmail(domainName, SendEmailRequestTest.sendEmailRequest);

TestHelpers.recursiveEquals(response, SendEmailResponseTest.expectedSendEmailResponse);
}
Expand All @@ -65,7 +66,7 @@ void sendMime() {
.thenReturn(SendEmailResponseTest.expectedSendEmailResponse);

SendEmailResponse response =
service.sendMime(domainName, SendMimeEmailRequestTest.sendMimEmailRequest);
service.sendMimeEmail(domainName, SendMimeEmailRequestTest.sendMimEmailRequest);

TestHelpers.recursiveEquals(response, SendEmailResponseTest.expectedSendEmailResponse);
}
Expand All @@ -75,7 +76,7 @@ void get() {
when(api.getStoredEmail(eq(domainName), eq(storageKey)))
.thenReturn(GetStoredEmailResponseTest.expectedGetEmailResponse);

GetStoredEmailResponse response = service.get(domainName, storageKey);
GetStoredEmailResponse response = service.getStoredEmail(domainName, storageKey);

TestHelpers.recursiveEquals(response, GetStoredEmailResponseTest.expectedGetEmailResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void send() {
.setSubject("E2E test text email")
.build();

sendEmailResponse = service.send(domainName, request);
sendEmailResponse = service.sendEmail(domainName, request);
}

@When("^I send a request to send a MIME email$")
Expand All @@ -71,13 +71,13 @@ public void sendMime() {
.setMessage(tempFile)
.build();

sendMimeEmailResponse = service.sendMime(domainName, request);
sendMimeEmailResponse = service.sendMimeEmail(domainName, request);
}

@When("^I send a request to retrieve a stored email$")
public void getStoredEmail() {

getStoredEmailResponse = service.get(domainName, storageKey);
getStoredEmailResponse = service.getStoredEmail(domainName, storageKey);
}

@When("^I send a request to get the sending queue status$")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import java.io.IOException;
import java.util.logging.Logger;

public class Get extends BaseApplication {
public class GetStoredEmail extends BaseApplication {

private static final Logger LOGGER = Logger.getLogger(Get.class.getName());
private static final Logger LOGGER = Logger.getLogger(GetStoredEmail.class.getName());

public Get() throws IOException {}
public GetStoredEmail() throws IOException {}

public static void main(String[] args) {
try {
new Get().run();
new GetStoredEmail().run();
} catch (Exception e) {
LOGGER.severe(e.getMessage());
e.printStackTrace();
Expand All @@ -26,9 +26,9 @@ public void run() {
EmailsService service = client.mailgun().v1().emails();

String storageKey = "value";
LOGGER.info("Get message with storageKey: " + storageKey);
LOGGER.info("Get stored email with storageKey: " + storageKey);

GetStoredEmailResponse response = service.get(mailgunDomain, storageKey);
GetStoredEmailResponse response = service.getStoredEmail(mailgunDomain, storageKey);

LOGGER.info("Response: " + response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@
import com.sinch.sample.BaseApplication;
import com.sinch.sdk.domains.mailgun.api.v1.EmailsService;
import com.sinch.sdk.domains.mailgun.models.v1.emails.request.SendEmailRequest;
import com.sinch.sdk.domains.mailgun.models.v1.emails.request.SendEmailRequest.TrackingEnum;
import com.sinch.sdk.domains.mailgun.models.v1.emails.response.SendEmailResponse;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.logging.Logger;

public class Send extends BaseApplication {
public class SendEmail extends BaseApplication {

private static final Logger LOGGER = Logger.getLogger(Send.class.getName());
private static final Logger LOGGER = Logger.getLogger(SendEmail.class.getName());

public Send() throws IOException {}
public SendEmail() throws IOException {}

public static void main(String[] args) {
try {
new Send().run();
new SendEmail().run();
} catch (Exception e) {
LOGGER.severe(e.getMessage());
e.printStackTrace();
Expand All @@ -30,11 +33,11 @@ public void run() {

EmailsService service = client.mailgun().v1().emails();

LOGGER.info("Send message with Mailgun to: " + mailgunTo);
LOGGER.info("Send email with Mailgun to: " + mailgunTo);

SendEmailRequest parameters = createTextEmail();

SendEmailResponse response = service.send(mailgunDomain, parameters);
SendEmailResponse response = service.sendEmail(mailgunDomain, parameters);

LOGGER.info("Response: " + response);
}
Expand Down Expand Up @@ -70,13 +73,15 @@ SendEmailRequest createTextEmail() {

return SendEmailRequest.builder()
.setFrom(mailgunFrom)
.setTo(Arrays.asList(mailgunTo, "[email protected]"))
.setTo(Arrays.asList(mailgunTo))
.setText("\uD83D\uDCE7 Text sent with Sinch SDK Java")
.setHtml("&#128231; HTML sent with <bold>Sinch SDK Java</bold>")
.setAttachment(Arrays.asList(tempFile, tempFile2))
.setSubject("\uD83D\uDCE7 Hello from Sinch SDK Java")
.setTag(Arrays.asList("my tag 1", "my tag 2"))
// .setTestMode(TestMode.YES)
.setTracking(TrackingEnum.YES)
.setDeliveryTime(Instant.now().plus(10, ChronoUnit.SECONDS))
.put("v:myvarkey", "myvar-value")
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
import java.util.Arrays;
import java.util.logging.Logger;

public class SendMime extends BaseApplication {
public class SendMimeEmail extends BaseApplication {

private static final Logger LOGGER = Logger.getLogger(SendMime.class.getName());
private static final Logger LOGGER = Logger.getLogger(SendMimeEmail.class.getName());

public SendMime() throws IOException {}
public SendMimeEmail() throws IOException {}

public static void main(String[] args) {
try {
new SendMime().run();
new SendMimeEmail().run();
} catch (Exception e) {
LOGGER.severe(e.getMessage());
e.printStackTrace();
Expand All @@ -30,11 +30,11 @@ public void run() {

EmailsService service = client.mailgun().v1().emails();

LOGGER.info("Send message with Mailgun to: " + mailgunTo);
LOGGER.info("Send MIME email with Mailgun to: " + mailgunTo);

SendMimeEmailRequest parameters = createMime();

SendEmailResponse response = service.sendMime(mailgunDomain, parameters);
SendEmailResponse response = service.sendMimeEmail(mailgunDomain, parameters);

LOGGER.info("Response: " + response);
}
Expand Down

0 comments on commit e24be7a

Please sign in to comment.