/
devices.go
57 lines (51 loc) · 1.49 KB
/
devices.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
package torchprint
import (
"strconv"
"time"
)
// Device a printing device
type Device struct {
Identifier string `json:"Identifier"`
Name string `json:"Name"`
Description string `json:"Description"`
Make string `json:"Make"`
Model string `json:"Model"`
Capabilities struct {
DuplexSupported bool `json:"DuplexSupported"`
ColorSupported bool `json:"ColorSupported"`
} `json:"Capabilities"`
Server string `json:"Server"`
DeviceGroups []string `json:"DeviceGroups"`
Active bool `json:"Active"`
LastModified time.Time `json:"LastModified"`
Location string `json:"Location"`
}
// DevicesResponseData is response of devices request
type DevicesResponseData struct {
PreviousPageLink string `json:"PreviousPageLink"`
NextPageLink string `json:"NextPageLink"`
Count int `json:"Count"`
Items []Device `json:"Items"`
}
// GetDevices gets printing devices
func (api *API) GetDevices(skip, pageSize int) (*DevicesResponseData, error) {
params := pagedRequest{
Skip: skip,
PageSize: pageSize,
}
var respData DevicesResponseData
_, err := api.GetJSON("devices", params, &respData)
if err != nil {
return nil, err
}
return &respData, nil
}
// GetDevice gets info about a printing device
func (api *API) GetDevice(deviceID int) (*Device, error) {
var respData Device
_, err := api.GetJSON("devices/"+strconv.Itoa(deviceID), nil, &respData)
if err != nil {
return nil, err
}
return &respData, nil
}