2017-10-31 22:03:54 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
2018-09-05 20:31:10 +00:00
|
|
|
// Quota represents a map of quota (name, value)
|
|
|
|
type Quotas map[string]int
|
2017-10-31 22:03:54 +00:00
|
|
|
|
2018-09-05 20:31:10 +00:00
|
|
|
// GetQuotas represents the response of GET /organizations/{orga_id}/quotas
|
|
|
|
type GetQuotas struct {
|
|
|
|
Quotas Quotas `json:"quotas"`
|
2017-10-31 22:03:54 +00:00
|
|
|
}
|
|
|
|
|
2018-09-05 20:31:10 +00:00
|
|
|
// GetQuotas returns a GetQuotas
|
|
|
|
func (s *API) GetQuotas() (Quotas, error) {
|
2017-10-31 22:03:54 +00:00
|
|
|
resp, err := s.GetResponsePaginate(AccountAPI, fmt.Sprintf("organizations/%s/quotas", s.Organization), url.Values{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
body, err := s.handleHTTPError([]int{http.StatusOK}, resp)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-09-05 20:31:10 +00:00
|
|
|
var quotas GetQuotas
|
2017-10-31 22:03:54 +00:00
|
|
|
|
|
|
|
if err = json.Unmarshal(body, "as); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-09-05 20:31:10 +00:00
|
|
|
return quotas.Quotas, nil
|
2017-10-31 22:03:54 +00:00
|
|
|
}
|