Skip to content

Commit

Permalink
lib: separate host detection logic from send method
Browse files Browse the repository at this point in the history
  • Loading branch information
narekhovhannisyan committed Sep 9, 2024
1 parent 7968a07 commit 49e099d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/lib/MailtrapClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ export default class MailtrapClient {
}

/**
* Sends mail with given `mail` params. If there is error, rejects with `MailtrapError`.
* Returns configured host. Checks if `bulk` and `sandbox` modes are activated simultaneously,
* then reject with Mailtrap Error.
* Otherwise returns appropriate host url.
*/
public async send(mail: Mail): Promise<SendResponse> {
private determineHost() {
let host;

if (this.bulk && this.sandbox) {
Expand All @@ -112,10 +114,17 @@ export default class MailtrapClient {
host = SENDING_ENDPOINT;
}

return host;
}

/**
* Sends mail with given `mail` params. If there is error, rejects with `MailtrapError`.
*/
public async send(mail: Mail): Promise<SendResponse> {
const host = this.determineHost();
const url = `${host}/api/send${
this.testInboxId ? `/${this.testInboxId}` : ""
}`;
console.log(url);
const preparedMail = encodeMailBuffers(mail);

return this.axios.post<SendResponse, SendResponse>(url, preparedMail);
Expand Down

0 comments on commit 49e099d

Please sign in to comment.