Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Following is the current checklist of the implemented schemas and API methods.
| DELETE | `/trackables` | ✅ |
| GET | `/trackables/:trackableID` | ✅ |
| DELETE | `/trackables/:trackableID` | ✅ |
| PUT | `/trackables/:trackableID` | |
| PUT | `/trackables/:trackableID` | |
| GET | `/trackables/:trackableID/fences` | |
| GET | `/trackables/:trackableID/location` | ✅ |
| GET | `/trackables/:trackableID/locations` | |
Expand All @@ -203,7 +203,7 @@ Following is the current checklist of the implemented schemas and API methods.
| POST | `/providers` | ✅ |
| DELETE | `/providers` | ✅ |
| GET | `/providers/:providerID` | ✅ |
| PUT | `/providers/:providerID` | |
| PUT | `/providers/:providerID` | |
| DELETE | `/providers/:providerID` | ✅ |
| PUT | `/providers/:providerID/location` | |
| GET | `/providers/:providerID/location` | |
Expand Down
2 changes: 2 additions & 0 deletions cmd/omlox-cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Common actions for omlox client:
- omlox sub location_updates
- omlox get trackables -o json > backup.trackables.json
- omlox create trackables < backup.trackables.json
- omlox update trackables < backup.trackables.json

Environment variables:

Expand Down Expand Up @@ -53,6 +54,7 @@ func newRootCmd(out io.Writer, args []string) (*cobra.Command, error) {
newVersionCmd(out),
newGetCmd(*settings, out),
newCreateCmd(*settings, out),
newUpdateCmd(*settings, out),
newDeleteCmd(*settings, out),
newSubCmd(*settings, out),
newGenCmd(),
Expand Down
24 changes: 24 additions & 0 deletions cmd/omlox-cli/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Omlox Client Go Contributors
// SPDX-License-Identifier: MIT

package main

import (
"io"

"github.com/spf13/cobra"
"github.com/wavecomtech/omlox-client-go/internal/cli"
)

func newUpdateCmd(settings cli.EnvSettings, out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "update",
Aliases: []string{"set"},
Short: "Update hub resources",
}

cmd.AddCommand(newUpdateTrackablesCmd(settings, out))
cmd.AddCommand(newUpdateProvidersCmd(settings, out))

return cmd
}
79 changes: 79 additions & 0 deletions cmd/omlox-cli/update_providers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) Omlox Client Go Contributors
// SPDX-License-Identifier: MIT

package main

import (
"context"
"fmt"
"io"
"os"

"github.com/spf13/cobra"
"github.com/wavecomtech/omlox-client-go"
"github.com/wavecomtech/omlox-client-go/internal/cli"
"github.com/wavecomtech/omlox-client-go/internal/cli/resource"
)

const updateProviderHelp = `
This command updates location providers in the Omlox Hub.
`

func newUpdateProvidersCmd(settings cli.EnvSettings, out io.Writer) *cobra.Command {
var files []string

cmd := &cobra.Command{
Use: "providers",
Aliases: []string{"location_providers"},
Short: "Update location providers in the Hub",
Long: updateProviderHelp,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
var in []io.Reader

if len(files) > 0 {
for _, name := range files {
f, err := os.OpenFile(name, os.O_RDONLY, 0444)
if err != nil {
return err
}
defer f.Close()

in = append(in, f)
}
} else {
in = append(in, cmd.InOrStdin())
}

loader := resource.Loader[omlox.LocationProvider]{
Resources: make([]omlox.LocationProvider, 0),
}
for _, r := range in {
if err := loader.LoadJSON(r); err != nil {
return err
}
}

c, err := newOmloxClient(&settings)
if err != nil {
return err
}

for _, p := range loader.Resources {
err := c.Providers.Update(context.Background(), p, p.ID)
if err != nil {
return err
}

fmt.Fprintf(out, "updated: %v %v\n", p.ID, p.Name)
}

return nil
},
}

f := cmd.Flags()
f.StringArrayVarP(&files, "file", "f", []string{}, "The files that contain the location providers to update")

return cmd
}
78 changes: 78 additions & 0 deletions cmd/omlox-cli/update_trackables.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright (c) Omlox Client Go Contributors
// SPDX-License-Identifier: MIT

package main

import (
"context"
"fmt"
"io"
"os"

"github.com/spf13/cobra"
"github.com/wavecomtech/omlox-client-go"
"github.com/wavecomtech/omlox-client-go/internal/cli"
"github.com/wavecomtech/omlox-client-go/internal/cli/resource"
)

const updateTrackableHelp = `
This command updates trackables in the Omlox Hub.
`

func newUpdateTrackablesCmd(settings cli.EnvSettings, out io.Writer) *cobra.Command {
var files []string

cmd := &cobra.Command{
Use: "trackables",
Short: "Update trackables in the Hub",
Long: updateTrackableHelp,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
var in []io.Reader

if len(files) > 0 {
for _, name := range files {
f, err := os.OpenFile(name, os.O_RDONLY, 0444)
if err != nil {
return err
}
defer f.Close()

in = append(in, f)
}
} else {
in = append(in, cmd.InOrStdin())
}

loader := resource.Loader[omlox.Trackable]{
Resources: make([]omlox.Trackable, 0),
}
for _, r := range in {
if err := loader.LoadJSON(r); err != nil {
return err
}
}

c, err := newOmloxClient(&settings)
if err != nil {
return err
}

for _, t := range loader.Resources {
err := c.Trackables.Update(context.Background(), t, t.ID)
if err != nil {
return err
}

fmt.Fprintf(out, "updated: %v %v\n", t.ID, t.Name)
}

return nil
},
}

