diff --git a/Readme.md b/Readme.md index 342885e..645b69b 100644 --- a/Readme.md +++ b/Readme.md @@ -110,6 +110,8 @@ MailerSend Golang SDK - [Add a Sender_Identity](#create-a-sender-identity) - [Update a Sender Identity](#update-a-sender-identity) - [Delete a Sender Identity](#delete-a-sender-identity) + - [Other Endpoints](#other-endpoints) + - [Get an API Quota](#get-an-api-quota) - [Types](#types) - [Helpers](#helpers) - [Testing](#testing) @@ -3212,6 +3214,36 @@ func main() { } ``` +## Other Endpoints + +### Get an API Quota + +```go +package main + +import ( + "context" + "log" + "time" + "fmt" + + "github.com/mailersend/mailersend-go" +) + +func main() { + // Create an instance of the mailersend client + ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY")) + + ctx := context.Background() + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() + + _, _, err := ms.ApiQuota.Get(ctx) + if err != nil { + log.Fatal(err) + } +} +``` # Types diff --git a/api_quota.go b/api_quota.go new file mode 100644 index 0000000..f9393ed --- /dev/null +++ b/api_quota.go @@ -0,0 +1,32 @@ +package mailersend + +import ( + "context" + "net/http" + "time" +) + +const apiQuotaBasePath = "/api-quota" + +type ApiQuotaService service + +type apiQuotaRoot struct { + Quota int `json:"quota"` + Remaining int `json:"remaining"` + Reset time.Time `json:"reset"` +} + +func (s *ApiQuotaService) Get(ctx context.Context) (*apiQuotaRoot, *Response, error) { + req, err := s.client.newRequest(http.MethodGet, apiQuotaBasePath, nil) + if err != nil { + return nil, nil, err + } + + root := new(apiQuotaRoot) + res, err := s.client.do(ctx, req, root) + if err != nil { + return nil, res, err + } + + return root, res, nil +} diff --git a/mailersend.go b/mailersend.go index c1a4013..aef999a 100644 --- a/mailersend.go +++ b/mailersend.go @@ -45,6 +45,7 @@ type Mailersend struct { SmsInbound *SmsInboundService EmailVerification *EmailVerificationService Identity *IdentityService + ApiQuota *ApiQuotaService } type service struct { @@ -129,6 +130,7 @@ func NewMailersend(apiKey string) *Mailersend { ms.SmsInbound = (*SmsInboundService)(&ms.common) ms.EmailVerification = (*EmailVerificationService)(&ms.common) ms.Identity = (*IdentityService)(&ms.common) + ms.ApiQuota = (*ApiQuotaService)(&ms.common) return ms }