-
Notifications
You must be signed in to change notification settings - Fork 1
/
requests.go
68 lines (56 loc) · 1.42 KB
/
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
package tsremote
import "errors"
type Request struct {
Type string `json:"type"`
Payload interface{} `json:"payload"`
}
func (app *RemoteApp) sendJson(eventType string, payload interface{}) error {
if app.c == nil {
return errors.New("not connected")
}
if !app.authorized {
return errors.New("not authorized")
}
return app.c.WriteJSON(Request{
Type: eventType,
Payload: payload,
})
}
type ButtonPressPayload struct {
Button string `json:"button"`
State bool `json:"state"`
}
func (app *RemoteApp) SendButtonPress(button string, state bool) error {
payload := ButtonPressPayload{
Button: button,
State: state,
}
return app.sendJson("buttonPress", payload)
}
type AuthRequestPayload struct {
Identifier string `json:"identifier"`
Version string `json:"version"`
Name string `json:"name"`
Description string `json:"description"`
Content struct {
ApiKey string `json:"apiKey"`
} `json:"content"`
}
func (app *RemoteApp) SendAuthRequest(identifier, version, name, description string) error {
if app.c == nil {
return errors.New("not connected")
}
payload := AuthRequestPayload{
Identifier: identifier,
Version: version,
Name: name,
Description: description,
Content: struct {
ApiKey string `json:"apiKey"`
}(struct{ ApiKey string }{ApiKey: app.apiKeyProvider.GetApiKey()}),
}
return app.c.WriteJSON(Request{
Type: "auth",
Payload: payload,
})
}