f := cmd.Flags()
f.StringArrayVarP(&files, "file", "f", []string{}, "The files that contain the trackables to update")

return cmd
}
2 changes: 2 additions & 0 deletions docs/cli/omlox.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Common actions for omlox client:
- omlox sub location_updates
- omlox get trackables -o json > backup.trackables.json
- omlox create trackables < backup.trackables.json
- omlox update trackables < backup.trackables.json

Environment variables:

Expand All @@ -35,5 +36,6 @@ Environment variables:
* [omlox gen](omlox_gen.md) - Generate commands
* [omlox get](omlox_get.md) - Get hub resources
* [omlox subscribe](omlox_subscribe.md) - Subscribes to real-time events
* [omlox update](omlox_update.md) - Update hub resources
* [omlox version](omlox_version.md) - Show version information

23 changes: 23 additions & 0 deletions docs/cli/omlox_update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## omlox update

Update hub resources

### Options

```
-h, --help help for update
```

### Options inherited from parent commands

```
--addr string omlox hub API endpoint (default "localhost:8081")
--debug enable debug logging
```

### SEE ALSO

* [omlox](omlox.md) - The Omlox Hub CLI tool
* [omlox update providers](omlox_update_providers.md) - Update location providers in the Hub
* [omlox update trackables](omlox_update_trackables.md) - Update trackables in the Hub

32 changes: 32 additions & 0 deletions docs/cli/omlox_update_providers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## omlox update providers

Update location providers in the Hub

### Synopsis


This command updates location providers in the Omlox Hub.


```
omlox update providers [flags]
```

### Options

```
-f, --file stringArray The files that contain the location providers to update
-h, --help help for providers
```

### Options inherited from parent commands

```
--addr string omlox hub API endpoint (default "localhost:8081")
--debug enable debug logging
```

### SEE ALSO

* [omlox update](omlox_update.md) - Update hub resources

32 changes: 32 additions & 0 deletions docs/cli/omlox_update_trackables.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## omlox update trackables

Update trackables in the Hub

### Synopsis


This command updates trackables in the Omlox Hub.


```
omlox update trackables [flags]
```

### Options

```
-f, --file stringArray The files that contain the trackables to update
-h, --help help for trackables
```

### Options inherited from parent commands

```
--addr string omlox hub API endpoint (default "localhost:8081")
--debug enable debug logging
```

### SEE ALSO

* [omlox update](omlox_update.md) - Update hub resources

1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ require (
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/tidwall/geojson v1.4.3
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
golang.org/x/time v0.4.0
nhooyr.io/websocket v1.8.10
)
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ github.com/tidwall/rtree v1.3.1 h1:xu3vJPKJrmGce7YJcFUCoqLrp9DTUEJBnVgdPSXHgHs=
github.com/tidwall/rtree v1.3.1/go.mod h1:S+JSsqPTI8LfWA4xHBo5eXzie8WJLVFeppAutSegl6M=
github.com/tidwall/sjson v1.2.4 h1:cuiLzLnaMeBhRmEv00Lpk3tkYrcxpmbU81tAY4Dw0tc=
github.com/tidwall/sjson v1.2.4/go.mod h1:098SZ494YoMWPmMO6ct4dcFnqxwj9r/gF0Etp19pSNM=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI=
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/time v0.4.0 h1:Z81tqI5ddIoXDPvVQ7/7CC9TnLM7ubaFG2qXYd5BbYY=
Expand Down
19 changes: 18 additions & 1 deletion provider_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (c *ProvidersAPI) DeleteAll(ctx context.Context) error {
return err
}

// Get gets a location providers.
// Get gets a location provider.
func (c *ProvidersAPI) Get(ctx context.Context, id string) (*LocationProvider, error) {
requestPath := "/providers/" + id

Expand All @@ -90,6 +90,23 @@ func (c *ProvidersAPI) Get(ctx context.Context, id string) (*LocationProvider, e
)
}

// Update updates a location provider.
func (c *ProvidersAPI) Update(ctx context.Context, provider LocationProvider, id string) error {
requestPath := "/providers/" + id

_, err := sendStructuredRequestParseResponse[struct{}](
ctx,
c.client,
http.MethodPut,
requestPath,
provider,
nil, // request query parameters
nil, // request headers
)

return err
}

// Delete deletes a location provider.
func (c *ProvidersAPI) Delete(ctx context.Context, id string) error {
requestPath := "/providers/" + id
Expand Down
17 changes: 17 additions & 0 deletions trackable_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ func (c *TrackablesAPI) Delete(ctx context.Context, id uuid.UUID) error {
return err
}

// Update updates a trackable.
func (c *TrackablesAPI) Update(ctx context.Context, trackable Trackable, id uuid.UUID) error {
requestPath := "/trackables/" + id.String()

_, err := sendStructuredRequestParseResponse[struct{}](
ctx,
c.client,
http.MethodPut,
requestPath,
trackable,
nil, // request query parameters
nil, // request headers
)

return err
}

// GetLocation gets the last most recent location for a trackable.
// It considers all recent location updates of the trackables location providers.
func (c *TrackablesAPI) GetLocation(ctx context.Context, id uuid.UUID) (*Location, error) {
Expand Down
Loading