121 lines
2.9 KiB
Go
121 lines
2.9 KiB
Go
// Code generated from ace.jar fields *.json files
|
|
// DO NOT EDIT.
|
|
|
|
package unifi
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
// just to fix compile issues with the import
|
|
var (
|
|
_ fmt.Formatter
|
|
_ context.Context
|
|
)
|
|
|
|
type Map struct {
|
|
ID string `json:"_id,omitempty"`
|
|
SiteID string `json:"site_id,omitempty"`
|
|
|
|
Hidden bool `json:"attr_hidden,omitempty"`
|
|
HiddenID string `json:"attr_hidden_id,omitempty"`
|
|
NoDelete bool `json:"attr_no_delete,omitempty"`
|
|
NoEdit bool `json:"attr_no_edit,omitempty"`
|
|
|
|
Lat string `json:"lat,omitempty"` // ^([-]?[\d]+[.]?[\d]*([eE][-+]?[\d]+)?)$
|
|
Lng string `json:"lng,omitempty"` // ^([-]?[\d]+[.]?[\d]*([eE][-+]?[\d]+)?)$
|
|
MapTypeID string `json:"mapTypeId"` // satellite|roadmap|hybrid|terrain
|
|
Name string `json:"name,omitempty"`
|
|
OffsetLeft float64 `json:"offset_left,omitempty"`
|
|
OffsetTop float64 `json:"offset_top,omitempty"`
|
|
Opacity float64 `json:"opacity,omitempty"` // ^(0(\.[\d]{1,2})?|1)$|^$
|
|
Selected bool `json:"selected"`
|
|
Tilt int `json:"tilt,omitempty"`
|
|
Type string `json:"type,omitempty"` // designerMap|imageMap|googleMap
|
|
Unit string `json:"unit,omitempty"` // m|f
|
|
Upp float64 `json:"upp,omitempty"`
|
|
Zoom int `json:"zoom,omitempty"`
|
|
}
|
|
|
|
func (c *Client) listMap(ctx context.Context, site string) ([]Map, error) {
|
|
var respBody struct {
|
|
Meta meta `json:"meta"`
|
|
Data []Map `json:"data"`
|
|
}
|
|
|
|
err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/map", site), nil, &respBody)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return respBody.Data, nil
|
|
}
|
|
|
|
func (c *Client) getMap(ctx context.Context, site, id string) (*Map, error) {
|
|
var respBody struct {
|
|
Meta meta `json:"meta"`
|
|
Data []Map `json:"data"`
|
|
}
|
|
|
|
err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/map/%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) deleteMap(ctx context.Context, site, id string) error {
|
|
err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/map/%s", site, id), struct{}{}, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (c *Client) createMap(ctx context.Context, site string, d *Map) (*Map, error) {
|
|
var respBody struct {
|
|
Meta meta `json:"meta"`
|
|
Data []Map `json:"data"`
|
|
}
|
|
|
|
err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/map", 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) updateMap(ctx context.Context, site string, d *Map) (*Map, error) {
|
|
var respBody struct {
|
|
Meta meta `json:"meta"`
|
|
Data []Map `json:"data"`
|
|
}
|
|
|
|
err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/map/%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
|
|
}
|