File: client_device.go

package info (click to toggle)
golang-github-koofr-go-koofrclient 0.0~git20190724.8e5366d-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 136 kB
  • sloc: makefile: 5
file content (84 lines) | stat: -rw-r--r-- 1,968 bytes parent folder | download | duplicates (2)
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
package koofrclient

import (
	"github.com/koofr/go-httpclient"
	"net/http"
)

func (c *KoofrClient) Devices() (devices []Device, err error) {
	d := &struct {
		Devices *[]Device
	}{&devices}

	request := httpclient.RequestData{
		Method:         "GET",
		Path:           "/api/v2/devices",
		ExpectedStatus: []int{http.StatusOK},
		RespEncoding:   httpclient.EncodingJSON,
		RespValue:      &d,
	}

	_, err = c.Request(&request)

	return
}

func (c *KoofrClient) DevicesCreate(name string, provider DeviceProvider) (device Device, err error) {
	deviceCreate := DeviceCreate{name, provider}

	request := httpclient.RequestData{
		Method:         "POST",
		Path:           "/api/v2/devices",
		ExpectedStatus: []int{http.StatusCreated},
		ReqEncoding:    httpclient.EncodingJSON,
		ReqValue:       deviceCreate,
		RespEncoding:   httpclient.EncodingJSON,
		RespValue:      &device,
	}

	_, err = c.Request(&request)

	return
}

func (c *KoofrClient) DevicesDetails(deviceId string) (device Device, err error) {
	request := httpclient.RequestData{
		Method:         "GET",
		Path:           "/api/v2/devices/" + deviceId,
		ExpectedStatus: []int{http.StatusOK},
		RespEncoding:   httpclient.EncodingJSON,
		RespValue:      &device,
	}

	_, err = c.Request(&request)

	return
}

func (c *KoofrClient) DevicesUpdate(deviceId string, deviceUpdate DeviceUpdate) (err error) {
	request := httpclient.RequestData{
		Method:         "PUT",
		Path:           "/api/v2/devices/" + deviceId,
		ExpectedStatus: []int{http.StatusNoContent},
		ReqEncoding:    httpclient.EncodingJSON,
		ReqValue:       deviceUpdate,
		RespConsume:    true,
	}

	_, err = c.Request(&request)

	return
}

func (c *KoofrClient) DevicesDelete(deviceId string) (err error) {
	request := httpclient.RequestData{
		Method:         "DELETE",
		Path:           "/api/v2/devices/" + deviceId,
		ExpectedStatus: []int{http.StatusNoContent},
		RespConsume:    true,
	}

	_, err = c.Request(&request)

	return
}