Skip to content
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
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ MailerSend Java SDK
- [Create a blocklist monitor](#create-a-blocklist-monitor)
- [Update a blocklist monitor](#update-a-blocklist-monitor)
- [Delete a blocklist monitor](#delete-a-blocklist-monitor)
- [Account](#account)
- [Get account](#get-account)

- [WhatsApp](#whatsapp)
- [Send a WhatsApp message](#send-a-whatsapp-message)
Expand Down Expand Up @@ -4795,6 +4797,42 @@ public void deleteInvite() {
}
```

## Account

### Get account

Returns the plan, usage, API rate limits and resource limits of the account the API token belongs to. A `limit` of `-1` means unlimited. `addons.whatsapp` is `null` when the account has no WhatsApp add-on, and `resources.webhooks.limit` can be `null`.

```java
import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.account.AccountDetails;
import com.mailersend.sdk.exceptions.MailerSendException;

public void getAccount() {

MailerSend ms = new MailerSend();
ms.setToken("Your API token");

try {

AccountDetails account = ms.account().getAccount();

System.out.println(account.name);
System.out.println(account.status);
System.out.println(account.planType);
System.out.println(account.emails.sent);
System.out.println(account.emails.limit);
System.out.println(account.rateLimits.general);
System.out.println(account.resources.domains.used);
System.out.println(account.resources.domains.limit);

} catch (MailerSendException e) {

e.printStackTrace();
}
}
```

# WhatsApp

`from` takes a connected WhatsApp sender, either as its phone number in E.164 format or as its MailerSend sender ID. A sender connected with a Meta virtual number has no phone number, so it can only be addressed by its sender ID. Recipients are phone numbers in E.164 format, or a BSUID taken from an inbound message. Sending requires a token with the `whatsapp_full` scope.
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/mailersend/sdk/MailerSend.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
**************************************************/
package com.mailersend.sdk;

import com.mailersend.sdk.account.Account;
import com.mailersend.sdk.activities.Activities;
import com.mailersend.sdk.analytics.Analytics;
import com.mailersend.sdk.domains.Domains;
Expand Down Expand Up @@ -56,6 +57,7 @@ public class MailerSend {
private SmtpUsers smtpUsers = null;
private SenderIdentities senderIdentities = null;
private Users users = null;
private Account account = null;

/**
* <p>Constructor for MailerSend.</p>
Expand All @@ -81,6 +83,7 @@ public MailerSend() {
smtpUsers = new SmtpUsers(this);
senderIdentities = new SenderIdentities(this);
users = new Users(this);
account = new Account(this);
}


Expand Down Expand Up @@ -275,6 +278,15 @@ public Users users() {
return users;
}

/**
* Get the account access object
*
* @return the Account object
*/
public Account account() {
return account;
}

/**
* Sets the MailerSend token
*
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/com/mailersend/sdk/account/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*************************************************
* MailerSend Java SDK
* https://github.com/mailersend/mailersend-java
*
* @author MailerSend <support@mailersend.com>
* https://mailersend.com
**************************************************/
package com.mailersend.sdk.account;

import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.MailerSendApi;
import com.mailersend.sdk.exceptions.MailerSendException;

/**
* Provides access to the Account endpoint of the MailerSend API.
*
* <p>Do not instantiate directly — access via {@code MailerSend.account()}.</p>
*/
public class Account {

private final MailerSend apiObjectReference;


/**
* Do not initialize directly. This should only be accessed from MailerSend.account().
*
* @param apiObjectRef a {@link com.mailersend.sdk.MailerSend} object.
*/
public Account(MailerSend apiObjectRef) {

apiObjectReference = apiObjectRef;
}


/**
* Gets the plan, usage, rate limits and resource limits of the account the API token belongs to.
*
* @throws com.mailersend.sdk.exceptions.MailerSendException
* @return an {@link AccountDetails} object
*/
public AccountDetails getAccount() throws MailerSendException {

MailerSendApi api = new MailerSendApi();
api.setToken(apiObjectReference.getToken());

AccountResponse response = api.getRequest("/account", AccountResponse.class);

return response.account;
}
}
37 changes: 37 additions & 0 deletions src/main/java/com/mailersend/sdk/account/AccountAddons.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*************************************************
* MailerSend Java SDK
* https://github.com/mailersend/mailersend-java
*
* @author MailerSend <support@mailersend.com>
* https://mailersend.com
**************************************************/
package com.mailersend.sdk.account;

import com.google.gson.annotations.SerializedName;

/**
* Add-ons of the account.
*/
public class AccountAddons {

@SerializedName("sms")
public AccountUsage sms;

/**
* {@code null} when the account has no WhatsApp add-on.
*/
@SerializedName("whatsapp")
public AccountWhatsAppUsage whatsapp;

@SerializedName("phone_numbers")
public int phoneNumbers;

@SerializedName("domain_spaces")
public int domainSpaces;

@SerializedName("data_retention_days")
public int dataRetentionDays;

@SerializedName("dedicated_ips")
public int dedicatedIps;
}
43 changes: 43 additions & 0 deletions src/main/java/com/mailersend/sdk/account/AccountDetails.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*************************************************
* MailerSend Java SDK
* https://github.com/mailersend/mailersend-java
*
* @author MailerSend <support@mailersend.com>
* https://mailersend.com
**************************************************/
package com.mailersend.sdk.account;

import com.google.gson.annotations.SerializedName;

/**
* Represents the account the API token belongs to.
*/
public class AccountDetails {

@SerializedName("name")
public String name;

/**
* One of {@code pending}, {@code approved}, {@code rejected} or {@code suspended}.
*/
@SerializedName("status")
public String status;

@SerializedName("plan_type")
public String planType;

@SerializedName("data_retention_days")
public int dataRetentionDays;

@SerializedName("emails")
public AccountUsage emails;

@SerializedName("rate_limits")
public AccountRateLimits rateLimits;

@SerializedName("resources")
public AccountResources resources;

@SerializedName("addons")
public AccountAddons addons;
}
28 changes: 28 additions & 0 deletions src/main/java/com/mailersend/sdk/account/AccountRateLimits.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*************************************************
* MailerSend Java SDK
* https://github.com/mailersend/mailersend-java
*
* @author MailerSend <support@mailersend.com>
* https://mailersend.com
**************************************************/
package com.mailersend.sdk.account;

import com.google.gson.annotations.SerializedName;

/**
* API rate limits of the account, in requests per minute.
*/
public class AccountRateLimits {

@SerializedName("general")
public int general;

@SerializedName("email")
public int email;

@SerializedName("bulk_email")
public int bulkEmail;

@SerializedName("activity")
public int activity;
}
23 changes: 23 additions & 0 deletions src/main/java/com/mailersend/sdk/account/AccountResourceUsage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*************************************************
* MailerSend Java SDK
* https://github.com/mailersend/mailersend-java
*
* @author MailerSend <support@mailersend.com>
* https://mailersend.com
**************************************************/
package com.mailersend.sdk.account;

import com.google.gson.annotations.SerializedName;

/**
* How many of a resource the account uses, against how many its plan allows.
* The limit can be {@code null}.
*/
public class AccountResourceUsage {

@SerializedName("used")
public int used;

@SerializedName("limit")
public Integer limit;
}
37 changes: 37 additions & 0 deletions src/main/java/com/mailersend/sdk/account/AccountResources.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*************************************************
* MailerSend Java SDK
* https://github.com/mailersend/mailersend-java
*
* @author MailerSend <support@mailersend.com>
* https://mailersend.com
**************************************************/
package com.mailersend.sdk.account;

import com.google.gson.annotations.SerializedName;

/**
* Resource usage and limits of the account.
*/
public class AccountResources {

@SerializedName("domains")
public AccountResourceUsage domains;

@SerializedName("users")
public AccountResourceUsage users;

@SerializedName("free_accountant_seat")
public AccountResourceUsage freeAccountantSeat;

@SerializedName("templates")
public AccountResourceUsage templates;

@SerializedName("smtp_users")
public AccountResourceUsage smtpUsers;

@SerializedName("api_tokens")
public AccountResourceUsage apiTokens;

@SerializedName("webhooks")
public AccountResourceUsage webhooks;
}
20 changes: 20 additions & 0 deletions src/main/java/com/mailersend/sdk/account/AccountResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*************************************************
* MailerSend Java SDK
* https://github.com/mailersend/mailersend-java
*
* @author MailerSend <support@mailersend.com>
* https://mailersend.com
**************************************************/
package com.mailersend.sdk.account;

import com.google.gson.annotations.SerializedName;
import com.mailersend.sdk.MailerSendResponse;

/**
* Wraps the account response from the API.
*/
public class AccountResponse extends MailerSendResponse {

@SerializedName("data")
public AccountDetails account;
}
25 changes: 25 additions & 0 deletions src/main/java/com/mailersend/sdk/account/AccountUsage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*************************************************
* MailerSend Java SDK
* https://github.com/mailersend/mailersend-java
*
* @author MailerSend <support@mailersend.com>
* https://mailersend.com
**************************************************/
package com.mailersend.sdk.account;

import com.google.gson.annotations.SerializedName;

/**
* Sent and received messages in the current usage cycle, against the limit in force.
*/
public class AccountUsage {

@SerializedName("sent")
public int sent;

@SerializedName("received")
public int received;

@SerializedName("limit")
public int limit;
}
22 changes: 22 additions & 0 deletions src/main/java/com/mailersend/sdk/account/AccountWhatsAppUsage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*************************************************
* MailerSend Java SDK
* https://github.com/mailersend/mailersend-java
*
* @author MailerSend <support@mailersend.com>
* https://mailersend.com
**************************************************/
package com.mailersend.sdk.account;

import com.google.gson.annotations.SerializedName;

/**
* WhatsApp messages sent in the add-on cycle, against the messages the add-on includes.
*/
public class AccountWhatsAppUsage {

@SerializedName("sent")
public int sent;

@SerializedName("limit")
public int limit;
}
Loading