forked from equinix/ne-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrest_account.go
34 lines (29 loc) · 915 Bytes
/
rest_account.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package ne
import (
"net/http"
"net/url"
"github.com/equinix/ne-go/internal/api"
)
// GetAccounts retrieves accounts and their details for a given metro code using Network Edge API
func (c RestClient) GetAccounts(metroCode string) ([]Account, error) {
path := "/ne/v1/accounts/" + url.PathEscape(metroCode)
respBody := api.AccountResponse{}
req := c.R().SetResult(&respBody)
if err := c.Execute(req, http.MethodGet, path); err != nil {
return nil, err
}
return mapAccountsAPIToDomain(respBody.Accounts), nil
}
func mapAccountsAPIToDomain(apiAccounts []api.Account) []Account {
transformed := make([]Account, len(apiAccounts))
for i := range apiAccounts {
transformed[i] = Account{
Name: apiAccounts[i].Name,
Number: apiAccounts[i].Number,
UCMID: apiAccounts[i].UCMID,
Status: apiAccounts[i].Status,
ProjectID: apiAccounts[i].ProjectID,
}
}
return transformed
}