Skip to content

Commit e0b9a6c

Browse files
authored
add IoT 1-Click event (#371)
1 parent e5da494 commit e0b9a6c

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

events/iot_1_click.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
3+
package events
4+
5+
// IoTOneClickEvent represents a click event published by clicking button type
6+
// device.
7+
type IoTOneClickEvent struct {
8+
DeviceEvent IoTOneClickDeviceEvent `json:"deviceEvent"`
9+
DeviceInfo IoTOneClickDeviceInfo `json:"deviceInfo"`
10+
PlacementInfo IoTOneClickPlacementInfo `json:"placementInfo"`
11+
}
12+
13+
type IoTOneClickDeviceEvent struct {
14+
ButtonClicked IoTOneClickButtonClicked `json:"buttonClicked"`
15+
}
16+
17+
type IoTOneClickButtonClicked struct {
18+
ClickType string `json:"clickType"`
19+
ReportedTime string `json:"reportedTime"`
20+
}
21+
22+
type IoTOneClickDeviceInfo struct {
23+
Attributes map[string]string `json:"attributes"`
24+
Type string `json:"type"`
25+
DeviceID string `json:"deviceId"`
26+
RemainingLife float64 `json:"remainingLife"`
27+
}
28+
29+
type IoTOneClickPlacementInfo struct {
30+
ProjectName string `json:"projectName"`
31+
PlacementName string `json:"placementName"`
32+
Attributes map[string]string `json:"attributes"`
33+
Devices map[string]string `json:"devices"`
34+
}

events/iot_1_click_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
package events
3+
4+
import (
5+
"encoding/json"
6+
"testing"
7+
8+
"github.com/aws/aws-lambda-go/events/test"
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestIoTOneClickEventMalformedJson(t *testing.T) {
13+
14+
// 1. read JSON from file
15+
inputJson := test.ReadJSONFromFile(t, "./testdata/iot-1-click-event.json")
16+
17+
// 2. de-serialize into Go object
18+
var inputEvent IoTOneClickEvent
19+
if err := json.Unmarshal(inputJson, &inputEvent); err != nil {
20+
t.Errorf("could not unmarshal event. details: %v", err)
21+
}
22+
23+
// 3. serialize to JSON
24+
outputJson, err := json.Marshal(inputEvent)
25+
if err != nil {
26+
t.Errorf("could not marshal event. details: %v", err)
27+
}
28+
// 4. check result
29+
assert.JSONEq(t, string(inputJson), string(outputJson))
30+
}
31+
32+
func TestIoTOneClickEventMarshaling(t *testing.T) {
33+
test.TestMalformedJson(t, IoTOneClickEvent{})
34+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"deviceEvent": {
3+
"buttonClicked": {
4+
"clickType": "SINGLE",
5+
"reportedTime": "2018-05-04T23:26:33.747Z"
6+
}
7+
},
8+
"deviceInfo": {
9+
"attributes": {
10+
"key3": "value3",
11+
"key1": "value1",
12+
"key4": "value4"
13+
},
14+
"type": "button",
15+
"deviceId": "G030PMXXXXXXXXXX",
16+
"remainingLife": 5.00
17+
},
18+
"placementInfo": {
19+
"projectName": "test",
20+
"placementName": "myPlacement",
21+
"attributes": {
22+
"location": "Seattle",
23+
"equipment": "printer"
24+
},
25+
"devices": {
26+
"myButton": "G030PMXXXXXXXXXX"
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)