Files
go-unifi/unifi/map.generated.go
2020-01-10 14:31:12 -05:00

117 lines
2.7 KiB
Go

// Code generated from ace.jar fields *.json files
// DO NOT EDIT.
package unifi
import (
"fmt"
)
// just to fix compile issues with the import
var _ fmt.Formatter
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(site string) ([]Map, error) {
var respBody struct {
Meta meta `json:"meta"`
Data []Map `json:"data"`
}
err := c.do("GET", fmt.Sprintf("s/%s/rest/map", site), nil, &respBody)
if err != nil {
return nil, err
}
return respBody.Data, nil
}
func (c *Client) getMap(site, id string) (*Map, error) {
var respBody struct {
Meta meta `json:"meta"`
Data []Map `json:"data"`
}
err := c.do("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(site, id string) error {
err := c.do("DELETE", fmt.Sprintf("s/%s/rest/map/%s", site, id), struct{}{}, nil)
if err != nil {
return err
}
return nil
}
func (c *Client) createMap(site string, d *Map) (*Map, error) {
var respBody struct {
Meta meta `json:"meta"`
Data []Map `json:"data"`
}
err := c.do("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(site string, d *Map) (*Map, error) {
var respBody struct {
Meta meta `json:"meta"`
Data []Map `json:"data"`
}
err := c.do("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
}