-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrackable_requests.go
126 lines (106 loc) · 2.74 KB
/
trackable_requests.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright (c) Omlox Client Go Contributors
// SPDX-License-Identifier: MIT
package omlox
import (
"context"
"net/http"
"github.com/google/uuid"
)
// TrackablesAPI is a simple wrapper around the client for trackables requests.
type TrackablesAPI struct {
client *Client
}
// List lists all trackables.
func (c *TrackablesAPI) List(ctx context.Context) ([]Trackable, error) {
requestPath := "/trackables/summary"
return sendRequestParseResponseList[Trackable](
ctx,
c.client,
http.MethodGet,
requestPath,
nil, // request body
nil, // request query parameters
nil, // request headers
)
}
// IDs lists all trackable IDs.
func (c *TrackablesAPI) IDs(ctx context.Context) ([]uuid.UUID, error) {
requestPath := "/trackables"
return sendRequestParseResponseList[uuid.UUID](
ctx,
c.client,
http.MethodGet,
requestPath,
nil, // request body
nil, // request query parameters
nil, // request headers
)
}
// Create creates a trackable.
func (c *TrackablesAPI) Create(ctx context.Context, trackable Trackable) (*Trackable, error) {
requestPath := "/trackables"
return sendStructuredRequestParseResponse[Trackable](
ctx,
c.client,
http.MethodPost,
requestPath,
trackable,
nil, // request query parameters
nil, // request headers
)
}
// DeleteAll deletes all trackables.
func (c *TrackablesAPI) DeleteAll(ctx context.Context) error {
requestPath := "/trackables"
_, err := sendRequestParseResponse[struct{}](
ctx,
c.client,
http.MethodDelete,
requestPath,
nil, // request body
nil, // request query parameters
nil, // request headers
)
return err
}
// Get gets a trackable.
func (c *TrackablesAPI) Get(ctx context.Context, id uuid.UUID) (*Trackable, error) {
requestPath := "/trackables/" + id.String()
return sendRequestParseResponse[Trackable](
ctx,
c.client,
http.MethodGet,
requestPath,
nil, // request body
nil, // request query parameters
nil, // request headers
)
}
// Delete deletes a trackable.
func (c *TrackablesAPI) Delete(ctx context.Context, id uuid.UUID) error {
requestPath := "/trackables/" + id.String()
_, err := sendRequestParseResponse[struct{}](
ctx,
c.client,
http.MethodDelete,
requestPath,
nil, // request body
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) {
requestPath := "/trackables/" + id.String() + "/location"
return sendRequestParseResponse[Location](
ctx,
c.client,
http.MethodGet,
requestPath,
nil, // request body
nil, // request query parameters
nil, // request headers
)
}