Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ConnectionRequest.go « octoprintApis - github.com/Z-Bolt/OctoScreen.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 49b4e15a028c6d7b91c39cdfea9deb44913108db (plain)
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
package octoprintApis

import (
	// "bytes"
	"encoding/json"
	// "io"

	"github.com/Z-Bolt/OctoScreen/logger"
	"github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels"
)


// ConnectionRequest Retrieve the current connection settings, including
// information regarding the available baudrates and serial ports and the
// current connection state.
type ConnectionRequest struct{}

// Do sends an API request and returns the API response.
func (cmd *ConnectionRequest) Do(client *Client) (*dataModels.ConnectionResponse, error) {
	logger.TraceEnter("ConnectionRequest.Do()")

	bytes, err := client.doJsonRequest("GET", ConnectionApiUri, nil, nil)
	if err != nil {
		logger.LogError("ConnectionRequest.Do()", "client.doJsonRequest(GET)", err)
		logger.TraceLeave("ConnectionRequest.Do()")
		return nil, err
	}

	response := &dataModels.ConnectionResponse{}
	if err := json.Unmarshal(bytes, response); err != nil {
		logger.LogError("ConnectionRequest.Do()", "json.Unmarshal()", err)
		logger.TraceLeave("ConnectionRequest.Do()")
		return nil, err
	}

	logger.TraceLeave("ConnectionRequest.Do()")
	return response, err
}