-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.go
162 lines (136 loc) · 5.11 KB
/
messages.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package connector
import (
"encoding/json"
"time"
"github.com/connctd/connector-go/connctd"
)
// Possible step types:
const (
StepText StepType = 1
StepMarkdown StepType = 2
StepRedirect StepType = 3
)
// InstallationState reflects the current state of an installation.
type InstallationState int
// Valid installations states:
const (
InstallationStateInitialized InstallationState = 1
InstallationStateComplete InstallationState = 2
InstallationStateOngoing InstallationState = 3
InstallationStateFailed InstallationState = 4
)
// InstallationRequest sent by connctd in order to signalise a new installation.
type InstallationRequest struct {
ID string `json:"id"`
Token InstallationToken `json:"token"`
State InstallationState `json:"state"`
Configuration []Configuration `json:"configuration"`
}
// GetConfig returns the configuration parameter with the given ID.
// If the parameter was not found it returns false.
func (i *InstallationRequest) GetConfig(id string) (*Configuration, bool) {
for _, c := range i.Configuration {
if c.ID == id {
return &c, true
}
}
return nil, false
}
// InstallationStateUpdateRequest can be sent by a connector to indicate new state.
type InstallationStateUpdateRequest struct {
State InstallationState `json:"state"`
Details json.RawMessage `json:"details,omitempty"`
}
// InstallationResponse defines the optional response to an installation request.
type InstallationResponse struct {
Details json.RawMessage `json:"details,omitempty"`
FurtherStep Step `json:"furtherStep,omitempty"`
}
// InstantiationState reflects the current state of an instantiation.
type InstantiationState int
// Valid instantiations states:
const (
InstantiationStateInitialized InstantiationState = 1
InstantiationStateComplete InstantiationState = 2
InstantiationStateOngoing InstantiationState = 3
InstantiationStateFailed InstantiationState = 4
)
// InstantiationRequest sent by connctd in order to signalise a new instantiation.
type InstantiationRequest struct {
ID string `json:"id"`
InstallationID string `json:"installation_id"`
Token InstantiationToken `json:"token"`
State InstantiationState `json:"state"`
Configuration []Configuration `json:"configuration"`
}
// GetConfig returns the configuration parameter with the given ID.
// If the parameter was not found it returns false.
func (i *InstantiationRequest) GetConfig(id string) (*Configuration, bool) {
for _, c := range i.Configuration {
if c.ID == id {
return &c, true
}
}
return nil, false
}
// InstantiationResponse defines the optional response to an instantiation request.
type InstantiationResponse struct {
Details json.RawMessage `json:"details,omitempty"`
FurtherStep Step `json:"furtherStep,omitempty"`
}
// InstanceStateUpdateRequest can be sent by a connector to indicate a new state.
type InstanceStateUpdateRequest struct {
State InstantiationState `json:"state"`
Details json.RawMessage `json:"details,omitempty"`
}
// StepType defines the type of a further installation or instantiation step.
type StepType int
// Step defines a further installation or instantiation step
type Step struct {
Type StepType `json:"type"`
Content string `json:"content"`
}
// AddThingRequest is used to create a new thing on the connctd platform.
type AddThingRequest struct {
Thing connctd.Thing `json:"thing"`
}
// AddThingResponse describes the response sent by connctd when thing creation was successful.
type AddThingResponse struct {
ID string `json:"id"`
}
// UpdateThingPropertyValueRequest can be used to propagate a new property value.
type UpdateThingPropertyValueRequest struct {
Value string `json:"value"`
LastUpdate time.Time `json:"lastUpdate"`
}
// UpdateThingStatusRequest allows updating the status of a thing.
type UpdateThingStatusRequest struct {
Status connctd.StatusType `json:"status"`
}
// ActionRequest is sent by connctd platform in order to trigger an action.
type ActionRequest struct {
ID string `json:"id"`
ThingID string `json:"thingId"`
ComponentID string `json:"componentId"`
ActionID string `json:"actionId"`
Status ActionRequestStatus `json:"status"`
Parameters map[string]string `json:"parameters"`
}
// ActionRequestStatus indicates the status of an action request.
type ActionRequestStatus string
const (
ActionRequestStatusPending ActionRequestStatus = "PENDING"
ActionRequestStatusCompleted ActionRequestStatus = "COMPLETED"
ActionRequestStatusFailed ActionRequestStatus = "FAILED"
ActionRequestStatusCanceled ActionRequestStatus = "CANCELED"
)
// ActionResponse can be sent in order to inform about the state of an action.
type ActionResponse struct {
Status ActionRequestStatus `json:"status"`
Error string `json:"error"`
}
// ActionRequestStatusUpdate allows a connector to update the status of an action.
type ActionRequestStatusUpdate struct {
Status ActionRequestStatus `json:"status"`
Error string `json:"error"`
}