diff --git a/README.md b/README.md index e34b2aa..ca31bc8 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,13 @@ but can be used independently for any Go project requiring UniFi Network Control - Great UniFi Network Controller API coverage through automated code generation and manually added code for undocumented endpoints - Generated data models from UniFi Controller API specifications - Daily automated updates to track the latest UniFi Controller versions +- Easy to use client with support for API Key and username/password authentication - Support for multiple UniFi Controller versions - Strong typing for all API models with Go structs ## Code Generation -The data models and basic REST methodsare generated from JSON specifications found in the UniFi Controller JAR files. Those JSON specs show all fields and the associated regex/validation information. +The data models and basic REST methods are generated from JSON specifications found in the UniFi Controller JAR files. Those JSON specs show all fields and the associated regex/validation information. This ensures accuracy and completeness of the API coverage. However, code generation is not perfect and some endpoints might be missing, or not covered perfectly by the generated code. We hope to rely on official API specifications as soon as they are available. To regenerate the code for the latest UniFi Controller version: @@ -31,17 +32,116 @@ challenging to directly use Java classes. Contributions and suggestions for impr ## Usage -TBD +Unifi client support both username/password and API Key authentication. It is recommended to use API Key authentication for better security, +as well as dedicated user restricted to local access only. + +### Obtaining an API Key +1. Open your Site in UniFi Site Manager +2. Click on `Control Plane -> Admins & Users`. +3. Select your Admin user. +4. Click `Create API Key`. +5. Add a name for your API Key. +6. Copy the key and store it securely, as it will only be displayed once. +7. Click Done to ensure the key is hashed and securely stored. +8. Use the API Key 🎉 + +### Client Initialization + +```go +c, err := unifi.NewClient(&unifi.ClientConfig{ + BaseURL: "https://unifi.localdomain", + APIKey: "your-api-key", +}) +``` + +Instead of API Key, you can also use username/password for authentication: + +```go +c, err := unifi.NewClient(&unifi.ClientConfig{ + BaseURL: "https://unifi.localdomain", + Username: "your-username", + Password: "your-password", +}) +``` + +If you are using self-signed certificates on your UniFi Controller, you can disable certificate verification: + +```go +c, err := unifi.NewClient(&unifi.ClientConfig{ + ... + VerifySSL: false, +}) +``` + +List of available client configuration options is available [here](https://pkg.go.dev/github.com/filipowm/go-unifi/unifi#ClientConfig). + +### Customizing HTTP Client + +You can customize underlying HTTP client by using `HttpCustomizer` interface: + +```go +c, err := unifi.NewClient(&unifi.ClientConfig{ + ... + HttpCustomizer: func(transport *http.Transport) error { + transport.MaxIdleConns = 10 + return nil + }, +}) +``` + +### Using interceptors + +You can use interceptors to modify requests and responses. This gives you more control over the client behavior +and flexibility to add custom logic. + +To use interceptor logic, you need to create a struct implementing [ClientInterceptor](https://pkg.go.dev/github.com/filipowm/go-unifi/unifi#ClientInterceptor). interface. +For example, you can use interceptors to log requests and responses: + +```go +type LoggingInterceptor struct{} + +func (l *LoggingInterceptor) InterceptRequest(req *http.Request) error { + log.Printf("Request: %s %s", req.Method, req.URL) + return nil +} + +func (l *LoggingInterceptor) InterceptResponse(resp *http.Response) error { + log.Printf("Response status: %d", resp.StatusCode) + return nil +} + +c, err := unifi.NewClient(&unifi.ClientConfig{ + ... + Interceptors: []unifi.ClientInterceptor{&LoggingInterceptor{}}, +}) +``` + +### Examples + +List all available networks: +```go +network, err := c.ListNetwork(ctx, "site-name") +``` + +Create user assigned to network: +```go +user, err := c.CreateUser(ctx, "site-name", &unifi.User{ + Name: "My Network User", + MAC: "00:00:00:00:00:00", + NetworkID: network[0].ID, + IP: "10.0.21.37", +}) +``` ## Plans - [ ] Increase API coverage, or modify code generation to rely on the official UniFi Controller API specifications -- [ ] Improve error handling (currently only basic error handling is implemented and some of errors are swallowed) -- [ ] Improve client creation -- [ ] Support authentication via Control Plane API Key -- [ ] Generate client code for currently generated API structures, for use within or outside of the Terraform provider +- [ ] Improve error handling (currently only basic error handling is implemented and some of the errors are swallowed) +- [x] Improve client code for better usability +- [x] Support API Key authentication +- [ ] Generate client code for currently generated API structures, for use within or outside the Terraform provider - [ ] Increase test coverage -- [ ] Implement validation for all fields +- [ ] Implement validation for fields and structures - [ ] Add more documentation and examples - [ ] Bugfixing... diff --git a/codegen/api.go.tmpl b/codegen/api.go.tmpl index d0dadeb..6cac7f5 100644 --- a/codegen/api.go.tmpl +++ b/codegen/api.go.tmpl @@ -67,11 +67,11 @@ func (dst *{{ $k }}) UnmarshalJSON(b []byte) error { {{ if not .IsSetting }} func (c *Client) list{{ .StructName }}(ctx context.Context, site string) ([]{{ .StructName }}, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []{{ .StructName }} `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/{{ if eq .StructName "Device" }}stat/{{else if eq .StructName "APGroup" }}{{ else }}rest/{{ end }}{{ .ResourcePath }}", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/{{ if eq .StructName "Device" }}stat/{{else if eq .StructName "APGroup" }}{{ else }}rest/{{ end }}{{ .ResourcePath }}", site), nil, &respBody) if err != nil { return nil, err } @@ -82,20 +82,20 @@ func (c *Client) list{{ .StructName }}(ctx context.Context, site string) ([]{{ . func (c *Client) get{{ .StructName }}(ctx context.Context, site{{ if not .IsSetting }}, id{{ end }} string) (*{{ .StructName }}, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []{{ .StructName }} `json:"data"` } {{ if .IsSetting }} - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/{{ .ResourcePath }}", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/{{ .ResourcePath }}", site), nil, &respBody) {{- else }} - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/{{ if eq .StructName "Device" }}stat{{ else }}rest{{ end }}/{{ .ResourcePath }}/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/{{ if eq .StructName "Device" }}stat{{ else }}rest{{ end }}/{{ .ResourcePath }}/%s", site, id), nil, &respBody) {{- end }} if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -104,7 +104,7 @@ func (c *Client) get{{ .StructName }}(ctx context.Context, site{{ if not .IsSett {{ if not .IsSetting }} func (c *Client) delete{{ .StructName }}(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/{{ .ResourcePath }}/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/{{ .ResourcePath }}/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -113,17 +113,17 @@ func (c *Client) delete{{ .StructName }}(ctx context.Context, site, id string) e func (c *Client) create{{ .StructName }}(ctx context.Context, site string, d *{{ .StructName }}) (*{{ .StructName }}, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []{{ .StructName }} `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/{{ .ResourcePath }}", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/{{ .ResourcePath }}", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -134,21 +134,21 @@ func (c *Client) create{{ .StructName }}(ctx context.Context, site string, d *{{ func (c *Client) update{{ .StructName }}(ctx context.Context, site string, d *{{ .StructName }}) (*{{ .StructName }}, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []{{ .StructName }} `json:"data"` } {{ if .IsSetting }} d.Key = "{{ .ResourcePath }}" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/{{ .ResourcePath }}", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/{{ .ResourcePath }}", site), d, &respBody) {{- else }} - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/{{ .ResourcePath }}/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/{{ .ResourcePath }}/%s", site, d.ID), d, &respBody) {{- end }} if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/go.mod b/go.mod index da05451..8c33e3c 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/tj/assert v0.0.3 github.com/ulikunitz/xz v0.5.12 github.com/xor-gate/ar v0.0.0-20170530204233-5c72ae81e2b7 + golang.org/x/net v0.34.0 golang.org/x/tools v0.29.0 ) @@ -167,7 +168,7 @@ require ( github.com/firefart/nonamedreturns v1.0.5 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/fzipp/gocyclo v0.6.0 // indirect - github.com/gabriel-vasile/mimetype v1.4.2 // indirect + github.com/gabriel-vasile/mimetype v1.4.8 // indirect github.com/ghostiam/protogetter v0.3.8 // indirect github.com/github/smimesign v0.2.0 // indirect github.com/go-critic/go-critic v0.11.5 // indirect @@ -427,7 +428,6 @@ require ( golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect golang.org/x/exp/typeparams v0.0.0-20241108190413-2d47ceb2692f // indirect golang.org/x/mod v0.22.0 // indirect - golang.org/x/net v0.34.0 // indirect golang.org/x/oauth2 v0.23.0 // indirect golang.org/x/sync v0.10.0 // indirect golang.org/x/sys v0.29.0 // indirect diff --git a/go.sum b/go.sum index 855c363..a2b49d6 100644 --- a/go.sum +++ b/go.sum @@ -105,8 +105,6 @@ github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEV github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= github.com/OpenPeeDeeP/depguard/v2 v2.2.0 h1:vDfG60vDtIuf0MEOhmLlLLSzqaRM8EMcgJPdp74zmpA= github.com/OpenPeeDeeP/depguard/v2 v2.2.0/go.mod h1:CIzddKRvLBC4Au5aYP/i3nyaWQ+ClszLIuVocRiCYFQ= -github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78= -github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= github.com/ProtonMail/go-crypto v1.1.5 h1:eoAQfK2dwL+tFSFpr7TbOaPNUbPiJj4fLYwwGE1FQO4= github.com/ProtonMail/go-crypto v1.1.5/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f h1:tCbYj7/299ekTTXpdwKYF8eBlsYsDVoggDAuAjoK66k= @@ -231,7 +229,6 @@ github.com/butuzov/ireturn v0.3.1 h1:mFgbEI6m+9W8oP/oDdfA34dLisRFCj2G6o/yiI1yZrY github.com/butuzov/ireturn v0.3.1/go.mod h1:ZfRp+E7eJLC0NQmk1Nrm1LOrn/gQlOykv+cVPdiXH5M= github.com/butuzov/mirror v1.3.0 h1:HdWCXzmwlQHdVhwvsfBb2Au0r3HyINry3bDWLYXiKoc= github.com/butuzov/mirror v1.3.0/go.mod h1:AEij0Z8YMALaq4yQj9CPPVYOyJQyiexpQEQgihajRfI= -github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/caarlos0/ctrlc v1.2.0 h1:AtbThhmbeYx1WW3WXdWrd94EHKi+0NPRGS4/4pzrjwk= github.com/caarlos0/ctrlc v1.2.0/go.mod h1:n3gDlSjsXZ7rbD9/RprIR040b7oaLfNStikPd4gFago= github.com/caarlos0/env/v11 v11.0.1 h1:A8dDt9Ub9ybqRSUF3fQc/TA/gTam2bKT4Pit+cwrsPs= @@ -278,7 +275,6 @@ github.com/chrismellard/docker-credential-acr-env v0.0.0-20230304212654-82a0ddb2 github.com/ckaznocha/intrange v0.3.0 h1:VqnxtK32pxgkhJgYQEeOArVidIPg+ahLP7WBOXZd5ZY= github.com/ckaznocha/intrange v0.3.0/go.mod h1:+I/o2d2A1FBHgGELbGxzIcyd3/9l9DuwjM8FsbSS3Lo= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= github.com/cloudflare/circl v1.3.8 h1:j+V8jJt09PoeMFIu2uh5JUyEaIHTXVOHslFoLNAKqwI= github.com/cloudflare/circl v1.3.8/go.mod h1:PDRU+oXvdD7KCtgKxW95M5Z8BpSCJXQORiZFnBQS5QU= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= @@ -296,8 +292,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lV github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/curioswitch/go-reassign v0.3.0 h1:dh3kpQHuADL3cobV/sSGETA8DOv457dwl+fbBAhrQPs= github.com/curioswitch/go-reassign v0.3.0/go.mod h1:nApPCCTtqLJN/s8HfItCcKV0jIPwluBOvZP+dsJGA88= -github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= -github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= github.com/cyphar/filepath-securejoin v0.3.6 h1:4d9N5ykBnSp5Xn2JkhocYDkOpURL/18CYMpo6xB9uWM= github.com/cyphar/filepath-securejoin v0.3.6/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI= github.com/daixiang0/gci v0.13.5 h1:kThgmH1yBmZSBCh1EJVxQ7JsHpm5Oms0AMed/0LaH4c= @@ -340,8 +334,8 @@ github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4 github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= -github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU= -github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM= +github.com/elazarl/goproxy v1.4.0 h1:4GyuSbFa+s26+3rmYNSuUVsx+HgPrV1bk1jXI0l9wjM= +github.com/elazarl/goproxy v1.4.0/go.mod h1:X/5W/t+gzDyLfHW4DrMdpjqYjpXsURlBt9lpBDxZZZQ= github.com/elliotchance/orderedmap/v2 v2.2.0 h1:7/2iwO98kYT4XkOjA9mBEIwvi4KpGB4cyHeOFOnj4Vk= github.com/elliotchance/orderedmap/v2 v2.2.0/go.mod h1:85lZyVbpGaGvHvnKa7Qhx7zncAdBIBq6u56Hb1PRU5Q= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= @@ -370,28 +364,24 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/fzipp/gocyclo v0.6.0 h1:lsblElZG7d3ALtGMx9fmxeTKZaLLpU8mET09yN4BBLo= github.com/fzipp/gocyclo v0.6.0/go.mod h1:rXPyn8fnlpa0R2csP/31uerbiVBugk5whMdlyaLkLoA= -github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= -github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= +github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= github.com/ghostiam/protogetter v0.3.8 h1:LYcXbYvybUyTIxN2Mj9h6rHrDZBDwZloPoKctWrFyJY= github.com/ghostiam/protogetter v0.3.8/go.mod h1:WZ0nw9pfzsgxuRsPOFQomgDVSWtDLJRfQJEhsGbmQMA= github.com/github/smimesign v0.2.0 h1:Hho4YcX5N1I9XNqhq0fNx0Sts8MhLonHd+HRXVGNjvk= github.com/github/smimesign v0.2.0/go.mod h1:iZiiwNT4HbtGRVqCQu7uJPEZCuEE5sfSSttcnePkDl4= -github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE= -github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8= +github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c= +github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU= github.com/go-critic/go-critic v0.11.5 h1:TkDTOn5v7EEngMxu8KbuFqFR43USaaH8XRJLz1jhVYA= github.com/go-critic/go-critic v0.11.5/go.mod h1:wu6U7ny9PiaHaZHcvMDmdysMqvDem162Rh3zWTrqk8M= github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI= github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= -github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= -github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= github.com/go-git/go-billy/v5 v5.6.2 h1:6Q86EsPXMa7c3YZ3aLAQsMA0VlWmy43r6FHqa/UNbRM= github.com/go-git/go-billy/v5 v5.6.2/go.mod h1:rcFC2rAsp/erv7CMz9GczHcuD0D32fWzH+MJAU+jaUU= github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII= -github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys= -github.com/go-git/go-git/v5 v5.12.0/go.mod h1:FTM9VKtnI2m65hNI/TenDDDnUf2Q9FHnXYjuz9i5OEY= github.com/go-git/go-git/v5 v5.13.2 h1:7O7xvsK7K+rZPKW6AQR1YyNhfywkv7B8/FsP3ki6Zv0= github.com/go-git/go-git/v5 v5.13.2/go.mod h1:hWdW5P4YZRjmpGHwRH2v3zkWcNl6HeXaXQEMGb3NJ9A= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -847,8 +837,6 @@ github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3v github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= -github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= -github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= github.com/pjbgf/sha1cd v0.3.2 h1:a9wb0bp1oC2TGwStyn0Umc/IGKQnEgF0vVaZ8QF8eo4= github.com/pjbgf/sha1cd v0.3.2/go.mod h1:zQWigSxVmsHEZow5qaLtPYxpcKMMQpa09ixqBxuCS6A= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= @@ -943,8 +931,6 @@ github.com/sivchari/containedctx v1.0.3 h1:x+etemjbsh2fB5ewm5FeLNi5bUjK0V8n0RB+W github.com/sivchari/containedctx v1.0.3/go.mod h1:c1RDvCbnJLtH4lLcYD/GqwiBSSf4F5Qk0xld2rBqzJ4= github.com/sivchari/tenv v1.12.1 h1:+E0QzjktdnExv/wwsnnyk4oqZBUfuh89YMQT1cyuvSY= github.com/sivchari/tenv v1.12.1/go.mod h1:1LjSOUCc25snIr5n3DtGGrENhX3LuWefcplwVGC24mw= -github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A= -github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= github.com/skeema/knownhosts v1.3.0 h1:AM+y0rI04VksttfwjkSTNQorvGqmwATnvnAHpSgc0LY= github.com/skeema/knownhosts v1.3.0/go.mod h1:sPINvnADmT/qYH1kfv+ePMmOBTH6Tbl7b5LvTDjFK7M= github.com/slack-go/slack v0.13.0 h1:7my/pR2ubZJ9912p9FtvALYpbt0cQPAqkRy2jaSI1PQ= @@ -1136,9 +1122,7 @@ golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= -golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= -golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= @@ -1235,7 +1219,6 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/unifi/account.generated.go b/unifi/account.generated.go index 55ee76c..c087f56 100644 --- a/unifi/account.generated.go +++ b/unifi/account.generated.go @@ -62,11 +62,11 @@ func (dst *Account) UnmarshalJSON(b []byte) error { func (c *Client) listAccount(ctx context.Context, site string) ([]Account, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Account `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/account", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/account", site), nil, &respBody) if err != nil { return nil, err } @@ -76,17 +76,17 @@ func (c *Client) listAccount(ctx context.Context, site string) ([]Account, error func (c *Client) getAccount(ctx context.Context, site, id string) (*Account, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Account `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/account/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/account/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -94,7 +94,7 @@ func (c *Client) getAccount(ctx context.Context, site, id string) (*Account, err } func (c *Client) deleteAccount(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/account/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/account/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -103,17 +103,17 @@ func (c *Client) deleteAccount(ctx context.Context, site, id string) error { func (c *Client) createAccount(ctx context.Context, site string, d *Account) (*Account, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Account `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/account", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/account", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -123,17 +123,17 @@ func (c *Client) createAccount(ctx context.Context, site string, d *Account) (*A func (c *Client) updateAccount(ctx context.Context, site string, d *Account) (*Account, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Account `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/account/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/account/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/ap_group.go b/unifi/ap_group.go index 5e02d34..e8c6b9c 100644 --- a/unifi/ap_group.go +++ b/unifi/ap_group.go @@ -28,7 +28,7 @@ type APGroup struct { func (c *Client) ListAPGroup(ctx context.Context, site string) ([]APGroup, error) { var respBody []APGroup - err := c.do(ctx, "GET", fmt.Sprintf("%s/site/%s/apgroups", c.apiV2Path, site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("%s/site/%s/apgroups", c.apiPaths.ApiV2Path, site), nil, &respBody) if err != nil { return nil, err } @@ -38,17 +38,17 @@ func (c *Client) ListAPGroup(ctx context.Context, site string) ([]APGroup, error // func (c *Client) getWLANGroup(ctx context.Context, site, id string) (*WLANGroup, error) { // var respBody struct { -// Meta meta `json:"meta"` +// Meta Meta `json:"Meta"` // Data []WLANGroup `json:"data"` // } -// err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/wlangroup/%s", site, id), nil, &respBody) +// err := c.Get(ctx, 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{} +// return nil, NotFoundError // } // d := respBody.Data[0] @@ -56,7 +56,7 @@ func (c *Client) ListAPGroup(ctx context.Context, site string) ([]APGroup, error // } // func (c *Client) deleteWLANGroup(ctx context.Context, site, id string) error { -// err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/wlangroup/%s", site, id), struct{}{}, nil) +// err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/wlangroup/%s", site, id), struct{}{}, nil) // if err != nil { // return err // } @@ -66,7 +66,7 @@ func (c *Client) ListAPGroup(ctx context.Context, site string) ([]APGroup, error func (c *Client) CreateAPGroup(ctx context.Context, site string, d *APGroup) (*APGroup, error) { var respBody APGroup - err := c.do(ctx, "POST", fmt.Sprintf("%s/site/%s/apgroups", c.apiV2Path, site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("%s/site/%s/apgroups", c.apiPaths.ApiV2Path, site), d, &respBody) if err != nil { return nil, err } @@ -76,17 +76,17 @@ func (c *Client) CreateAPGroup(ctx context.Context, site string, d *APGroup) (*A // func (c *Client) updateWLANGroup(ctx context.Context, site string, d *WLANGroup) (*WLANGroup, error) { // var respBody struct { -// Meta meta `json:"meta"` +// Meta Meta `json:"Meta"` // Data []WLANGroup `json:"data"` // } -// err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/wlangroup/%s", site, d.ID), d, &respBody) +// err := c.Put(ctx, 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{} +// return nil, NotFoundError // } // new := respBody.Data[0] diff --git a/unifi/broadcast_group.generated.go b/unifi/broadcast_group.generated.go index 643a818..863f224 100644 --- a/unifi/broadcast_group.generated.go +++ b/unifi/broadcast_group.generated.go @@ -47,11 +47,11 @@ func (dst *BroadcastGroup) UnmarshalJSON(b []byte) error { func (c *Client) listBroadcastGroup(ctx context.Context, site string) ([]BroadcastGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []BroadcastGroup `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/broadcastgroup", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/broadcastgroup", site), nil, &respBody) if err != nil { return nil, err } @@ -61,17 +61,17 @@ func (c *Client) listBroadcastGroup(ctx context.Context, site string) ([]Broadca func (c *Client) getBroadcastGroup(ctx context.Context, site, id string) (*BroadcastGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []BroadcastGroup `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/broadcastgroup/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/broadcastgroup/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -79,7 +79,7 @@ func (c *Client) getBroadcastGroup(ctx context.Context, site, id string) (*Broad } func (c *Client) deleteBroadcastGroup(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/broadcastgroup/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/broadcastgroup/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -88,17 +88,17 @@ func (c *Client) deleteBroadcastGroup(ctx context.Context, site, id string) erro func (c *Client) createBroadcastGroup(ctx context.Context, site string, d *BroadcastGroup) (*BroadcastGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []BroadcastGroup `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/broadcastgroup", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/broadcastgroup", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -108,17 +108,17 @@ func (c *Client) createBroadcastGroup(ctx context.Context, site string, d *Broad func (c *Client) updateBroadcastGroup(ctx context.Context, site string, d *BroadcastGroup) (*BroadcastGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []BroadcastGroup `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/broadcastgroup/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/broadcastgroup/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/channel_plan.generated.go b/unifi/channel_plan.generated.go index ccb2929..e743f1a 100644 --- a/unifi/channel_plan.generated.go +++ b/unifi/channel_plan.generated.go @@ -190,11 +190,11 @@ func (dst *ChannelPlanSiteBlacklistedChannels) UnmarshalJSON(b []byte) error { func (c *Client) listChannelPlan(ctx context.Context, site string) ([]ChannelPlan, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []ChannelPlan `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/channelplan", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/channelplan", site), nil, &respBody) if err != nil { return nil, err } @@ -204,17 +204,17 @@ func (c *Client) listChannelPlan(ctx context.Context, site string) ([]ChannelPla func (c *Client) getChannelPlan(ctx context.Context, site, id string) (*ChannelPlan, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []ChannelPlan `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/channelplan/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/channelplan/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -222,7 +222,7 @@ func (c *Client) getChannelPlan(ctx context.Context, site, id string) (*ChannelP } func (c *Client) deleteChannelPlan(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/channelplan/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/channelplan/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -231,17 +231,17 @@ func (c *Client) deleteChannelPlan(ctx context.Context, site, id string) error { func (c *Client) createChannelPlan(ctx context.Context, site string, d *ChannelPlan) (*ChannelPlan, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []ChannelPlan `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/channelplan", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/channelplan", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -251,17 +251,17 @@ func (c *Client) createChannelPlan(ctx context.Context, site string, d *ChannelP func (c *Client) updateChannelPlan(ctx context.Context, site string, d *ChannelPlan) (*ChannelPlan, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []ChannelPlan `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/channelplan/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/channelplan/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/codegen.go b/unifi/codegen.go index ea30101..d70f653 100644 --- a/unifi/codegen.go +++ b/unifi/codegen.go @@ -1,5 +1,5 @@ package unifi // This will generate the *.generated.go files in this package for the specified -// Unifi controller version. +// Client controller version. //go:generate go run ../codegen/ -version-base-dir=../codegen/ latest diff --git a/unifi/dashboard.generated.go b/unifi/dashboard.generated.go index f8270a6..01b6d3d 100644 --- a/unifi/dashboard.generated.go +++ b/unifi/dashboard.generated.go @@ -73,11 +73,11 @@ func (dst *DashboardModules) UnmarshalJSON(b []byte) error { func (c *Client) listDashboard(ctx context.Context, site string) ([]Dashboard, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Dashboard `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/dashboard", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/dashboard", site), nil, &respBody) if err != nil { return nil, err } @@ -87,17 +87,17 @@ func (c *Client) listDashboard(ctx context.Context, site string) ([]Dashboard, e func (c *Client) getDashboard(ctx context.Context, site, id string) (*Dashboard, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Dashboard `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/dashboard/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/dashboard/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -105,7 +105,7 @@ func (c *Client) getDashboard(ctx context.Context, site, id string) (*Dashboard, } func (c *Client) deleteDashboard(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/dashboard/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/dashboard/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -114,17 +114,17 @@ func (c *Client) deleteDashboard(ctx context.Context, site, id string) error { func (c *Client) createDashboard(ctx context.Context, site string, d *Dashboard) (*Dashboard, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Dashboard `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/dashboard", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/dashboard", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -134,17 +134,17 @@ func (c *Client) createDashboard(ctx context.Context, site string, d *Dashboard) func (c *Client) updateDashboard(ctx context.Context, site string, d *Dashboard) (*Dashboard, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Dashboard `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/dashboard/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/dashboard/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/device.generated.go b/unifi/device.generated.go index 3eb3c12..6610e70 100644 --- a/unifi/device.generated.go +++ b/unifi/device.generated.go @@ -586,11 +586,11 @@ func (dst *DeviceRpsPortTable) UnmarshalJSON(b []byte) error { func (c *Client) listDevice(ctx context.Context, site string) ([]Device, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Device `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/stat/device", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/stat/device", site), nil, &respBody) if err != nil { return nil, err } @@ -600,17 +600,17 @@ func (c *Client) listDevice(ctx context.Context, site string) ([]Device, error) func (c *Client) getDevice(ctx context.Context, site, id string) (*Device, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Device `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/stat/device/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/stat/device/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -618,7 +618,7 @@ func (c *Client) getDevice(ctx context.Context, site, id string) (*Device, error } func (c *Client) deleteDevice(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/device/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/device/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -627,17 +627,17 @@ func (c *Client) deleteDevice(ctx context.Context, site, id string) error { func (c *Client) createDevice(ctx context.Context, site string, d *Device) (*Device, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Device `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/device", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/device", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -647,17 +647,17 @@ func (c *Client) createDevice(ctx context.Context, site string, d *Device) (*Dev func (c *Client) updateDevice(ctx context.Context, site string, d *Device) (*Device, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Device `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/device/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/device/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/device.go b/unifi/device.go index d3ecfa6..50b2c15 100644 --- a/unifi/device.go +++ b/unifi/device.go @@ -55,7 +55,7 @@ func (c *Client) GetDevice(ctx context.Context, site, id string) (*Device, error } } - return nil, &NotFoundError{} + return nil, NotFoundError } func (c *Client) AdoptDevice(ctx context.Context, site, mac string) error { @@ -68,10 +68,10 @@ func (c *Client) AdoptDevice(ctx context.Context, site, mac string) error { } var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"Meta"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/cmd/devmgr", site), reqBody, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/cmd/devmgr", site), reqBody, &respBody) if err != nil { return err } @@ -89,11 +89,11 @@ func (c *Client) ForgetDevice(ctx context.Context, site, mac string) error { } var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"Meta"` Data []Device `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/cmd/sitemgr", site), reqBody, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/cmd/sitemgr", site), reqBody, &respBody) if err != nil { return err } diff --git a/unifi/dhcp_option.generated.go b/unifi/dhcp_option.generated.go index 329012e..218c581 100644 --- a/unifi/dhcp_option.generated.go +++ b/unifi/dhcp_option.generated.go @@ -53,11 +53,11 @@ func (dst *DHCPOption) UnmarshalJSON(b []byte) error { func (c *Client) listDHCPOption(ctx context.Context, site string) ([]DHCPOption, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []DHCPOption `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/dhcpoption", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/dhcpoption", site), nil, &respBody) if err != nil { return nil, err } @@ -67,17 +67,17 @@ func (c *Client) listDHCPOption(ctx context.Context, site string) ([]DHCPOption, func (c *Client) getDHCPOption(ctx context.Context, site, id string) (*DHCPOption, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []DHCPOption `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/dhcpoption/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/dhcpoption/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -85,7 +85,7 @@ func (c *Client) getDHCPOption(ctx context.Context, site, id string) (*DHCPOptio } func (c *Client) deleteDHCPOption(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/dhcpoption/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/dhcpoption/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -94,17 +94,17 @@ func (c *Client) deleteDHCPOption(ctx context.Context, site, id string) error { func (c *Client) createDHCPOption(ctx context.Context, site string, d *DHCPOption) (*DHCPOption, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []DHCPOption `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/dhcpoption", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/dhcpoption", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -114,17 +114,17 @@ func (c *Client) createDHCPOption(ctx context.Context, site string, d *DHCPOptio func (c *Client) updateDHCPOption(ctx context.Context, site string, d *DHCPOption) (*DHCPOption, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []DHCPOption `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/dhcpoption/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/dhcpoption/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/dns_record.go b/unifi/dns_record.go index 7d79a01..50c9408 100644 --- a/unifi/dns_record.go +++ b/unifi/dns_record.go @@ -1,4 +1,4 @@ -// Custom package for handling DNS records in Unifi Controller +// Custom package for handling DNS records in Client Controller package unifi @@ -54,7 +54,7 @@ func (dst *DNSRecord) UnmarshalJSON(b []byte) error { func (c *Client) ListDNSRecord(ctx context.Context, site string) ([]DNSRecord, error) { var respBody []DNSRecord - err := c.do(ctx, "GET", fmt.Sprintf("%s/site/%s/static-dns", c.apiV2Path, site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("%s/site/%s/static-dns", c.apiPaths.ApiV2Path, site), nil, &respBody) if err != nil { return nil, err } @@ -65,20 +65,20 @@ func (c *Client) ListDNSRecord(ctx context.Context, site string) ([]DNSRecord, e func (c *Client) GetDNSRecord(ctx context.Context, site, id string) (*DNSRecord, error) { var respBody DNSRecord - err := c.do(ctx, "GET", fmt.Sprintf("%s/site/%s/static-dns/%s", c.apiV2Path, site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("%s/site/%s/static-dns/%s", c.apiPaths.ApiV2Path, site, id), nil, &respBody) if err != nil { return nil, err } if respBody.ID == "" { - return nil, &NotFoundError{} + return nil, NotFoundError } return &respBody, nil } func (c *Client) DeleteDNSRecord(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("%s/site/%s/static-dns/%s", c.apiV2Path, site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("%s/site/%s/static-dns/%s", c.apiPaths.ApiV2Path, site, id), struct{}{}, nil) if err != nil { return err } @@ -87,7 +87,7 @@ func (c *Client) DeleteDNSRecord(ctx context.Context, site, id string) error { func (c *Client) CreateDNSRecord(ctx context.Context, site string, d *DNSRecord) (*DNSRecord, error) { var respBody DNSRecord - err := c.do(ctx, "POST", fmt.Sprintf("%s/site/%s/static-dns", c.apiV2Path, site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("%s/site/%s/static-dns", c.apiPaths.ApiV2Path, site), d, &respBody) if err != nil { return nil, err } @@ -97,13 +97,13 @@ func (c *Client) CreateDNSRecord(ctx context.Context, site string, d *DNSRecord) func (c *Client) UpdateDNSRecord(ctx context.Context, site string, d *DNSRecord) (*DNSRecord, error) { var respBody DNSRecord - err := c.do(ctx, "PUT", fmt.Sprintf("%s/site/%s/static-dns/%s", c.apiV2Path, site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("%s/site/%s/static-dns/%s", c.apiPaths.ApiV2Path, site, d.ID), d, &respBody) if err != nil { return nil, err } // if len(respBody) != nil { - // return nil, &NotFoundError{} + // return nil, NotFoundError // } return &respBody, nil diff --git a/unifi/dpi_app.generated.go b/unifi/dpi_app.generated.go index 518a4d6..024aefc 100644 --- a/unifi/dpi_app.generated.go +++ b/unifi/dpi_app.generated.go @@ -68,11 +68,11 @@ func (dst *DpiApp) UnmarshalJSON(b []byte) error { func (c *Client) listDpiApp(ctx context.Context, site string) ([]DpiApp, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []DpiApp `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/dpiapp", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/dpiapp", site), nil, &respBody) if err != nil { return nil, err } @@ -82,17 +82,17 @@ func (c *Client) listDpiApp(ctx context.Context, site string) ([]DpiApp, error) func (c *Client) getDpiApp(ctx context.Context, site, id string) (*DpiApp, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []DpiApp `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/dpiapp/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/dpiapp/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -100,7 +100,7 @@ func (c *Client) getDpiApp(ctx context.Context, site, id string) (*DpiApp, error } func (c *Client) deleteDpiApp(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/dpiapp/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/dpiapp/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -109,17 +109,17 @@ func (c *Client) deleteDpiApp(ctx context.Context, site, id string) error { func (c *Client) createDpiApp(ctx context.Context, site string, d *DpiApp) (*DpiApp, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []DpiApp `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/dpiapp", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/dpiapp", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -129,17 +129,17 @@ func (c *Client) createDpiApp(ctx context.Context, site string, d *DpiApp) (*Dpi func (c *Client) updateDpiApp(ctx context.Context, site string, d *DpiApp) (*DpiApp, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []DpiApp `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/dpiapp/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/dpiapp/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/dpi_group.generated.go b/unifi/dpi_group.generated.go index ee1e345..34acd28 100644 --- a/unifi/dpi_group.generated.go +++ b/unifi/dpi_group.generated.go @@ -48,11 +48,11 @@ func (dst *DpiGroup) UnmarshalJSON(b []byte) error { func (c *Client) listDpiGroup(ctx context.Context, site string) ([]DpiGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []DpiGroup `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/dpigroup", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/dpigroup", site), nil, &respBody) if err != nil { return nil, err } @@ -62,17 +62,17 @@ func (c *Client) listDpiGroup(ctx context.Context, site string) ([]DpiGroup, err func (c *Client) getDpiGroup(ctx context.Context, site, id string) (*DpiGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []DpiGroup `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/dpigroup/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/dpigroup/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -80,7 +80,7 @@ func (c *Client) getDpiGroup(ctx context.Context, site, id string) (*DpiGroup, e } func (c *Client) deleteDpiGroup(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/dpigroup/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/dpigroup/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -89,17 +89,17 @@ func (c *Client) deleteDpiGroup(ctx context.Context, site, id string) error { func (c *Client) createDpiGroup(ctx context.Context, site string, d *DpiGroup) (*DpiGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []DpiGroup `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/dpigroup", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/dpigroup", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -109,17 +109,17 @@ func (c *Client) createDpiGroup(ctx context.Context, site string, d *DpiGroup) ( func (c *Client) updateDpiGroup(ctx context.Context, site string, d *DpiGroup) (*DpiGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []DpiGroup `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/dpigroup/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/dpigroup/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/dynamic_dns.generated.go b/unifi/dynamic_dns.generated.go index 11dca3a..1b40fe1 100644 --- a/unifi/dynamic_dns.generated.go +++ b/unifi/dynamic_dns.generated.go @@ -53,11 +53,11 @@ func (dst *DynamicDNS) UnmarshalJSON(b []byte) error { func (c *Client) listDynamicDNS(ctx context.Context, site string) ([]DynamicDNS, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []DynamicDNS `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/dynamicdns", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/dynamicdns", site), nil, &respBody) if err != nil { return nil, err } @@ -67,17 +67,17 @@ func (c *Client) listDynamicDNS(ctx context.Context, site string) ([]DynamicDNS, func (c *Client) getDynamicDNS(ctx context.Context, site, id string) (*DynamicDNS, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []DynamicDNS `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/dynamicdns/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/dynamicdns/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -85,7 +85,7 @@ func (c *Client) getDynamicDNS(ctx context.Context, site, id string) (*DynamicDN } func (c *Client) deleteDynamicDNS(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/dynamicdns/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/dynamicdns/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -94,17 +94,17 @@ func (c *Client) deleteDynamicDNS(ctx context.Context, site, id string) error { func (c *Client) createDynamicDNS(ctx context.Context, site string, d *DynamicDNS) (*DynamicDNS, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []DynamicDNS `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/dynamicdns", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/dynamicdns", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -114,17 +114,17 @@ func (c *Client) createDynamicDNS(ctx context.Context, site string, d *DynamicDN func (c *Client) updateDynamicDNS(ctx context.Context, site string, d *DynamicDNS) (*DynamicDNS, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []DynamicDNS `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/dynamicdns/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/dynamicdns/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/firewall_group.generated.go b/unifi/firewall_group.generated.go index e3d24b5..1d950ae 100644 --- a/unifi/firewall_group.generated.go +++ b/unifi/firewall_group.generated.go @@ -48,11 +48,11 @@ func (dst *FirewallGroup) UnmarshalJSON(b []byte) error { func (c *Client) listFirewallGroup(ctx context.Context, site string) ([]FirewallGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []FirewallGroup `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/firewallgroup", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/firewallgroup", site), nil, &respBody) if err != nil { return nil, err } @@ -62,17 +62,17 @@ func (c *Client) listFirewallGroup(ctx context.Context, site string) ([]Firewall func (c *Client) getFirewallGroup(ctx context.Context, site, id string) (*FirewallGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []FirewallGroup `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/firewallgroup/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/firewallgroup/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -80,7 +80,7 @@ func (c *Client) getFirewallGroup(ctx context.Context, site, id string) (*Firewa } func (c *Client) deleteFirewallGroup(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/firewallgroup/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/firewallgroup/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -89,17 +89,17 @@ func (c *Client) deleteFirewallGroup(ctx context.Context, site, id string) error func (c *Client) createFirewallGroup(ctx context.Context, site string, d *FirewallGroup) (*FirewallGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []FirewallGroup `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/firewallgroup", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/firewallgroup", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -109,17 +109,17 @@ func (c *Client) createFirewallGroup(ctx context.Context, site string, d *Firewa func (c *Client) updateFirewallGroup(ctx context.Context, site string, d *FirewallGroup) (*FirewallGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []FirewallGroup `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/firewallgroup/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/firewallgroup/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/firewall_rule.generated.go b/unifi/firewall_rule.generated.go index 4e08e20..17f3064 100644 --- a/unifi/firewall_rule.generated.go +++ b/unifi/firewall_rule.generated.go @@ -78,11 +78,11 @@ func (dst *FirewallRule) UnmarshalJSON(b []byte) error { func (c *Client) listFirewallRule(ctx context.Context, site string) ([]FirewallRule, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []FirewallRule `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/firewallrule", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/firewallrule", site), nil, &respBody) if err != nil { return nil, err } @@ -92,17 +92,17 @@ func (c *Client) listFirewallRule(ctx context.Context, site string) ([]FirewallR func (c *Client) getFirewallRule(ctx context.Context, site, id string) (*FirewallRule, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []FirewallRule `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/firewallrule/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/firewallrule/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -110,7 +110,7 @@ func (c *Client) getFirewallRule(ctx context.Context, site, id string) (*Firewal } func (c *Client) deleteFirewallRule(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/firewallrule/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/firewallrule/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -119,17 +119,17 @@ func (c *Client) deleteFirewallRule(ctx context.Context, site, id string) error func (c *Client) createFirewallRule(ctx context.Context, site string, d *FirewallRule) (*FirewallRule, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []FirewallRule `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/firewallrule", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/firewallrule", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -139,17 +139,17 @@ func (c *Client) createFirewallRule(ctx context.Context, site string, d *Firewal func (c *Client) updateFirewallRule(ctx context.Context, site string, d *FirewallRule) (*FirewallRule, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []FirewallRule `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/firewallrule/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/firewallrule/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/firewall_rule.go b/unifi/firewall_rule.go index 8a1c929..a603440 100644 --- a/unifi/firewall_rule.go +++ b/unifi/firewall_rule.go @@ -40,7 +40,7 @@ func (c *Client) ReorderFirewallRules(ctx context.Context, site, ruleset string, Ruleset: ruleset, Rules: reorder, } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/cmd/firewall", site), reqBody, nil) + err := c.Post(ctx, fmt.Sprintf("s/%s/cmd/firewall", site), reqBody, nil) if err != nil { return err } diff --git a/unifi/heat_map.generated.go b/unifi/heat_map.generated.go index 431d998..292205c 100644 --- a/unifi/heat_map.generated.go +++ b/unifi/heat_map.generated.go @@ -49,11 +49,11 @@ func (dst *HeatMap) UnmarshalJSON(b []byte) error { func (c *Client) listHeatMap(ctx context.Context, site string) ([]HeatMap, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []HeatMap `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/heatmap", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/heatmap", site), nil, &respBody) if err != nil { return nil, err } @@ -63,17 +63,17 @@ func (c *Client) listHeatMap(ctx context.Context, site string) ([]HeatMap, error func (c *Client) getHeatMap(ctx context.Context, site, id string) (*HeatMap, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []HeatMap `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/heatmap/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/heatmap/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -81,7 +81,7 @@ func (c *Client) getHeatMap(ctx context.Context, site, id string) (*HeatMap, err } func (c *Client) deleteHeatMap(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/heatmap/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/heatmap/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -90,17 +90,17 @@ func (c *Client) deleteHeatMap(ctx context.Context, site, id string) error { func (c *Client) createHeatMap(ctx context.Context, site string, d *HeatMap) (*HeatMap, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []HeatMap `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/heatmap", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/heatmap", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -110,17 +110,17 @@ func (c *Client) createHeatMap(ctx context.Context, site string, d *HeatMap) (*H func (c *Client) updateHeatMap(ctx context.Context, site string, d *HeatMap) (*HeatMap, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []HeatMap `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/heatmap/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/heatmap/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/heat_map_point.generated.go b/unifi/heat_map_point.generated.go index cebaa0c..93c3acb 100644 --- a/unifi/heat_map_point.generated.go +++ b/unifi/heat_map_point.generated.go @@ -50,11 +50,11 @@ func (dst *HeatMapPoint) UnmarshalJSON(b []byte) error { func (c *Client) listHeatMapPoint(ctx context.Context, site string) ([]HeatMapPoint, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []HeatMapPoint `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/heatmappoint", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/heatmappoint", site), nil, &respBody) if err != nil { return nil, err } @@ -64,17 +64,17 @@ func (c *Client) listHeatMapPoint(ctx context.Context, site string) ([]HeatMapPo func (c *Client) getHeatMapPoint(ctx context.Context, site, id string) (*HeatMapPoint, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []HeatMapPoint `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/heatmappoint/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/heatmappoint/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -82,7 +82,7 @@ func (c *Client) getHeatMapPoint(ctx context.Context, site, id string) (*HeatMap } func (c *Client) deleteHeatMapPoint(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/heatmappoint/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/heatmappoint/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -91,17 +91,17 @@ func (c *Client) deleteHeatMapPoint(ctx context.Context, site, id string) error func (c *Client) createHeatMapPoint(ctx context.Context, site string, d *HeatMapPoint) (*HeatMapPoint, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []HeatMapPoint `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/heatmappoint", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/heatmappoint", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -111,17 +111,17 @@ func (c *Client) createHeatMapPoint(ctx context.Context, site string, d *HeatMap func (c *Client) updateHeatMapPoint(ctx context.Context, site string, d *HeatMapPoint) (*HeatMapPoint, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []HeatMapPoint `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/heatmappoint/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/heatmappoint/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/hotspot_2_conf.generated.go b/unifi/hotspot_2_conf.generated.go index 661583d..13b449e 100644 --- a/unifi/hotspot_2_conf.generated.go +++ b/unifi/hotspot_2_conf.generated.go @@ -429,11 +429,11 @@ func (dst *Hotspot2ConfVenueName) UnmarshalJSON(b []byte) error { func (c *Client) listHotspot2Conf(ctx context.Context, site string) ([]Hotspot2Conf, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Hotspot2Conf `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/hotspot2conf", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/hotspot2conf", site), nil, &respBody) if err != nil { return nil, err } @@ -443,17 +443,17 @@ func (c *Client) listHotspot2Conf(ctx context.Context, site string) ([]Hotspot2C func (c *Client) getHotspot2Conf(ctx context.Context, site, id string) (*Hotspot2Conf, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Hotspot2Conf `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/hotspot2conf/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/hotspot2conf/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -461,7 +461,7 @@ func (c *Client) getHotspot2Conf(ctx context.Context, site, id string) (*Hotspot } func (c *Client) deleteHotspot2Conf(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/hotspot2conf/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/hotspot2conf/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -470,17 +470,17 @@ func (c *Client) deleteHotspot2Conf(ctx context.Context, site, id string) error func (c *Client) createHotspot2Conf(ctx context.Context, site string, d *Hotspot2Conf) (*Hotspot2Conf, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Hotspot2Conf `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/hotspot2conf", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/hotspot2conf", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -490,17 +490,17 @@ func (c *Client) createHotspot2Conf(ctx context.Context, site string, d *Hotspot func (c *Client) updateHotspot2Conf(ctx context.Context, site string, d *Hotspot2Conf) (*Hotspot2Conf, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Hotspot2Conf `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/hotspot2conf/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/hotspot2conf/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/hotspot_op.generated.go b/unifi/hotspot_op.generated.go index 83cfa1f..ef881ce 100644 --- a/unifi/hotspot_op.generated.go +++ b/unifi/hotspot_op.generated.go @@ -48,11 +48,11 @@ func (dst *HotspotOp) UnmarshalJSON(b []byte) error { func (c *Client) listHotspotOp(ctx context.Context, site string) ([]HotspotOp, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []HotspotOp `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/hotspotop", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/hotspotop", site), nil, &respBody) if err != nil { return nil, err } @@ -62,17 +62,17 @@ func (c *Client) listHotspotOp(ctx context.Context, site string) ([]HotspotOp, e func (c *Client) getHotspotOp(ctx context.Context, site, id string) (*HotspotOp, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []HotspotOp `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/hotspotop/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/hotspotop/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -80,7 +80,7 @@ func (c *Client) getHotspotOp(ctx context.Context, site, id string) (*HotspotOp, } func (c *Client) deleteHotspotOp(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/hotspotop/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/hotspotop/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -89,17 +89,17 @@ func (c *Client) deleteHotspotOp(ctx context.Context, site, id string) error { func (c *Client) createHotspotOp(ctx context.Context, site string, d *HotspotOp) (*HotspotOp, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []HotspotOp `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/hotspotop", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/hotspotop", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -109,17 +109,17 @@ func (c *Client) createHotspotOp(ctx context.Context, site string, d *HotspotOp) func (c *Client) updateHotspotOp(ctx context.Context, site string, d *HotspotOp) (*HotspotOp, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []HotspotOp `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/hotspotop/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/hotspotop/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/hotspot_package.generated.go b/unifi/hotspot_package.generated.go index 59ec6a6..415d2e3 100644 --- a/unifi/hotspot_package.generated.go +++ b/unifi/hotspot_package.generated.go @@ -87,11 +87,11 @@ func (dst *HotspotPackage) UnmarshalJSON(b []byte) error { func (c *Client) listHotspotPackage(ctx context.Context, site string) ([]HotspotPackage, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []HotspotPackage `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/hotspotpackage", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/hotspotpackage", site), nil, &respBody) if err != nil { return nil, err } @@ -101,17 +101,17 @@ func (c *Client) listHotspotPackage(ctx context.Context, site string) ([]Hotspot func (c *Client) getHotspotPackage(ctx context.Context, site, id string) (*HotspotPackage, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []HotspotPackage `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/hotspotpackage/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/hotspotpackage/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -119,7 +119,7 @@ func (c *Client) getHotspotPackage(ctx context.Context, site, id string) (*Hotsp } func (c *Client) deleteHotspotPackage(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/hotspotpackage/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/hotspotpackage/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -128,17 +128,17 @@ func (c *Client) deleteHotspotPackage(ctx context.Context, site, id string) erro func (c *Client) createHotspotPackage(ctx context.Context, site string, d *HotspotPackage) (*HotspotPackage, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []HotspotPackage `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/hotspotpackage", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/hotspotpackage", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -148,17 +148,17 @@ func (c *Client) createHotspotPackage(ctx context.Context, site string, d *Hotsp func (c *Client) updateHotspotPackage(ctx context.Context, site string, d *HotspotPackage) (*HotspotPackage, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []HotspotPackage `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/hotspotpackage/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/hotspotpackage/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/map.generated.go b/unifi/map.generated.go index 329093a..cc7cf83 100644 --- a/unifi/map.generated.go +++ b/unifi/map.generated.go @@ -63,11 +63,11 @@ func (dst *Map) UnmarshalJSON(b []byte) error { func (c *Client) listMap(ctx context.Context, site string) ([]Map, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Map `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/map", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/map", site), nil, &respBody) if err != nil { return nil, err } @@ -77,17 +77,17 @@ func (c *Client) listMap(ctx context.Context, site string) ([]Map, error) { func (c *Client) getMap(ctx context.Context, site, id string) (*Map, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Map `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/map/%s", site, id), nil, &respBody) + err := c.Get(ctx, 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{} + return nil, NotFoundError } d := respBody.Data[0] @@ -95,7 +95,7 @@ func (c *Client) getMap(ctx context.Context, site, id string) (*Map, error) { } 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) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/map/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -104,17 +104,17 @@ func (c *Client) deleteMap(ctx context.Context, site, id string) error { func (c *Client) createMap(ctx context.Context, site string, d *Map) (*Map, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Map `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/map", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/map", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -124,17 +124,17 @@ func (c *Client) createMap(ctx context.Context, site string, d *Map) (*Map, erro func (c *Client) updateMap(ctx context.Context, site string, d *Map) (*Map, error) { var respBody struct { - Meta meta `json:"meta"` + 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) + err := c.Put(ctx, 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{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/media_file.generated.go b/unifi/media_file.generated.go index 0cf4117..4d5b95f 100644 --- a/unifi/media_file.generated.go +++ b/unifi/media_file.generated.go @@ -46,11 +46,11 @@ func (dst *MediaFile) UnmarshalJSON(b []byte) error { func (c *Client) listMediaFile(ctx context.Context, site string) ([]MediaFile, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []MediaFile `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/mediafile", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/mediafile", site), nil, &respBody) if err != nil { return nil, err } @@ -60,17 +60,17 @@ func (c *Client) listMediaFile(ctx context.Context, site string) ([]MediaFile, e func (c *Client) getMediaFile(ctx context.Context, site, id string) (*MediaFile, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []MediaFile `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/mediafile/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/mediafile/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -78,7 +78,7 @@ func (c *Client) getMediaFile(ctx context.Context, site, id string) (*MediaFile, } func (c *Client) deleteMediaFile(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/mediafile/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/mediafile/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -87,17 +87,17 @@ func (c *Client) deleteMediaFile(ctx context.Context, site, id string) error { func (c *Client) createMediaFile(ctx context.Context, site string, d *MediaFile) (*MediaFile, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []MediaFile `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/mediafile", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/mediafile", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -107,17 +107,17 @@ func (c *Client) createMediaFile(ctx context.Context, site string, d *MediaFile) func (c *Client) updateMediaFile(ctx context.Context, site string, d *MediaFile) (*MediaFile, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []MediaFile `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/mediafile/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/mediafile/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/network.generated.go b/unifi/network.generated.go index 8c5af25..ba6f19c 100644 --- a/unifi/network.generated.go +++ b/unifi/network.generated.go @@ -438,11 +438,11 @@ func (dst *NetworkWANProviderCapabilities) UnmarshalJSON(b []byte) error { func (c *Client) listNetwork(ctx context.Context, site string) ([]Network, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Network `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/networkconf", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/networkconf", site), nil, &respBody) if err != nil { return nil, err } @@ -452,17 +452,17 @@ func (c *Client) listNetwork(ctx context.Context, site string) ([]Network, error func (c *Client) getNetwork(ctx context.Context, site, id string) (*Network, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Network `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/networkconf/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/networkconf/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -470,7 +470,7 @@ func (c *Client) getNetwork(ctx context.Context, site, id string) (*Network, err } func (c *Client) deleteNetwork(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/networkconf/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/networkconf/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -479,17 +479,17 @@ func (c *Client) deleteNetwork(ctx context.Context, site, id string) error { func (c *Client) createNetwork(ctx context.Context, site string, d *Network) (*Network, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Network `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/networkconf", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/networkconf", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -499,17 +499,17 @@ func (c *Client) createNetwork(ctx context.Context, site string, d *Network) (*N func (c *Client) updateNetwork(ctx context.Context, site string, d *Network) (*Network, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Network `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/networkconf/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/networkconf/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/network.go b/unifi/network.go index d454738..196ecd1 100644 --- a/unifi/network.go +++ b/unifi/network.go @@ -27,7 +27,7 @@ func (dst *Network) MarshalJSON() ([]byte, error) { } func (c *Client) DeleteNetwork(ctx context.Context, site, id, name string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/networkconf/%s", site, id), struct { + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/networkconf/%s", site, id), struct { Name string `json:"name"` }{ Name: name, diff --git a/unifi/port_forward.generated.go b/unifi/port_forward.generated.go index f149b11..583eb7c 100644 --- a/unifi/port_forward.generated.go +++ b/unifi/port_forward.generated.go @@ -80,11 +80,11 @@ func (dst *PortForwardDestinationIPs) UnmarshalJSON(b []byte) error { func (c *Client) listPortForward(ctx context.Context, site string) ([]PortForward, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []PortForward `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/portforward", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/portforward", site), nil, &respBody) if err != nil { return nil, err } @@ -94,17 +94,17 @@ func (c *Client) listPortForward(ctx context.Context, site string) ([]PortForwar func (c *Client) getPortForward(ctx context.Context, site, id string) (*PortForward, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []PortForward `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/portforward/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/portforward/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -112,7 +112,7 @@ func (c *Client) getPortForward(ctx context.Context, site, id string) (*PortForw } func (c *Client) deletePortForward(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/portforward/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/portforward/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -121,17 +121,17 @@ func (c *Client) deletePortForward(ctx context.Context, site, id string) error { func (c *Client) createPortForward(ctx context.Context, site string, d *PortForward) (*PortForward, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []PortForward `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/portforward", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/portforward", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -141,17 +141,17 @@ func (c *Client) createPortForward(ctx context.Context, site string, d *PortForw func (c *Client) updatePortForward(ctx context.Context, site string, d *PortForward) (*PortForward, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []PortForward `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/portforward/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/portforward/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/port_profile.generated.go b/unifi/port_profile.generated.go index 7f083fe..4f9b148 100644 --- a/unifi/port_profile.generated.go +++ b/unifi/port_profile.generated.go @@ -222,11 +222,11 @@ func (dst *PortProfileQOSProfile) UnmarshalJSON(b []byte) error { func (c *Client) listPortProfile(ctx context.Context, site string) ([]PortProfile, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []PortProfile `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/portconf", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/portconf", site), nil, &respBody) if err != nil { return nil, err } @@ -236,17 +236,17 @@ func (c *Client) listPortProfile(ctx context.Context, site string) ([]PortProfil func (c *Client) getPortProfile(ctx context.Context, site, id string) (*PortProfile, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []PortProfile `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/portconf/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/portconf/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -254,7 +254,7 @@ func (c *Client) getPortProfile(ctx context.Context, site, id string) (*PortProf } func (c *Client) deletePortProfile(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/portconf/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/portconf/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -263,17 +263,17 @@ func (c *Client) deletePortProfile(ctx context.Context, site, id string) error { func (c *Client) createPortProfile(ctx context.Context, site string, d *PortProfile) (*PortProfile, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []PortProfile `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/portconf", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/portconf", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -283,17 +283,17 @@ func (c *Client) createPortProfile(ctx context.Context, site string, d *PortProf func (c *Client) updatePortProfile(ctx context.Context, site string, d *PortProfile) (*PortProfile, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []PortProfile `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/portconf/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/portconf/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/radius_profile.generated.go b/unifi/radius_profile.generated.go index e0138c4..2db85fd 100644 --- a/unifi/radius_profile.generated.go +++ b/unifi/radius_profile.generated.go @@ -136,11 +136,11 @@ func (dst *RADIUSProfileXCaCrts) UnmarshalJSON(b []byte) error { func (c *Client) listRADIUSProfile(ctx context.Context, site string) ([]RADIUSProfile, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []RADIUSProfile `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/radiusprofile", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/radiusprofile", site), nil, &respBody) if err != nil { return nil, err } @@ -150,17 +150,17 @@ func (c *Client) listRADIUSProfile(ctx context.Context, site string) ([]RADIUSPr func (c *Client) getRADIUSProfile(ctx context.Context, site, id string) (*RADIUSProfile, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []RADIUSProfile `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/radiusprofile/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/radiusprofile/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -168,7 +168,7 @@ func (c *Client) getRADIUSProfile(ctx context.Context, site, id string) (*RADIUS } func (c *Client) deleteRADIUSProfile(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/radiusprofile/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/radiusprofile/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -177,17 +177,17 @@ func (c *Client) deleteRADIUSProfile(ctx context.Context, site, id string) error func (c *Client) createRADIUSProfile(ctx context.Context, site string, d *RADIUSProfile) (*RADIUSProfile, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []RADIUSProfile `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/radiusprofile", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/radiusprofile", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -197,17 +197,17 @@ func (c *Client) createRADIUSProfile(ctx context.Context, site string, d *RADIUS func (c *Client) updateRADIUSProfile(ctx context.Context, site string, d *RADIUSProfile) (*RADIUSProfile, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []RADIUSProfile `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/radiusprofile/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/radiusprofile/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/routing.generated.go b/unifi/routing.generated.go index b82313a..8fe7cb9 100644 --- a/unifi/routing.generated.go +++ b/unifi/routing.generated.go @@ -58,11 +58,11 @@ func (dst *Routing) UnmarshalJSON(b []byte) error { func (c *Client) listRouting(ctx context.Context, site string) ([]Routing, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Routing `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/routing", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/routing", site), nil, &respBody) if err != nil { return nil, err } @@ -72,17 +72,17 @@ func (c *Client) listRouting(ctx context.Context, site string) ([]Routing, error func (c *Client) getRouting(ctx context.Context, site, id string) (*Routing, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Routing `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/routing/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/routing/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -90,7 +90,7 @@ func (c *Client) getRouting(ctx context.Context, site, id string) (*Routing, err } func (c *Client) deleteRouting(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/routing/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/routing/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -99,17 +99,17 @@ func (c *Client) deleteRouting(ctx context.Context, site, id string) error { func (c *Client) createRouting(ctx context.Context, site string, d *Routing) (*Routing, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Routing `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/routing", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/routing", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -119,17 +119,17 @@ func (c *Client) createRouting(ctx context.Context, site string, d *Routing) (*R func (c *Client) updateRouting(ctx context.Context, site string, d *Routing) (*Routing, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Routing `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/routing/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/routing/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/schedule_task.generated.go b/unifi/schedule_task.generated.go index e9230a3..e4c6147 100644 --- a/unifi/schedule_task.generated.go +++ b/unifi/schedule_task.generated.go @@ -70,11 +70,11 @@ func (dst *ScheduleTaskUpgradeTargets) UnmarshalJSON(b []byte) error { func (c *Client) listScheduleTask(ctx context.Context, site string) ([]ScheduleTask, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []ScheduleTask `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/scheduletask", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/scheduletask", site), nil, &respBody) if err != nil { return nil, err } @@ -84,17 +84,17 @@ func (c *Client) listScheduleTask(ctx context.Context, site string) ([]ScheduleT func (c *Client) getScheduleTask(ctx context.Context, site, id string) (*ScheduleTask, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []ScheduleTask `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/scheduletask/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/scheduletask/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -102,7 +102,7 @@ func (c *Client) getScheduleTask(ctx context.Context, site, id string) (*Schedul } func (c *Client) deleteScheduleTask(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/scheduletask/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/scheduletask/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -111,17 +111,17 @@ func (c *Client) deleteScheduleTask(ctx context.Context, site, id string) error func (c *Client) createScheduleTask(ctx context.Context, site string, d *ScheduleTask) (*ScheduleTask, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []ScheduleTask `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/scheduletask", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/scheduletask", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -131,17 +131,17 @@ func (c *Client) createScheduleTask(ctx context.Context, site string, d *Schedul func (c *Client) updateScheduleTask(ctx context.Context, site string, d *ScheduleTask) (*ScheduleTask, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []ScheduleTask `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/scheduletask/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/scheduletask/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting.go b/unifi/setting.go index 0c89e1f..33ecbb7 100644 --- a/unifi/setting.go +++ b/unifi/setting.go @@ -81,11 +81,11 @@ func (s *Setting) newFields() (interface{}, error) { func (c *Client) GetSetting(ctx context.Context, site, key string) (*Setting, interface{}, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"Meta"` Data []json.RawMessage `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting", site), nil, &respBody) if err != nil { return nil, nil, err } @@ -103,7 +103,7 @@ func (c *Client) GetSetting(ctx context.Context, site, key string) (*Setting, in } } if setting == nil { - return nil, nil, &NotFoundError{} + return nil, nil, NotFoundError } fields, err := setting.newFields() diff --git a/unifi/setting_auto_speedtest.generated.go b/unifi/setting_auto_speedtest.generated.go index f5bf8db..3c495d3 100644 --- a/unifi/setting_auto_speedtest.generated.go +++ b/unifi/setting_auto_speedtest.generated.go @@ -49,17 +49,17 @@ func (dst *SettingAutoSpeedtest) UnmarshalJSON(b []byte) error { func (c *Client) getSettingAutoSpeedtest(ctx context.Context, site string) (*SettingAutoSpeedtest, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingAutoSpeedtest `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/auto_speedtest", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/auto_speedtest", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -68,18 +68,18 @@ func (c *Client) getSettingAutoSpeedtest(ctx context.Context, site string) (*Set func (c *Client) updateSettingAutoSpeedtest(ctx context.Context, site string, d *SettingAutoSpeedtest) (*SettingAutoSpeedtest, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingAutoSpeedtest `json:"data"` } d.Key = "auto_speedtest" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/auto_speedtest", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/auto_speedtest", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_baresip.generated.go b/unifi/setting_baresip.generated.go index 2b81b21..62566e4 100644 --- a/unifi/setting_baresip.generated.go +++ b/unifi/setting_baresip.generated.go @@ -51,17 +51,17 @@ func (dst *SettingBaresip) UnmarshalJSON(b []byte) error { func (c *Client) getSettingBaresip(ctx context.Context, site string) (*SettingBaresip, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingBaresip `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/baresip", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/baresip", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -70,18 +70,18 @@ func (c *Client) getSettingBaresip(ctx context.Context, site string) (*SettingBa func (c *Client) updateSettingBaresip(ctx context.Context, site string, d *SettingBaresip) (*SettingBaresip, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingBaresip `json:"data"` } d.Key = "baresip" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/baresip", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/baresip", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_broadcast.generated.go b/unifi/setting_broadcast.generated.go index beed669..33ff65f 100644 --- a/unifi/setting_broadcast.generated.go +++ b/unifi/setting_broadcast.generated.go @@ -53,17 +53,17 @@ func (dst *SettingBroadcast) UnmarshalJSON(b []byte) error { func (c *Client) getSettingBroadcast(ctx context.Context, site string) (*SettingBroadcast, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingBroadcast `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/broadcast", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/broadcast", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -72,18 +72,18 @@ func (c *Client) getSettingBroadcast(ctx context.Context, site string) (*Setting func (c *Client) updateSettingBroadcast(ctx context.Context, site string, d *SettingBroadcast) (*SettingBroadcast, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingBroadcast `json:"data"` } d.Key = "broadcast" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/broadcast", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/broadcast", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_connectivity.generated.go b/unifi/setting_connectivity.generated.go index 1a3ef05..ada9569 100644 --- a/unifi/setting_connectivity.generated.go +++ b/unifi/setting_connectivity.generated.go @@ -53,17 +53,17 @@ func (dst *SettingConnectivity) UnmarshalJSON(b []byte) error { func (c *Client) getSettingConnectivity(ctx context.Context, site string) (*SettingConnectivity, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingConnectivity `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/connectivity", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/connectivity", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -72,18 +72,18 @@ func (c *Client) getSettingConnectivity(ctx context.Context, site string) (*Sett func (c *Client) updateSettingConnectivity(ctx context.Context, site string, d *SettingConnectivity) (*SettingConnectivity, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingConnectivity `json:"data"` } d.Key = "connectivity" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/connectivity", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/connectivity", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_country.generated.go b/unifi/setting_country.generated.go index 765f6ff..f6ba59c 100644 --- a/unifi/setting_country.generated.go +++ b/unifi/setting_country.generated.go @@ -51,17 +51,17 @@ func (dst *SettingCountry) UnmarshalJSON(b []byte) error { func (c *Client) getSettingCountry(ctx context.Context, site string) (*SettingCountry, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingCountry `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/country", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/country", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -70,18 +70,18 @@ func (c *Client) getSettingCountry(ctx context.Context, site string) (*SettingCo func (c *Client) updateSettingCountry(ctx context.Context, site string, d *SettingCountry) (*SettingCountry, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingCountry `json:"data"` } d.Key = "country" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/country", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/country", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_dashboard.generated.go b/unifi/setting_dashboard.generated.go index 223a78f..7d65dfe 100644 --- a/unifi/setting_dashboard.generated.go +++ b/unifi/setting_dashboard.generated.go @@ -70,17 +70,17 @@ func (dst *SettingDashboardWidgets) UnmarshalJSON(b []byte) error { func (c *Client) getSettingDashboard(ctx context.Context, site string) (*SettingDashboard, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingDashboard `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/dashboard", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/dashboard", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -89,18 +89,18 @@ func (c *Client) getSettingDashboard(ctx context.Context, site string) (*Setting func (c *Client) updateSettingDashboard(ctx context.Context, site string, d *SettingDashboard) (*SettingDashboard, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingDashboard `json:"data"` } d.Key = "dashboard" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/dashboard", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/dashboard", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_doh.generated.go b/unifi/setting_doh.generated.go index 1b60db8..5797a1c 100644 --- a/unifi/setting_doh.generated.go +++ b/unifi/setting_doh.generated.go @@ -72,17 +72,17 @@ func (dst *SettingDohCustomServers) UnmarshalJSON(b []byte) error { func (c *Client) getSettingDoh(ctx context.Context, site string) (*SettingDoh, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingDoh `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/doh", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/doh", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -91,18 +91,18 @@ func (c *Client) getSettingDoh(ctx context.Context, site string) (*SettingDoh, e func (c *Client) updateSettingDoh(ctx context.Context, site string, d *SettingDoh) (*SettingDoh, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingDoh `json:"data"` } d.Key = "doh" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/doh", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/doh", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_dpi.generated.go b/unifi/setting_dpi.generated.go index 1493c57..2506657 100644 --- a/unifi/setting_dpi.generated.go +++ b/unifi/setting_dpi.generated.go @@ -49,17 +49,17 @@ func (dst *SettingDpi) UnmarshalJSON(b []byte) error { func (c *Client) getSettingDpi(ctx context.Context, site string) (*SettingDpi, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingDpi `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/dpi", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/dpi", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -68,18 +68,18 @@ func (c *Client) getSettingDpi(ctx context.Context, site string) (*SettingDpi, e func (c *Client) updateSettingDpi(ctx context.Context, site string, d *SettingDpi) (*SettingDpi, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingDpi `json:"data"` } d.Key = "dpi" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/dpi", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/dpi", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_element_adopt.generated.go b/unifi/setting_element_adopt.generated.go index ce67adc..a703a06 100644 --- a/unifi/setting_element_adopt.generated.go +++ b/unifi/setting_element_adopt.generated.go @@ -50,17 +50,17 @@ func (dst *SettingElementAdopt) UnmarshalJSON(b []byte) error { func (c *Client) getSettingElementAdopt(ctx context.Context, site string) (*SettingElementAdopt, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingElementAdopt `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/element_adopt", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/element_adopt", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -69,18 +69,18 @@ func (c *Client) getSettingElementAdopt(ctx context.Context, site string) (*Sett func (c *Client) updateSettingElementAdopt(ctx context.Context, site string, d *SettingElementAdopt) (*SettingElementAdopt, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingElementAdopt `json:"data"` } d.Key = "element_adopt" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/element_adopt", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/element_adopt", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_ether_lighting.generated.go b/unifi/setting_ether_lighting.generated.go index e2acaf4..8788495 100644 --- a/unifi/setting_ether_lighting.generated.go +++ b/unifi/setting_ether_lighting.generated.go @@ -91,17 +91,17 @@ func (dst *SettingEtherLightingSpeedOverrides) UnmarshalJSON(b []byte) error { func (c *Client) getSettingEtherLighting(ctx context.Context, site string) (*SettingEtherLighting, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingEtherLighting `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/ether_lighting", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/ether_lighting", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -110,18 +110,18 @@ func (c *Client) getSettingEtherLighting(ctx context.Context, site string) (*Set func (c *Client) updateSettingEtherLighting(ctx context.Context, site string, d *SettingEtherLighting) (*SettingEtherLighting, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingEtherLighting `json:"data"` } d.Key = "ether_lighting" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/ether_lighting", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/ether_lighting", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_evaluation_score.generated.go b/unifi/setting_evaluation_score.generated.go index 61bb8ae..9f9ee62 100644 --- a/unifi/setting_evaluation_score.generated.go +++ b/unifi/setting_evaluation_score.generated.go @@ -48,17 +48,17 @@ func (dst *SettingEvaluationScore) UnmarshalJSON(b []byte) error { func (c *Client) getSettingEvaluationScore(ctx context.Context, site string) (*SettingEvaluationScore, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingEvaluationScore `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/evaluation_score", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/evaluation_score", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -67,18 +67,18 @@ func (c *Client) getSettingEvaluationScore(ctx context.Context, site string) (*S func (c *Client) updateSettingEvaluationScore(ctx context.Context, site string, d *SettingEvaluationScore) (*SettingEvaluationScore, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingEvaluationScore `json:"data"` } d.Key = "evaluation_score" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/evaluation_score", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/evaluation_score", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_global_ap.generated.go b/unifi/setting_global_ap.generated.go index 730ce13..6d54dc0 100644 --- a/unifi/setting_global_ap.generated.go +++ b/unifi/setting_global_ap.generated.go @@ -70,17 +70,17 @@ func (dst *SettingGlobalAp) UnmarshalJSON(b []byte) error { func (c *Client) getSettingGlobalAp(ctx context.Context, site string) (*SettingGlobalAp, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingGlobalAp `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/global_ap", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/global_ap", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -89,18 +89,18 @@ func (c *Client) getSettingGlobalAp(ctx context.Context, site string) (*SettingG func (c *Client) updateSettingGlobalAp(ctx context.Context, site string, d *SettingGlobalAp) (*SettingGlobalAp, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingGlobalAp `json:"data"` } d.Key = "global_ap" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/global_ap", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/global_ap", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_global_nat.generated.go b/unifi/setting_global_nat.generated.go index 21a263c..317476d 100644 --- a/unifi/setting_global_nat.generated.go +++ b/unifi/setting_global_nat.generated.go @@ -49,17 +49,17 @@ func (dst *SettingGlobalNat) UnmarshalJSON(b []byte) error { func (c *Client) getSettingGlobalNat(ctx context.Context, site string) (*SettingGlobalNat, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingGlobalNat `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/global_nat", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/global_nat", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -68,18 +68,18 @@ func (c *Client) getSettingGlobalNat(ctx context.Context, site string) (*Setting func (c *Client) updateSettingGlobalNat(ctx context.Context, site string, d *SettingGlobalNat) (*SettingGlobalNat, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingGlobalNat `json:"data"` } d.Key = "global_nat" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/global_nat", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/global_nat", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_global_switch.generated.go b/unifi/setting_global_switch.generated.go index 96f98b3..9990415 100644 --- a/unifi/setting_global_switch.generated.go +++ b/unifi/setting_global_switch.generated.go @@ -78,17 +78,17 @@ func (dst *SettingGlobalSwitchAclL3Isolation) UnmarshalJSON(b []byte) error { func (c *Client) getSettingGlobalSwitch(ctx context.Context, site string) (*SettingGlobalSwitch, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingGlobalSwitch `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/global_switch", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/global_switch", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -97,18 +97,18 @@ func (c *Client) getSettingGlobalSwitch(ctx context.Context, site string) (*Sett func (c *Client) updateSettingGlobalSwitch(ctx context.Context, site string, d *SettingGlobalSwitch) (*SettingGlobalSwitch, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingGlobalSwitch `json:"data"` } d.Key = "global_switch" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/global_switch", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/global_switch", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_guest_access.generated.go b/unifi/setting_guest_access.generated.go index 3198ce3..5459c95 100644 --- a/unifi/setting_guest_access.generated.go +++ b/unifi/setting_guest_access.generated.go @@ -157,17 +157,17 @@ func (dst *SettingGuestAccess) UnmarshalJSON(b []byte) error { func (c *Client) getSettingGuestAccess(ctx context.Context, site string) (*SettingGuestAccess, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingGuestAccess `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/guest_access", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/guest_access", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -176,18 +176,18 @@ func (c *Client) getSettingGuestAccess(ctx context.Context, site string) (*Setti func (c *Client) updateSettingGuestAccess(ctx context.Context, site string, d *SettingGuestAccess) (*SettingGuestAccess, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingGuestAccess `json:"data"` } d.Key = "guest_access" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/guest_access", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/guest_access", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_ips.generated.go b/unifi/setting_ips.generated.go index 906d645..95d0e19 100644 --- a/unifi/setting_ips.generated.go +++ b/unifi/setting_ips.generated.go @@ -224,17 +224,17 @@ func (dst *SettingIpsWhitelist) UnmarshalJSON(b []byte) error { func (c *Client) getSettingIps(ctx context.Context, site string) (*SettingIps, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingIps `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/ips", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/ips", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -243,18 +243,18 @@ func (c *Client) getSettingIps(ctx context.Context, site string) (*SettingIps, e func (c *Client) updateSettingIps(ctx context.Context, site string, d *SettingIps) (*SettingIps, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingIps `json:"data"` } d.Key = "ips" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/ips", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/ips", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_lcm.generated.go b/unifi/setting_lcm.generated.go index f2bc404..514a2cc 100644 --- a/unifi/setting_lcm.generated.go +++ b/unifi/setting_lcm.generated.go @@ -57,17 +57,17 @@ func (dst *SettingLcm) UnmarshalJSON(b []byte) error { func (c *Client) getSettingLcm(ctx context.Context, site string) (*SettingLcm, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingLcm `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/lcm", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/lcm", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -76,18 +76,18 @@ func (c *Client) getSettingLcm(ctx context.Context, site string) (*SettingLcm, e func (c *Client) updateSettingLcm(ctx context.Context, site string, d *SettingLcm) (*SettingLcm, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingLcm `json:"data"` } d.Key = "lcm" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/lcm", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/lcm", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_locale.generated.go b/unifi/setting_locale.generated.go index e026498..3e88abf 100644 --- a/unifi/setting_locale.generated.go +++ b/unifi/setting_locale.generated.go @@ -48,17 +48,17 @@ func (dst *SettingLocale) UnmarshalJSON(b []byte) error { func (c *Client) getSettingLocale(ctx context.Context, site string) (*SettingLocale, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingLocale `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/locale", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/locale", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -67,18 +67,18 @@ func (c *Client) getSettingLocale(ctx context.Context, site string) (*SettingLoc func (c *Client) updateSettingLocale(ctx context.Context, site string, d *SettingLocale) (*SettingLocale, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingLocale `json:"data"` } d.Key = "locale" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/locale", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/locale", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_magic_site_to_site_vpn.generated.go b/unifi/setting_magic_site_to_site_vpn.generated.go index 4a744da..57982a6 100644 --- a/unifi/setting_magic_site_to_site_vpn.generated.go +++ b/unifi/setting_magic_site_to_site_vpn.generated.go @@ -48,17 +48,17 @@ func (dst *SettingMagicSiteToSiteVpn) UnmarshalJSON(b []byte) error { func (c *Client) getSettingMagicSiteToSiteVpn(ctx context.Context, site string) (*SettingMagicSiteToSiteVpn, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingMagicSiteToSiteVpn `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/magic_site_to_site_vpn", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/magic_site_to_site_vpn", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -67,18 +67,18 @@ func (c *Client) getSettingMagicSiteToSiteVpn(ctx context.Context, site string) func (c *Client) updateSettingMagicSiteToSiteVpn(ctx context.Context, site string, d *SettingMagicSiteToSiteVpn) (*SettingMagicSiteToSiteVpn, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingMagicSiteToSiteVpn `json:"data"` } d.Key = "magic_site_to_site_vpn" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/magic_site_to_site_vpn", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/magic_site_to_site_vpn", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_mgmt.generated.go b/unifi/setting_mgmt.generated.go index 7d4329d..5db7e66 100644 --- a/unifi/setting_mgmt.generated.go +++ b/unifi/setting_mgmt.generated.go @@ -95,17 +95,17 @@ func (dst *SettingMgmtXSshKeys) UnmarshalJSON(b []byte) error { func (c *Client) getSettingMgmt(ctx context.Context, site string) (*SettingMgmt, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingMgmt `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/mgmt", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/mgmt", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -114,18 +114,18 @@ func (c *Client) getSettingMgmt(ctx context.Context, site string) (*SettingMgmt, func (c *Client) updateSettingMgmt(ctx context.Context, site string, d *SettingMgmt) (*SettingMgmt, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingMgmt `json:"data"` } d.Key = "mgmt" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/mgmt", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/mgmt", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_netflow.generated.go b/unifi/setting_netflow.generated.go index f9546c8..4bab8dc 100644 --- a/unifi/setting_netflow.generated.go +++ b/unifi/setting_netflow.generated.go @@ -71,17 +71,17 @@ func (dst *SettingNetflow) UnmarshalJSON(b []byte) error { func (c *Client) getSettingNetflow(ctx context.Context, site string) (*SettingNetflow, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingNetflow `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/netflow", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/netflow", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -90,18 +90,18 @@ func (c *Client) getSettingNetflow(ctx context.Context, site string) (*SettingNe func (c *Client) updateSettingNetflow(ctx context.Context, site string, d *SettingNetflow) (*SettingNetflow, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingNetflow `json:"data"` } d.Key = "netflow" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/netflow", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/netflow", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_network_optimization.generated.go b/unifi/setting_network_optimization.generated.go index 7b28ce7..51c8239 100644 --- a/unifi/setting_network_optimization.generated.go +++ b/unifi/setting_network_optimization.generated.go @@ -48,17 +48,17 @@ func (dst *SettingNetworkOptimization) UnmarshalJSON(b []byte) error { func (c *Client) getSettingNetworkOptimization(ctx context.Context, site string) (*SettingNetworkOptimization, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingNetworkOptimization `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/network_optimization", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/network_optimization", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -67,18 +67,18 @@ func (c *Client) getSettingNetworkOptimization(ctx context.Context, site string) func (c *Client) updateSettingNetworkOptimization(ctx context.Context, site string, d *SettingNetworkOptimization) (*SettingNetworkOptimization, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingNetworkOptimization `json:"data"` } d.Key = "network_optimization" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/network_optimization", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/network_optimization", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_ntp.generated.go b/unifi/setting_ntp.generated.go index d56caf3..6dd8b51 100644 --- a/unifi/setting_ntp.generated.go +++ b/unifi/setting_ntp.generated.go @@ -52,17 +52,17 @@ func (dst *SettingNtp) UnmarshalJSON(b []byte) error { func (c *Client) getSettingNtp(ctx context.Context, site string) (*SettingNtp, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingNtp `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/ntp", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/ntp", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -71,18 +71,18 @@ func (c *Client) getSettingNtp(ctx context.Context, site string) (*SettingNtp, e func (c *Client) updateSettingNtp(ctx context.Context, site string, d *SettingNtp) (*SettingNtp, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingNtp `json:"data"` } d.Key = "ntp" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/ntp", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/ntp", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_porta.generated.go b/unifi/setting_porta.generated.go index 294df7b..e4021f0 100644 --- a/unifi/setting_porta.generated.go +++ b/unifi/setting_porta.generated.go @@ -48,17 +48,17 @@ func (dst *SettingPorta) UnmarshalJSON(b []byte) error { func (c *Client) getSettingPorta(ctx context.Context, site string) (*SettingPorta, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingPorta `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/porta", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/porta", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -67,18 +67,18 @@ func (c *Client) getSettingPorta(ctx context.Context, site string) (*SettingPort func (c *Client) updateSettingPorta(ctx context.Context, site string, d *SettingPorta) (*SettingPorta, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingPorta `json:"data"` } d.Key = "porta" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/porta", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/porta", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_provider_capabilities.generated.go b/unifi/setting_provider_capabilities.generated.go index 3eb0188..95f4290 100644 --- a/unifi/setting_provider_capabilities.generated.go +++ b/unifi/setting_provider_capabilities.generated.go @@ -55,17 +55,17 @@ func (dst *SettingProviderCapabilities) UnmarshalJSON(b []byte) error { func (c *Client) getSettingProviderCapabilities(ctx context.Context, site string) (*SettingProviderCapabilities, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"Meta"` Data []SettingProviderCapabilities `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/provider_capabilities", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/provider_capabilities", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -74,18 +74,18 @@ func (c *Client) getSettingProviderCapabilities(ctx context.Context, site string func (c *Client) updateSettingProviderCapabilities(ctx context.Context, site string, d *SettingProviderCapabilities) (*SettingProviderCapabilities, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"Meta"` Data []SettingProviderCapabilities `json:"data"` } d.Key = "provider_capabilities" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/provider_capabilities", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/provider_capabilities", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_radio_ai.generated.go b/unifi/setting_radio_ai.generated.go index 7e1b7dc..e3ee60f 100644 --- a/unifi/setting_radio_ai.generated.go +++ b/unifi/setting_radio_ai.generated.go @@ -115,17 +115,17 @@ func (dst *SettingRadioAiChannelsBlacklist) UnmarshalJSON(b []byte) error { func (c *Client) getSettingRadioAi(ctx context.Context, site string) (*SettingRadioAi, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingRadioAi `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/radio_ai", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/radio_ai", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -134,18 +134,18 @@ func (c *Client) getSettingRadioAi(ctx context.Context, site string) (*SettingRa func (c *Client) updateSettingRadioAi(ctx context.Context, site string, d *SettingRadioAi) (*SettingRadioAi, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingRadioAi `json:"data"` } d.Key = "radio_ai" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/radio_ai", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/radio_ai", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_radius.generated.go b/unifi/setting_radius.generated.go index 6b4c753..605346b 100644 --- a/unifi/setting_radius.generated.go +++ b/unifi/setting_radius.generated.go @@ -62,17 +62,17 @@ func (dst *SettingRadius) UnmarshalJSON(b []byte) error { func (c *Client) getSettingRadius(ctx context.Context, site string) (*SettingRadius, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingRadius `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/radius", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/radius", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -81,18 +81,18 @@ func (c *Client) getSettingRadius(ctx context.Context, site string) (*SettingRad func (c *Client) updateSettingRadius(ctx context.Context, site string, d *SettingRadius) (*SettingRadius, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingRadius `json:"data"` } d.Key = "radius" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/radius", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/radius", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_rsyslogd.generated.go b/unifi/setting_rsyslogd.generated.go index 307609d..5b4c64b 100644 --- a/unifi/setting_rsyslogd.generated.go +++ b/unifi/setting_rsyslogd.generated.go @@ -63,17 +63,17 @@ func (dst *SettingRsyslogd) UnmarshalJSON(b []byte) error { func (c *Client) getSettingRsyslogd(ctx context.Context, site string) (*SettingRsyslogd, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingRsyslogd `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/rsyslogd", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/rsyslogd", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -82,18 +82,18 @@ func (c *Client) getSettingRsyslogd(ctx context.Context, site string) (*SettingR func (c *Client) updateSettingRsyslogd(ctx context.Context, site string, d *SettingRsyslogd) (*SettingRsyslogd, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingRsyslogd `json:"data"` } d.Key = "rsyslogd" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/rsyslogd", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/rsyslogd", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_snmp.generated.go b/unifi/setting_snmp.generated.go index f251b20..1e369ce 100644 --- a/unifi/setting_snmp.generated.go +++ b/unifi/setting_snmp.generated.go @@ -52,17 +52,17 @@ func (dst *SettingSnmp) UnmarshalJSON(b []byte) error { func (c *Client) getSettingSnmp(ctx context.Context, site string) (*SettingSnmp, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSnmp `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/snmp", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/snmp", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -71,18 +71,18 @@ func (c *Client) getSettingSnmp(ctx context.Context, site string) (*SettingSnmp, func (c *Client) updateSettingSnmp(ctx context.Context, site string, d *SettingSnmp) (*SettingSnmp, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSnmp `json:"data"` } d.Key = "snmp" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/snmp", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/snmp", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_ssl_inspection.generated.go b/unifi/setting_ssl_inspection.generated.go index 76c042a..7dc6cdc 100644 --- a/unifi/setting_ssl_inspection.generated.go +++ b/unifi/setting_ssl_inspection.generated.go @@ -48,17 +48,17 @@ func (dst *SettingSslInspection) UnmarshalJSON(b []byte) error { func (c *Client) getSettingSslInspection(ctx context.Context, site string) (*SettingSslInspection, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSslInspection `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/ssl_inspection", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/ssl_inspection", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -67,18 +67,18 @@ func (c *Client) getSettingSslInspection(ctx context.Context, site string) (*Set func (c *Client) updateSettingSslInspection(ctx context.Context, site string, d *SettingSslInspection) (*SettingSslInspection, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSslInspection `json:"data"` } d.Key = "ssl_inspection" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/ssl_inspection", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/ssl_inspection", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_super_cloudaccess.generated.go b/unifi/setting_super_cloudaccess.generated.go index 7a7872f..1eb284c 100644 --- a/unifi/setting_super_cloudaccess.generated.go +++ b/unifi/setting_super_cloudaccess.generated.go @@ -54,17 +54,17 @@ func (dst *SettingSuperCloudaccess) UnmarshalJSON(b []byte) error { func (c *Client) getSettingSuperCloudaccess(ctx context.Context, site string) (*SettingSuperCloudaccess, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSuperCloudaccess `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/super_cloudaccess", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/super_cloudaccess", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -73,18 +73,18 @@ func (c *Client) getSettingSuperCloudaccess(ctx context.Context, site string) (* func (c *Client) updateSettingSuperCloudaccess(ctx context.Context, site string, d *SettingSuperCloudaccess) (*SettingSuperCloudaccess, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSuperCloudaccess `json:"data"` } d.Key = "super_cloudaccess" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/super_cloudaccess", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/super_cloudaccess", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_super_events.generated.go b/unifi/setting_super_events.generated.go index 0982803..48bd4ca 100644 --- a/unifi/setting_super_events.generated.go +++ b/unifi/setting_super_events.generated.go @@ -48,17 +48,17 @@ func (dst *SettingSuperEvents) UnmarshalJSON(b []byte) error { func (c *Client) getSettingSuperEvents(ctx context.Context, site string) (*SettingSuperEvents, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSuperEvents `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/super_events", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/super_events", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -67,18 +67,18 @@ func (c *Client) getSettingSuperEvents(ctx context.Context, site string) (*Setti func (c *Client) updateSettingSuperEvents(ctx context.Context, site string, d *SettingSuperEvents) (*SettingSuperEvents, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSuperEvents `json:"data"` } d.Key = "super_events" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/super_events", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/super_events", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_super_fwupdate.generated.go b/unifi/setting_super_fwupdate.generated.go index 256d85a..2cd461f 100644 --- a/unifi/setting_super_fwupdate.generated.go +++ b/unifi/setting_super_fwupdate.generated.go @@ -50,17 +50,17 @@ func (dst *SettingSuperFwupdate) UnmarshalJSON(b []byte) error { func (c *Client) getSettingSuperFwupdate(ctx context.Context, site string) (*SettingSuperFwupdate, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSuperFwupdate `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/super_fwupdate", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/super_fwupdate", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -69,18 +69,18 @@ func (c *Client) getSettingSuperFwupdate(ctx context.Context, site string) (*Set func (c *Client) updateSettingSuperFwupdate(ctx context.Context, site string, d *SettingSuperFwupdate) (*SettingSuperFwupdate, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSuperFwupdate `json:"data"` } d.Key = "super_fwupdate" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/super_fwupdate", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/super_fwupdate", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_super_identity.generated.go b/unifi/setting_super_identity.generated.go index a491238..447484a 100644 --- a/unifi/setting_super_identity.generated.go +++ b/unifi/setting_super_identity.generated.go @@ -49,17 +49,17 @@ func (dst *SettingSuperIdentity) UnmarshalJSON(b []byte) error { func (c *Client) getSettingSuperIdentity(ctx context.Context, site string) (*SettingSuperIdentity, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSuperIdentity `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/super_identity", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/super_identity", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -68,18 +68,18 @@ func (c *Client) getSettingSuperIdentity(ctx context.Context, site string) (*Set func (c *Client) updateSettingSuperIdentity(ctx context.Context, site string, d *SettingSuperIdentity) (*SettingSuperIdentity, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSuperIdentity `json:"data"` } d.Key = "super_identity" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/super_identity", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/super_identity", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_super_mail.generated.go b/unifi/setting_super_mail.generated.go index 4cc05b3..c662710 100644 --- a/unifi/setting_super_mail.generated.go +++ b/unifi/setting_super_mail.generated.go @@ -48,17 +48,17 @@ func (dst *SettingSuperMail) UnmarshalJSON(b []byte) error { func (c *Client) getSettingSuperMail(ctx context.Context, site string) (*SettingSuperMail, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSuperMail `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/super_mail", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/super_mail", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -67,18 +67,18 @@ func (c *Client) getSettingSuperMail(ctx context.Context, site string) (*Setting func (c *Client) updateSettingSuperMail(ctx context.Context, site string, d *SettingSuperMail) (*SettingSuperMail, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSuperMail `json:"data"` } d.Key = "super_mail" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/super_mail", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/super_mail", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_super_mgmt.generated.go b/unifi/setting_super_mgmt.generated.go index 63e0847..a838317 100644 --- a/unifi/setting_super_mgmt.generated.go +++ b/unifi/setting_super_mgmt.generated.go @@ -113,17 +113,17 @@ func (dst *SettingSuperMgmt) UnmarshalJSON(b []byte) error { func (c *Client) getSettingSuperMgmt(ctx context.Context, site string) (*SettingSuperMgmt, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSuperMgmt `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/super_mgmt", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/super_mgmt", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -132,18 +132,18 @@ func (c *Client) getSettingSuperMgmt(ctx context.Context, site string) (*Setting func (c *Client) updateSettingSuperMgmt(ctx context.Context, site string, d *SettingSuperMgmt) (*SettingSuperMgmt, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSuperMgmt `json:"data"` } d.Key = "super_mgmt" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/super_mgmt", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/super_mgmt", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_super_sdn.generated.go b/unifi/setting_super_sdn.generated.go index 4032f1b..cae225a 100644 --- a/unifi/setting_super_sdn.generated.go +++ b/unifi/setting_super_sdn.generated.go @@ -53,17 +53,17 @@ func (dst *SettingSuperSdn) UnmarshalJSON(b []byte) error { func (c *Client) getSettingSuperSdn(ctx context.Context, site string) (*SettingSuperSdn, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSuperSdn `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/super_sdn", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/super_sdn", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -72,18 +72,18 @@ func (c *Client) getSettingSuperSdn(ctx context.Context, site string) (*SettingS func (c *Client) updateSettingSuperSdn(ctx context.Context, site string, d *SettingSuperSdn) (*SettingSuperSdn, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSuperSdn `json:"data"` } d.Key = "super_sdn" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/super_sdn", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/super_sdn", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_super_smtp.generated.go b/unifi/setting_super_smtp.generated.go index 0522335..acca0b5 100644 --- a/unifi/setting_super_smtp.generated.go +++ b/unifi/setting_super_smtp.generated.go @@ -59,17 +59,17 @@ func (dst *SettingSuperSmtp) UnmarshalJSON(b []byte) error { func (c *Client) getSettingSuperSmtp(ctx context.Context, site string) (*SettingSuperSmtp, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSuperSmtp `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/super_smtp", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/super_smtp", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -78,18 +78,18 @@ func (c *Client) getSettingSuperSmtp(ctx context.Context, site string) (*Setting func (c *Client) updateSettingSuperSmtp(ctx context.Context, site string, d *SettingSuperSmtp) (*SettingSuperSmtp, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingSuperSmtp `json:"data"` } d.Key = "super_smtp" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/super_smtp", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/super_smtp", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_teleport.generated.go b/unifi/setting_teleport.generated.go index 074a5da..c7eeb46 100644 --- a/unifi/setting_teleport.generated.go +++ b/unifi/setting_teleport.generated.go @@ -49,17 +49,17 @@ func (dst *SettingTeleport) UnmarshalJSON(b []byte) error { func (c *Client) getSettingTeleport(ctx context.Context, site string) (*SettingTeleport, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingTeleport `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/teleport", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/teleport", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -68,18 +68,18 @@ func (c *Client) getSettingTeleport(ctx context.Context, site string) (*SettingT func (c *Client) updateSettingTeleport(ctx context.Context, site string, d *SettingTeleport) (*SettingTeleport, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingTeleport `json:"data"` } d.Key = "teleport" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/teleport", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/teleport", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_usg.generated.go b/unifi/setting_usg.generated.go index d7e4bb1..35f3071 100644 --- a/unifi/setting_usg.generated.go +++ b/unifi/setting_usg.generated.go @@ -160,17 +160,17 @@ func (dst *SettingUsgDNSVerification) UnmarshalJSON(b []byte) error { func (c *Client) getSettingUsg(ctx context.Context, site string) (*SettingUsg, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingUsg `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/usg", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/usg", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -179,18 +179,18 @@ func (c *Client) getSettingUsg(ctx context.Context, site string) (*SettingUsg, e func (c *Client) updateSettingUsg(ctx context.Context, site string, d *SettingUsg) (*SettingUsg, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingUsg `json:"data"` } d.Key = "usg" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/usg", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/usg", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/setting_usw.generated.go b/unifi/setting_usw.generated.go index 2d48ae3..b2ab821 100644 --- a/unifi/setting_usw.generated.go +++ b/unifi/setting_usw.generated.go @@ -48,17 +48,17 @@ func (dst *SettingUsw) UnmarshalJSON(b []byte) error { func (c *Client) getSettingUsw(ctx context.Context, site string) (*SettingUsw, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingUsw `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/get/setting/usw", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/get/setting/usw", site), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -67,18 +67,18 @@ func (c *Client) getSettingUsw(ctx context.Context, site string) (*SettingUsw, e func (c *Client) updateSettingUsw(ctx context.Context, site string, d *SettingUsw) (*SettingUsw, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SettingUsw `json:"data"` } d.Key = "usw" - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/set/setting/usw", site), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/set/setting/usw", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/sites.go b/unifi/sites.go index 2ac5d82..6ceae39 100644 --- a/unifi/sites.go +++ b/unifi/sites.go @@ -21,11 +21,11 @@ type Site struct { func (c *Client) ListSites(ctx context.Context) ([]Site, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"Meta"` Data []Site `json:"data"` } - err := c.do(ctx, "GET", "self/sites", nil, &respBody) + err := c.Get(ctx, "self/sites", nil, &respBody) if err != nil { return nil, err } @@ -45,7 +45,7 @@ func (c *Client) GetSite(ctx context.Context, id string) (*Site, error) { } } - return nil, &NotFoundError{} + return nil, NotFoundError } func (c *Client) CreateSite(ctx context.Context, description string) ([]Site, error) { @@ -58,11 +58,11 @@ func (c *Client) CreateSite(ctx context.Context, description string) ([]Site, er } var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"Meta"` Data []Site `json:"data"` } - err := c.do(ctx, "POST", "s/default/cmd/sitemgr", reqBody, &respBody) + err := c.Post(ctx, "s/default/cmd/sitemgr", reqBody, &respBody) if err != nil { return nil, err } @@ -80,11 +80,11 @@ func (c *Client) DeleteSite(ctx context.Context, id string) ([]Site, error) { } var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"Meta"` Data []Site `json:"data"` } - err := c.do(ctx, "POST", "s/default/cmd/sitemgr", reqBody, &respBody) + err := c.Post(ctx, "s/default/cmd/sitemgr", reqBody, &respBody) if err != nil { return nil, err } @@ -102,11 +102,11 @@ func (c *Client) UpdateSite(ctx context.Context, name, description string) ([]Si } var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"Meta"` Data []Site `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/cmd/sitemgr", name), reqBody, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/cmd/sitemgr", name), reqBody, &respBody) if err != nil { return nil, err } diff --git a/unifi/spatial_record.generated.go b/unifi/spatial_record.generated.go index 04f2495..3f696d1 100644 --- a/unifi/spatial_record.generated.go +++ b/unifi/spatial_record.generated.go @@ -90,11 +90,11 @@ func (dst *SpatialRecordPosition) UnmarshalJSON(b []byte) error { func (c *Client) listSpatialRecord(ctx context.Context, site string) ([]SpatialRecord, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SpatialRecord `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/spatialrecord", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/spatialrecord", site), nil, &respBody) if err != nil { return nil, err } @@ -104,17 +104,17 @@ func (c *Client) listSpatialRecord(ctx context.Context, site string) ([]SpatialR func (c *Client) getSpatialRecord(ctx context.Context, site, id string) (*SpatialRecord, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SpatialRecord `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/spatialrecord/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/spatialrecord/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -122,7 +122,7 @@ func (c *Client) getSpatialRecord(ctx context.Context, site, id string) (*Spatia } func (c *Client) deleteSpatialRecord(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/spatialrecord/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/spatialrecord/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -131,17 +131,17 @@ func (c *Client) deleteSpatialRecord(ctx context.Context, site, id string) error func (c *Client) createSpatialRecord(ctx context.Context, site string, d *SpatialRecord) (*SpatialRecord, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SpatialRecord `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/spatialrecord", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/spatialrecord", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -151,17 +151,17 @@ func (c *Client) createSpatialRecord(ctx context.Context, site string, d *Spatia func (c *Client) updateSpatialRecord(ctx context.Context, site string, d *SpatialRecord) (*SpatialRecord, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []SpatialRecord `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/spatialrecord/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/spatialrecord/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/sysinfo.go b/unifi/sysinfo.go index 2ce05c1..5cbb7dd 100644 --- a/unifi/sysinfo.go +++ b/unifi/sysinfo.go @@ -15,7 +15,7 @@ type sysInfo struct { /* { - "meta": { + "Meta": { "rc": "ok" }, "data": [ @@ -68,17 +68,17 @@ type sysInfo struct { func (c *Client) sysinfo(ctx context.Context, id string) (*sysInfo, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"Meta"` Data []sysInfo `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/stat/sysinfo", id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/stat/sysinfo", id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } return &respBody.Data[0], nil diff --git a/unifi/tag.generated.go b/unifi/tag.generated.go index a916dcf..e48238e 100644 --- a/unifi/tag.generated.go +++ b/unifi/tag.generated.go @@ -47,11 +47,11 @@ func (dst *Tag) UnmarshalJSON(b []byte) error { func (c *Client) listTag(ctx context.Context, site string) ([]Tag, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Tag `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/tag", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/tag", site), nil, &respBody) if err != nil { return nil, err } @@ -61,17 +61,17 @@ func (c *Client) listTag(ctx context.Context, site string) ([]Tag, error) { func (c *Client) getTag(ctx context.Context, site, id string) (*Tag, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Tag `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/tag/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/tag/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -79,7 +79,7 @@ func (c *Client) getTag(ctx context.Context, site, id string) (*Tag, error) { } func (c *Client) deleteTag(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/tag/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/tag/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -88,17 +88,17 @@ func (c *Client) deleteTag(ctx context.Context, site, id string) error { func (c *Client) createTag(ctx context.Context, site string, d *Tag) (*Tag, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Tag `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/tag", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/tag", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -108,17 +108,17 @@ func (c *Client) createTag(ctx context.Context, site string, d *Tag) (*Tag, erro func (c *Client) updateTag(ctx context.Context, site string, d *Tag) (*Tag, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []Tag `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/tag/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/tag/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/unifi.go b/unifi/unifi.go index 5e5f5d6..06f144c 100644 --- a/unifi/unifi.go +++ b/unifi/unifi.go @@ -3,6 +3,7 @@ package unifi import ( "bytes" "context" + "crypto/tls" "encoding/json" "errors" "fmt" @@ -11,8 +12,12 @@ import ( "net/http/cookiejar" "net/url" "path" + "slices" "strings" "sync" + "time" + + "golang.org/x/net/publicsuffix" ) const ( @@ -27,13 +32,16 @@ const ( statusPath = "/status" statusPathNew = "/proxy/network/status" + + logoutPath = "/api/logout" + + defaultUserAgent = "go-unifi/0.0.1" ) -type NotFoundError struct{} - -func (err *NotFoundError) Error() string { - return "not found" -} +var ( + AuthenticationFailedError = fmt.Errorf("authentication failed") + NotFoundError = fmt.Errorf("not found") +) type APIError struct { RC string @@ -54,246 +62,12 @@ func (err *APIError) Is(target error) bool { return false } -type Client struct { - // single thread client calls for CSRF, etc. - sync.Mutex - - c *http.Client - baseURL *url.URL - - apiPath string - apiV2Path string - loginPath string - statusPath string - - csrf string - - version string -} - -func (c *Client) CSRFToken() string { - return c.csrf -} - -func (c *Client) Version() string { - return c.version -} - -func (c *Client) SetBaseURL(base string) error { - var err error - c.baseURL, err = url.Parse(base) - if err != nil { - return err - } - - // error for people who are still passing hard coded old paths - if path := strings.TrimSuffix(c.baseURL.Path, "/"); path == apiPath { - return fmt.Errorf("expected a base URL without the `/api`, got: %q", c.baseURL) - } - - return nil -} - -func (c *Client) SetHTTPClient(hc *http.Client) error { - c.c = hc - return nil -} - -func (c *Client) setAPIUrlStyle(ctx context.Context) error { - // check if new style API - // this is modified from the unifi-poller (https://github.com/unifi-poller/unifi) implementation. - // see https://github.com/unifi-poller/unifi/blob/4dc44f11f61a2e08bf7ec5b20c71d5bced837b5d/unifi.go#L101-L104 - // and https://github.com/unifi-poller/unifi/commit/43a6b225031a28f2b358f52d03a7217c7b524143 - - req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.baseURL.String(), nil) - if err != nil { - return err - } - - // We can't share these cookies with other requests, so make a new client. - // Checking the return code on the first request so don't follow a redirect. - client := &http.Client{ - CheckRedirect: func(req *http.Request, via []*http.Request) error { - return http.ErrUseLastResponse - }, - Transport: c.c.Transport, - } - - resp, err := client.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - _, _ = io.Copy(io.Discard, resp.Body) - - if resp.StatusCode == http.StatusOK { - // the new API returns a 200 for a / request - c.apiPath = apiPathNew - c.apiV2Path = apiV2PathNew - c.loginPath = loginPathNew - c.statusPath = statusPathNew - return nil - } - - // The old version returns a "302" (to /manage) for a / request - c.apiPath = apiPath - c.apiV2Path = apiV2Path - c.loginPath = loginPath - c.statusPath = statusPath - return nil -} - -func (c *Client) Login(ctx context.Context, user, pass string) error { - if c.c == nil { - c.c = &http.Client{} - - jar, _ := cookiejar.New(nil) - c.c.Jar = jar - } - - err := c.setAPIUrlStyle(ctx) - if err != nil { - return fmt.Errorf("unable to determine API URL style: %w", err) - } - - var status struct { - Meta struct { - ServerVersion string `json:"server_version"` - UUID string `json:"uuid"` - } `json:"meta"` - } - - err = c.do(ctx, "POST", c.loginPath, &struct { - Username string `json:"username"` - Password string `json:"password"` - }{ - Username: user, - Password: pass, - }, nil) - if err != nil { - return err - } - - err = c.do(ctx, "GET", c.statusPath, nil, &status) - if err != nil { - return err - } - - if version := status.Meta.ServerVersion; version != "" { - c.version = status.Meta.ServerVersion - return nil - } - - // newer version of 6.0 controller, use sysinfo to determine version - // using default site since it must exist - si, err := c.sysinfo(ctx, "default") - if err != nil { - return err - } - - c.version = si.Version - - if c.version == "" { - return errors.New("unable to determine controller version") - } - - return nil -} - -func (c *Client) do(ctx context.Context, method, relativeURL string, reqBody interface{}, respBody interface{}) error { - // single threading requests, this is mostly to assist in CSRF token propagation - c.Lock() - defer c.Unlock() - - var ( - reqReader io.Reader - err error - reqBytes []byte - ) - if reqBody != nil { - reqBytes, err = json.Marshal(reqBody) - if err != nil { - return fmt.Errorf("unable to marshal JSON: %s %s %w", method, relativeURL, err) - } - reqReader = bytes.NewReader(reqBytes) - } - - reqURL, err := url.Parse(relativeURL) - if err != nil { - return fmt.Errorf("unable to parse URL: %s %s %w", method, relativeURL, err) - } - if !strings.HasPrefix(relativeURL, "/") && !reqURL.IsAbs() { - reqURL.Path = path.Join(c.apiPath, reqURL.Path) - } - - url := c.baseURL.ResolveReference(reqURL) - req, err := http.NewRequestWithContext(ctx, method, url.String(), reqReader) - if err != nil { - return fmt.Errorf("unable to create request: %s %s %w", method, relativeURL, err) - } - - req.Header.Set("User-Agent", "terraform-provider-unifi/0.1") - req.Header.Add("Content-Type", "application/json; charset=utf-8") - - if c.csrf != "" { - req.Header.Set("X-Csrf-Token", c.csrf) - } - - resp, err := c.c.Do(req) - if err != nil { - return fmt.Errorf("unable to perform request: %s %s %w", method, relativeURL, err) - } - defer resp.Body.Close() - - if resp.StatusCode == http.StatusNotFound { - return &NotFoundError{} - } - - if csrf := resp.Header.Get("X-Csrf-Token"); csrf != "" { - c.csrf = resp.Header.Get("X-Csrf-Token") - } - - if resp.StatusCode != http.StatusOK { - errBody := struct { - Meta meta `json:"meta"` - Data []struct { - Meta meta `json:"meta"` - } `json:"data"` - }{} - if err = json.NewDecoder(resp.Body).Decode(&errBody); err != nil { - return err - } - var apiErr error - if len(errBody.Data) > 0 && errBody.Data[0].Meta.RC == "error" { - // check first error in data, should we look for more than one? - apiErr = errBody.Data[0].Meta.error() - } - if apiErr == nil { - apiErr = errBody.Meta.error() - } - return fmt.Errorf("%w (%s) for %s %s", apiErr, resp.Status, method, url.String()) - } - - if respBody == nil || resp.ContentLength == 0 { - return nil - } - - // TODO: check rc in addition to status code? - - err = json.NewDecoder(resp.Body).Decode(respBody) - if err != nil { - return fmt.Errorf("unable to decode body: %s %s %w", method, relativeURL, err) - } - - return nil -} - -type meta struct { +type Meta struct { RC string `json:"rc"` Message string `json:"msg"` } -func (m *meta) error() error { +func (m *Meta) error() error { if m.RC != "ok" { return &APIError{ RC: m.RC, @@ -303,3 +77,472 @@ func (m *meta) error() error { return nil } + +type ClientConfig struct { + User string + Pass string + APIKey string + URL string + Timeout time.Duration // how long to wait for replies, default: forever. + VerifySSL bool + Interceptors []ClientInterceptor + HttpCustomizer HttpCustomizer + UserAgent string + ErrorHandler ResponseErrorHandler + UseLocking bool +} + +type Client struct { + BaseURL *url.URL + ServerInfo *ServerInfo + apiPaths *ApiPaths + config *ClientConfig + http *http.Client + interceptors []ClientInterceptor + errorHandler ResponseErrorHandler + lock sync.Mutex +} + +type ApiPaths struct { + ApiPath string + ApiV2Path string + LoginPath string + StatusPath string + LogoutPath string +} + +var ( + OldStyleAPI = ApiPaths{ + ApiPath: apiPath, + ApiV2Path: apiV2Path, + LoginPath: loginPath, + StatusPath: statusPath, + LogoutPath: logoutPath, + } + NewStyleAPI = ApiPaths{ + ApiPath: apiPathNew, + ApiV2Path: apiV2PathNew, + LoginPath: loginPathNew, + StatusPath: statusPathNew, + LogoutPath: logoutPath, + } +) + +type ServerInfo struct { + Up bool `json:"up"` + ServerVersion string `fake:"{appversion}" json:"server_version"` + UUID string `fake:"{uuid}" json:"uuid"` +} + +type HttpCustomizer func(transport *http.Transport) error + +type ClientInterceptor interface { + InterceptRequest(req *http.Request) error + InterceptResponse(resp *http.Response) error +} +type ApiTokenAuthInterceptor struct { + apiKey string +} + +func (a *ApiTokenAuthInterceptor) InterceptRequest(req *http.Request) error { + req.Header.Set("X-API-Key", a.apiKey) + return nil +} +func (a *ApiTokenAuthInterceptor) InterceptResponse(_ *http.Response) error { + return nil +} + +type CsrfInterceptor struct { + csrfToken string +} + +func (c *CsrfInterceptor) InterceptRequest(req *http.Request) error { + if c.csrfToken != "" { + req.Header.Set("X-Csrf-Token", c.csrfToken) + } + return nil +} + +func (c *CsrfInterceptor) InterceptResponse(resp *http.Response) error { + if csrf := resp.Header.Get("X-Csrf-Token"); csrf != "" { + c.csrfToken = csrf + } + return nil +} + +type DefaultHeadersInterceptor struct { + headers map[string]string +} + +func (d *DefaultHeadersInterceptor) InterceptRequest(req *http.Request) error { + for key, value := range d.headers { + req.Header.Set(key, value) + } + return nil +} + +func (d *DefaultHeadersInterceptor) InterceptResponse(_ *http.Response) error { + return nil +} + +func (c *Client) RegisterInterceptor(interceptor *ClientInterceptor) { + // ensure no duplicate interceptors + if !slices.Contains(c.interceptors, *interceptor) { + c.interceptors = append(c.interceptors, *interceptor) + } +} + +type ResponseErrorHandler interface { + HandleError(resp *http.Response) error +} + +type DefaultResponseErrorHandler struct{} + +func (d *DefaultResponseErrorHandler) HandleError(resp *http.Response) error { + switch resp.StatusCode { + case http.StatusOK: + return nil + case http.StatusNotFound: + return NotFoundError + case http.StatusUnauthorized: + return AuthenticationFailedError + } + errBody := struct { + Meta Meta `json:"Meta"` + Data []struct { + Meta Meta `json:"Meta"` + } `json:"data"` + }{} + if err := json.NewDecoder(resp.Body).Decode(&errBody); err != nil { + return err + } + var apiErr error + if len(errBody.Data) > 0 && errBody.Data[0].Meta.RC == "error" { + // check first error in data, should we look for more than one? + apiErr = errBody.Data[0].Meta.error() + } + if apiErr == nil { + apiErr = errBody.Meta.error() + } + + // TODO: check rc in addition to status code? + return fmt.Errorf("%w (%s) for %s %s", apiErr, resp.Status, resp.Request.Method, resp.Request.URL.String()) +} + +// NewClient creates a http.Client with authenticated cookies. +// Used to make additional, authenticated requests to the APIs. +// Start here. +func NewClient(config *ClientConfig) (*Client, error) { + u, err := newUnifi(config) + if err != nil { + return nil, fmt.Errorf("failed creating unifi client: %w", err) + } + if err = u.determineApiStyle(); err != nil { + return u, fmt.Errorf("failed determining API style: %w", err) + } + + if err = u.Login(); err != nil { + return u, fmt.Errorf("failed logging in: %w", err) + } + + if serverInfo, err := u.GetServerInfo(); err != nil { + return u, fmt.Errorf("failed getting server info: %w", err) + } else { + u.ServerInfo = serverInfo + } + return u, nil +} + +func parseBaseUrl(base string) (*url.URL, error) { + var err error + baseURL, err := url.Parse(base) + if err != nil { + return nil, err + } + + // error for people who are still passing hard coded old paths + if path := strings.TrimSuffix(baseURL.Path, "/"); path == apiPath { + return nil, fmt.Errorf("expected a base URL without the `/api`, got: %q", baseURL) + } + + return baseURL, nil +} + +func newUnifi(config *ClientConfig) (*Client, error) { + var err error + + config.URL = strings.TrimRight(config.URL, "/") + transport := &http.Transport{ + Proxy: http.ProxyFromEnvironment, + TLSClientConfig: &tls.Config{InsecureSkipVerify: !config.VerifySSL}, // nolint: gosec + } + + if config.HttpCustomizer != nil { + if err = config.HttpCustomizer(transport); err != nil { + return nil, fmt.Errorf("failed customizing HTTP transport: %w", err) + } + } + + client := &http.Client{ + Timeout: config.Timeout, + Transport: transport, + } + + if config.APIKey == "" { + // old user/pass style use the cookie jar + jar, err := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List}) + if err != nil { + return nil, fmt.Errorf("failed creating cookiejar: %w", err) + } + client.Jar = jar + } + baseURL, err := parseBaseUrl(config.URL) + if err != nil { + return nil, fmt.Errorf("failed parsing base URL: %w", err) + } + var interceptors []ClientInterceptor + + if config.APIKey != "" { + interceptors = append(interceptors, &ApiTokenAuthInterceptor{apiKey: config.APIKey}) + } else { + // CSRF is only needed for user/pass auth + interceptors = append(interceptors, &CsrfInterceptor{}) + } + if len(config.UserAgent) == 0 { + config.UserAgent = defaultUserAgent + } + interceptors = append(interceptors, &DefaultHeadersInterceptor{headers: map[string]string{ + "User-Agent": config.UserAgent, + "Accept": "application/json", + "Content-Type": "application/json; charset=utf-8", + }}) + + var errorHandler ResponseErrorHandler + if config.ErrorHandler != nil { + errorHandler = config.ErrorHandler + } else { + errorHandler = &DefaultResponseErrorHandler{} + } + u := &Client{ + BaseURL: baseURL, + config: config, + http: client, + interceptors: interceptors, + errorHandler: errorHandler, + lock: sync.Mutex{}, + } + for _, interceptor := range config.Interceptors { + // add any custom interceptors and ensure no duplicates + u.RegisterInterceptor(&interceptor) + } + + return u, nil +} + +// Login is a helper method. It can be called to grab a new authentication cookie. +func (c *Client) Login() error { + if c.config.APIKey != "" { + // no need to login on api-key auth + return nil + } + + ctx, cancel := c.createRequestContext() + defer cancel() + + err := c.Post(ctx, c.apiPaths.LoginPath, &struct { + Username string `json:"username"` + Password string `json:"password"` + }{ + Username: c.config.User, + Password: c.config.Pass, + }, nil) + if err != nil { + return err + } + return nil +} + +// Logout closes the current session. +func (c *Client) Logout() error { + if c.config.APIKey != "" { + // no need to logout on api-key auth + return nil + } + ctx, cancel := c.createRequestContext() + defer cancel() + + // a post is needed for logout + err := c.Post(ctx, c.apiPaths.LogoutPath, nil, nil) + + return err +} + +func (c *Client) createRequestContext() (context.Context, context.CancelFunc) { + var ( + ctx = context.Background() + cancel = func() {} + ) + if c.config.Timeout != 0 { + ctx, cancel = context.WithTimeout(ctx, c.config.Timeout) + } + return ctx, cancel +} + +// with the release of controller version 5.12.55 on UDM in Jan 2020 the api paths +// changed and broke this library. This function runs when `NewClient()` is called to +// check if this is a newer controller or not. If it is, we set new to true. +// Setting new to true makes the path() method return different (new) paths. +func (c *Client) determineApiStyle() error { + ctx, cancel := c.createRequestContext() + defer cancel() + + //c.DebugLog("Requesting %s/ to determine API paths", c.URL) + + req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.BaseURL.String(), nil) + if err != nil { + return err + } + + // We can't share these cookies with other requests, so make a new client. + // Checking the return code on the first request so don't follow a redirect. + client := &http.Client{ + CheckRedirect: func(_ *http.Request, _ []*http.Request) error { + return http.ErrUseLastResponse + }, + Transport: c.http.Transport, + } + + resp, err := client.Do(req) + if err != nil { + return err + } + defer resp.Body.Close() // we need no data here. + _, _ = io.Copy(io.Discard, resp.Body) // avoid leaking. + + switch resp.StatusCode { + case http.StatusOK: + c.apiPaths = &NewStyleAPI // The new version returns a "200" for a / request. + case http.StatusFound: + c.apiPaths = &OldStyleAPI // The old version returns a "302" (to /manage) for a / request. + default: + return fmt.Errorf("expected 200 or 302 status code, but got: %d", resp.StatusCode) + } + if c.apiPaths == &OldStyleAPI && c.config.APIKey != "" { + return fmt.Errorf("unable to use API key authentication with old style API. Switch to user/pass authentication or update controller to latest version") + } + return nil +} + +// GetServerInfo sets the controller's version and UUID. Only call this if you +// previously called Login and suspect the controller version has changed. +func (c *Client) GetServerInfo() (*ServerInfo, error) { + ctx, cancel := c.createRequestContext() + defer cancel() + + var response struct { + Data ServerInfo `json:"Meta"` + } + + err := c.Get(ctx, c.apiPaths.StatusPath, nil, &response) + if err != nil { + return nil, err + } + + return &response.Data, nil +} + +func marshalRequest(reqBody interface{}) (io.Reader, error) { + if reqBody == nil { + return nil, nil + } + reqBytes, err := json.Marshal(reqBody) + if err != nil { + return nil, err + } + return bytes.NewReader(reqBytes), nil +} + +func (c *Client) createRequestURL(apiPath string) (*url.URL, error) { + reqURL, err := url.Parse(apiPath) + if err != nil { + return nil, err + } + if !strings.HasPrefix(apiPath, "/") && !reqURL.IsAbs() { + reqURL.Path = path.Join(c.apiPaths.ApiPath, reqURL.Path) + } + + return c.BaseURL.ResolveReference(reqURL), nil +} + +func (c *Client) Do(ctx context.Context, method, apiPath string, reqBody interface{}, respBody interface{}) error { + reqReader, err := marshalRequest(reqBody) + if err != nil { + return fmt.Errorf("unable to marshal request: %w", err) + } + + url, err := c.createRequestURL(apiPath) + if err != nil { + return fmt.Errorf("unable to create request URL: %w", err) + } + req, err := http.NewRequestWithContext(ctx, method, url.String(), reqReader) + if err != nil { + return fmt.Errorf("unable to create request: %s %s %w", method, apiPath, err) + } + if c.config.UseLocking { + c.lock.Lock() + defer c.lock.Unlock() + } + + for _, interceptor := range c.interceptors { + if err := interceptor.InterceptRequest(req); err != nil { + return err + } + } + + resp, err := c.http.Do(req) + if err != nil { + return fmt.Errorf("unable to perform request: %s %s %w", method, apiPath, err) + } + defer func(body io.ReadCloser) { + err := body.Close() + if err != nil { + // TODO use logger + fmt.Printf("error closing body: %s", err) + } + }(resp.Body) + + for _, interceptor := range c.interceptors { + if err := interceptor.InterceptResponse(resp); err != nil { + return err + } + } + if err := c.errorHandler.HandleError(resp); err != nil { + return err + } + if respBody == nil || resp.ContentLength == 0 { + return nil + } + + err = json.NewDecoder(resp.Body).Decode(respBody) + if err != nil { + return fmt.Errorf("unable to decode body: %s %s %w", method, apiPath, err) + } + + return nil +} + +func (c *Client) Get(context context.Context, apiPath string, reqBody interface{}, respBody interface{}) error { + return c.Do(context, http.MethodGet, apiPath, reqBody, respBody) +} + +func (c *Client) Post(context context.Context, apiPath string, reqBody interface{}, respBody interface{}) error { + return c.Do(context, http.MethodPost, apiPath, reqBody, respBody) +} + +func (c *Client) Put(context context.Context, apiPath string, reqBody interface{}, respBody interface{}) error { + return c.Do(context, http.MethodPut, apiPath, reqBody, respBody) +} + +func (c *Client) Delete(context context.Context, apiPath string, reqBody interface{}, respBody interface{}) error { + return c.Do(context, http.MethodDelete, apiPath, reqBody, respBody) +} diff --git a/unifi/user.generated.go b/unifi/user.generated.go index bf4cac5..1fd1b66 100644 --- a/unifi/user.generated.go +++ b/unifi/user.generated.go @@ -67,11 +67,11 @@ func (dst *User) UnmarshalJSON(b []byte) error { func (c *Client) listUser(ctx context.Context, site string) ([]User, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []User `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/user", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/user", site), nil, &respBody) if err != nil { return nil, err } @@ -81,17 +81,17 @@ func (c *Client) listUser(ctx context.Context, site string) ([]User, error) { func (c *Client) getUser(ctx context.Context, site, id string) (*User, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []User `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/user/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/user/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -99,7 +99,7 @@ func (c *Client) getUser(ctx context.Context, site, id string) (*User, error) { } func (c *Client) deleteUser(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/user/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/user/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -108,17 +108,17 @@ func (c *Client) deleteUser(ctx context.Context, site, id string) error { func (c *Client) createUser(ctx context.Context, site string, d *User) (*User, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []User `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/user", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/user", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -128,17 +128,17 @@ func (c *Client) createUser(ctx context.Context, site string, d *User) (*User, e func (c *Client) updateUser(ctx context.Context, site string, d *User) (*User, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []User `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/user/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/user/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/user.go b/unifi/user.go index b939c8c..2f78093 100644 --- a/unifi/user.go +++ b/unifi/user.go @@ -11,17 +11,17 @@ import ( // by this method. func (c *Client) GetUserByMAC(ctx context.Context, site, mac string) (*User, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"Meta"` Data []User `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/stat/user/%s", site, mac), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/stat/user/%s", site, mac), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -42,14 +42,14 @@ func (c *Client) CreateUser(ctx context.Context, site string, d *User) (*User, e } var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"Meta"` Data []struct { - Meta meta `json:"meta"` + Meta Meta `json:"Meta"` Data []User `json:"data"` } `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/group/user", site), reqBody, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/group/user", site), reqBody, &respBody) if err != nil { return nil, err } @@ -63,7 +63,7 @@ func (c *Client) CreateUser(ctx context.Context, site string, d *User) (*User, e } if len(respBody.Data[0].Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } user := respBody.Data[0].Data[0] @@ -81,11 +81,11 @@ func (c *Client) stamgr(ctx context.Context, site, cmd string, data map[string]i reqBody["cmd"] = cmd var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"Meta"` Data []User `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/cmd/stamgr", site), reqBody, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/cmd/stamgr", site), reqBody, &respBody) if err != nil { return nil, err } @@ -101,7 +101,7 @@ func (c *Client) BlockUserByMAC(ctx context.Context, site, mac string) error { return err } if len(users) != 1 { - return &NotFoundError{} + return NotFoundError } return nil } @@ -114,7 +114,7 @@ func (c *Client) UnblockUserByMAC(ctx context.Context, site, mac string) error { return err } if len(users) != 1 { - return &NotFoundError{} + return NotFoundError } return nil } @@ -127,7 +127,7 @@ func (c *Client) DeleteUserByMAC(ctx context.Context, site, mac string) error { return err } if len(users) != 1 { - return &NotFoundError{} + return NotFoundError } return nil } @@ -140,7 +140,7 @@ func (c *Client) KickUserByMAC(ctx context.Context, site, mac string) error { return err } if len(users) != 1 { - return &NotFoundError{} + return NotFoundError } return nil } @@ -165,7 +165,7 @@ func (c *Client) OverrideUserFingerprint(ctx context.Context, site, mac string, SearchQuery string `json:"search_query"` } - err := c.do(ctx, reqMethod, fmt.Sprintf("%s/site/%s/station/%s/fingerprint_override", c.apiV2Path, site, mac), reqBody, &respBody) + err := c.Do(ctx, reqMethod, fmt.Sprintf("%s/site/%s/station/%s/fingerprint_override", c.apiPaths.ApiV2Path, site, mac), reqBody, &respBody) if err != nil { return err } diff --git a/unifi/user_group.generated.go b/unifi/user_group.generated.go index 3b843e9..b29202a 100644 --- a/unifi/user_group.generated.go +++ b/unifi/user_group.generated.go @@ -53,11 +53,11 @@ func (dst *UserGroup) UnmarshalJSON(b []byte) error { func (c *Client) listUserGroup(ctx context.Context, site string) ([]UserGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []UserGroup `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/usergroup", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/usergroup", site), nil, &respBody) if err != nil { return nil, err } @@ -67,17 +67,17 @@ func (c *Client) listUserGroup(ctx context.Context, site string) ([]UserGroup, e func (c *Client) getUserGroup(ctx context.Context, site, id string) (*UserGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []UserGroup `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/usergroup/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/usergroup/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -85,7 +85,7 @@ func (c *Client) getUserGroup(ctx context.Context, site, id string) (*UserGroup, } func (c *Client) deleteUserGroup(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/usergroup/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/usergroup/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -94,17 +94,17 @@ func (c *Client) deleteUserGroup(ctx context.Context, site, id string) error { func (c *Client) createUserGroup(ctx context.Context, site string, d *UserGroup) (*UserGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []UserGroup `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/usergroup", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/usergroup", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -114,17 +114,17 @@ func (c *Client) createUserGroup(ctx context.Context, site string, d *UserGroup) func (c *Client) updateUserGroup(ctx context.Context, site string, d *UserGroup) (*UserGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []UserGroup `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/usergroup/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/usergroup/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/virtual_device.generated.go b/unifi/virtual_device.generated.go index 2c6e40f..d0f5b35 100644 --- a/unifi/virtual_device.generated.go +++ b/unifi/virtual_device.generated.go @@ -51,11 +51,11 @@ func (dst *VirtualDevice) UnmarshalJSON(b []byte) error { func (c *Client) listVirtualDevice(ctx context.Context, site string) ([]VirtualDevice, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []VirtualDevice `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/virtualdevice", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/virtualdevice", site), nil, &respBody) if err != nil { return nil, err } @@ -65,17 +65,17 @@ func (c *Client) listVirtualDevice(ctx context.Context, site string) ([]VirtualD func (c *Client) getVirtualDevice(ctx context.Context, site, id string) (*VirtualDevice, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []VirtualDevice `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/virtualdevice/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/virtualdevice/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -83,7 +83,7 @@ func (c *Client) getVirtualDevice(ctx context.Context, site, id string) (*Virtua } func (c *Client) deleteVirtualDevice(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/virtualdevice/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/virtualdevice/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -92,17 +92,17 @@ func (c *Client) deleteVirtualDevice(ctx context.Context, site, id string) error func (c *Client) createVirtualDevice(ctx context.Context, site string, d *VirtualDevice) (*VirtualDevice, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []VirtualDevice `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/virtualdevice", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/virtualdevice", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -112,17 +112,17 @@ func (c *Client) createVirtualDevice(ctx context.Context, site string, d *Virtua func (c *Client) updateVirtualDevice(ctx context.Context, site string, d *VirtualDevice) (*VirtualDevice, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []VirtualDevice `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/virtualdevice/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/virtualdevice/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/wlan.generated.go b/unifi/wlan.generated.go index 912d551..311540b 100644 --- a/unifi/wlan.generated.go +++ b/unifi/wlan.generated.go @@ -468,11 +468,11 @@ func (dst *WLANVenueName) UnmarshalJSON(b []byte) error { func (c *Client) listWLAN(ctx context.Context, site string) ([]WLAN, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []WLAN `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/wlanconf", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/wlanconf", site), nil, &respBody) if err != nil { return nil, err } @@ -482,17 +482,17 @@ func (c *Client) listWLAN(ctx context.Context, site string) ([]WLAN, error) { func (c *Client) getWLAN(ctx context.Context, site, id string) (*WLAN, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []WLAN `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/wlanconf/%s", site, id), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/wlanconf/%s", site, id), nil, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } d := respBody.Data[0] @@ -500,7 +500,7 @@ func (c *Client) getWLAN(ctx context.Context, site, id string) (*WLAN, error) { } func (c *Client) deleteWLAN(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/wlanconf/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/wlanconf/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -509,17 +509,17 @@ func (c *Client) deleteWLAN(ctx context.Context, site, id string) error { func (c *Client) createWLAN(ctx context.Context, site string, d *WLAN) (*WLAN, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []WLAN `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/wlanconf", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/wlanconf", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -529,17 +529,17 @@ func (c *Client) createWLAN(ctx context.Context, site string, d *WLAN) (*WLAN, e func (c *Client) updateWLAN(ctx context.Context, site string, d *WLAN) (*WLAN, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []WLAN `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/wlanconf/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, fmt.Sprintf("s/%s/rest/wlanconf/%s", site, d.ID), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] diff --git a/unifi/wlan_group.generated.go b/unifi/wlan_group.generated.go index 52990c5..0033e52 100644 --- a/unifi/wlan_group.generated.go +++ b/unifi/wlan_group.generated.go @@ -46,11 +46,11 @@ func (dst *WLANGroup) UnmarshalJSON(b []byte) error { func (c *Client) listWLANGroup(ctx context.Context, site string) ([]WLANGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []WLANGroup `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/wlangroup", site), nil, &respBody) + err := c.Get(ctx, fmt.Sprintf("s/%s/rest/wlangroup", site), nil, &respBody) if err != nil { return nil, err } @@ -60,17 +60,17 @@ func (c *Client) listWLANGroup(ctx context.Context, site string) ([]WLANGroup, e func (c *Client) getWLANGroup(ctx context.Context, site, id string) (*WLANGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []WLANGroup `json:"data"` } - err := c.do(ctx, "GET", fmt.Sprintf("s/%s/rest/wlangroup/%s", site, id), nil, &respBody) + err := c.Get(ctx, 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{} + return nil, NotFoundError } d := respBody.Data[0] @@ -78,7 +78,7 @@ func (c *Client) getWLANGroup(ctx context.Context, site, id string) (*WLANGroup, } func (c *Client) deleteWLANGroup(ctx context.Context, site, id string) error { - err := c.do(ctx, "DELETE", fmt.Sprintf("s/%s/rest/wlangroup/%s", site, id), struct{}{}, nil) + err := c.Delete(ctx, fmt.Sprintf("s/%s/rest/wlangroup/%s", site, id), struct{}{}, nil) if err != nil { return err } @@ -87,17 +87,17 @@ func (c *Client) deleteWLANGroup(ctx context.Context, site, id string) error { func (c *Client) createWLANGroup(ctx context.Context, site string, d *WLANGroup) (*WLANGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []WLANGroup `json:"data"` } - err := c.do(ctx, "POST", fmt.Sprintf("s/%s/rest/wlangroup", site), d, &respBody) + err := c.Post(ctx, fmt.Sprintf("s/%s/rest/wlangroup", site), d, &respBody) if err != nil { return nil, err } if len(respBody.Data) != 1 { - return nil, &NotFoundError{} + return nil, NotFoundError } new := respBody.Data[0] @@ -107,17 +107,17 @@ func (c *Client) createWLANGroup(ctx context.Context, site string, d *WLANGroup) func (c *Client) updateWLANGroup(ctx context.Context, site string, d *WLANGroup) (*WLANGroup, error) { var respBody struct { - Meta meta `json:"meta"` + Meta Meta `json:"meta"` Data []WLANGroup `json:"data"` } - err := c.do(ctx, "PUT", fmt.Sprintf("s/%s/rest/wlangroup/%s", site, d.ID), d, &respBody) + err := c.Put(ctx, 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{} + return nil, NotFoundError } new := respBody.Data[0]