87 lines
1.7 KiB
Go
87 lines
1.7 KiB
Go
package unifi
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func (c *Client) ListWLANGroup(site string) ([]WLANGroup, error) {
|
|
var respBody struct {
|
|
Meta meta `json:"meta"`
|
|
Data []WLANGroup `json:"data"`
|
|
}
|
|
|
|
err := c.do("GET", fmt.Sprintf("s/%s/rest/wlangroup", site), nil, &respBody)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return respBody.Data, nil
|
|
}
|
|
|
|
func (c *Client) GetWLANGroup(site, id string) (*WLANGroup, error) {
|
|
var respBody struct {
|
|
Meta meta `json:"meta"`
|
|
Data []WLANGroup `json:"data"`
|
|
}
|
|
|
|
err := c.do("GET", fmt.Sprintf("s/%s/rest/wlangroup/%s", site, id), nil, &respBody)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if len(respBody.Data) != 1 {
|
|
return nil, &NotFoundError{}
|
|
}
|
|
|
|
d := respBody.Data[0]
|
|
return &d, nil
|
|
}
|
|
|
|
func (c *Client) DeleteWLANGroup(site, id string) error {
|
|
err := c.do("DELETE", fmt.Sprintf("s/%s/rest/wlangroup/%s", site, id), struct{}{}, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (c *Client) CreateWLANGroup(site string, d *WLANGroup) (*WLANGroup, error) {
|
|
var respBody struct {
|
|
Meta meta `json:"meta"`
|
|
Data []WLANGroup `json:"data"`
|
|
}
|
|
|
|
err := c.do("POST", fmt.Sprintf("s/%s/rest/wlangroup", site), d, &respBody)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if len(respBody.Data) != 1 {
|
|
return nil, &NotFoundError{}
|
|
}
|
|
|
|
new := respBody.Data[0]
|
|
|
|
return &new, nil
|
|
}
|
|
|
|
func (c *Client) UpdateWLANGroup(site string, d *WLANGroup) (*WLANGroup, error) {
|
|
var respBody struct {
|
|
Meta meta `json:"meta"`
|
|
Data []WLANGroup `json:"data"`
|
|
}
|
|
|
|
err := c.do("PUT", fmt.Sprintf("s/%s/rest/wlangroup/%s", site, d.ID), d, &respBody)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if len(respBody.Data) != 1 {
|
|
return nil, &NotFoundError{}
|
|
}
|
|
|
|
new := respBody.Data[0]
|
|
|
|
return &new, nil
|
|
}
|