diff --git a/configuration.go b/configuration.go index b90e737..3394a71 100644 --- a/configuration.go +++ b/configuration.go @@ -9,7 +9,7 @@ import ( ) const ( - libraryVersion = "6.25.0" + libraryVersion = "6.26.0" defaultBasePath = "https://api.transip.nl/v6" userAgent = "go-client-gotransip/" + libraryVersion ) diff --git a/email/mailpackage.go b/email/mailpackage.go new file mode 100644 index 0000000..da9122a --- /dev/null +++ b/email/mailpackage.go @@ -0,0 +1,13 @@ +package email + +// Mailpackage struct of a mailpackage +type Mailpackage struct { + Domain string `json:"domain"` + Status string `json:"status"` +} + +// mailpackagesWrapper contains a list of Mailpackage in it. +// this is solely used for unmarshalling/marshalling +type mailpackagesWrapper struct { + MailPackages []Mailpackage `json:"packages"` +} diff --git a/email/repository.go b/email/repository.go index 24f5dcc..36ccf70 100644 --- a/email/repository.go +++ b/email/repository.go @@ -193,3 +193,12 @@ func (r *Repository) UnlinkMailaddon(addonID int, mailbox string) error { return err } + +// GetMailpackages gets a list of mail packages associated with a account +func (r *Repository) GetMailpackages() ([]Mailpackage, error) { + var response mailpackagesWrapper + restRequest := rest.Request{Endpoint: "/email"} + err := r.Client.Get(restRequest, &response) + + return response.MailPackages, err +} diff --git a/email/repository_test.go b/email/repository_test.go index db315f5..9975ec4 100644 --- a/email/repository_test.go +++ b/email/repository_test.go @@ -306,7 +306,6 @@ func TestRepository_UnlinkAddonInvalidMailbox(t *testing.T) { } func TestRepository_GetMailAddonsByDomainName(t *testing.T) { - const apiResponse = `{"addons": [{"id": 282154,"diskSpace": 1024,"mailboxes": 5,"linkedMailBox": "test@example.com","canBeLinked": false}]}` server := testutil.MockServer{T: t, ExpectedURL: "/email/example.com/mail-addons", ExpectedMethod: "GET", StatusCode: 200, Response: apiResponse} client, tearDown := server.GetClient() @@ -323,3 +322,21 @@ func TestRepository_GetMailAddonsByDomainName(t *testing.T) { assert.Equal(t, 5, all[0].Mailboxes) assert.Equal(t, 1024, all[0].DiskSpace) } + +func TestRepository_GetMailpackages(t *testing.T) { + const apiResponse = `{"packages": [{"domain": "example.com", "status": "creating"},{"domain": "example2.com", "status": "created"}]}` + server := testutil.MockServer{T: t, ExpectedURL: "/email", ExpectedMethod: "GET", StatusCode: 200, Response: apiResponse} + client, tearDown := server.GetClient() + defer tearDown() + repo := Repository{Client: *client} + + all, err := repo.GetMailpackages() + require.NoError(t, err) + require.Equal(t, 2, len(all)) + + assert.Equal(t, "example.com", all[0].Domain) + assert.Equal(t, "creating", all[0].Status) + + assert.Equal(t, "example2.com", all[1].Domain) + assert.Equal(t, "created", all[1].Status) +} diff --git a/examples/email/main.go b/examples/email/main.go index 1faefc2..7850563 100644 --- a/examples/email/main.go +++ b/examples/email/main.go @@ -74,4 +74,15 @@ func main() { fmt.Printf("Addon ID %d with disk space: %d, additional mailboxes: '%d' \n", addon.ID, addon.DiskSpace, addon.Mailboxes) } fmt.Println(strings.Repeat("-", 50)) + + log.Println("Getting a list of mail packages") + mailpackages, err := emailRepo.GetMailpackages() + if err != nil { + panic(err) + } + fmt.Println(strings.Repeat("-", 50)) + for _, pkg := range mailpackages { + fmt.Printf("Package for domain %s and status %s", pkg.Domain, pkg.Status) + } + fmt.Println(strings.Repeat("-", 50)) }