generated from mattermost/mattermost-plugin-starter-template
/
cmd_debug_stop_watch.go
58 lines (50 loc) · 1.4 KB
/
cmd_debug_stop_watch.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
package function
import (
"github.com/pkg/errors"
"google.golang.org/api/calendar/v3"
"github.com/mattermost/mattermost-plugin-apps/apps"
)
var debugStopWatch = Command{
Name: "stop-watch",
Description: "Stop Google watch with the internal IDs",
BaseForm: &apps.Form{
Title: "debug stop watch",
Fields: []apps.Field{
{
Name: fID,
Type: apps.FieldTypeText,
Description: "Google channel ID (aka subscription ID, also see Channel)",
IsRequired: true,
},
{
Name: fResourceID,
Type: apps.FieldTypeText,
Description: "Google resource ID (see Channel)",
IsRequired: true,
},
},
Submit: &apps.Call{
Expand: &apps.Expand{
OAuth2User: apps.ExpandAll,
OAuth2App: apps.ExpandAll,
},
},
},
Handler: RequireGoogleAuth(
func(creq CallRequest) apps.CallResponse {
id := creq.GetValue(fID, "")
resourceID := creq.GetValue(fResourceID, "")
calService, err := calendar.NewService(creq.ctx, creq.authOption)
if err != nil {
return apps.NewErrorResponse(errors.Wrap(err, "failed to get Calendar client to Google"))
}
err = calService.Channels.Stop(&calendar.Channel{
Id: id,
ResourceId: resourceID,
}).Do()
if err != nil {
return apps.NewErrorResponse(errors.Wrap(err, "failed to stop Google watch"))
}
return RespondWithJSON(creq, "Successfully unsubscribed: "+id, nil)
}),
}