Skip to content

Commit

Permalink
Merge pull request #61 from mailersend/feature/58/add-get-api-quota
Browse files Browse the repository at this point in the history
feat: add Get an API Quota endpoint
  • Loading branch information
Kseniya Kalesnikava authored May 2, 2023
2 parents b36ae6b + e32d18c commit 8518630
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
32 changes: 32 additions & 0 deletions api_quota.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions mailersend.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Mailersend struct {
SmsInbound *SmsInboundService
EmailVerification *EmailVerificationService
Identity *IdentityService
ApiQuota *ApiQuotaService
}

type service struct {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 8518630

Please sign in to comment.