/
chat_api_version_handler.go
106 lines (99 loc) · 3.03 KB
/
chat_api_version_handler.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
// Copyright 2016 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package client
import (
"io"
"golang.org/x/net/context"
)
type ChatAPIVersionHandler struct {
handler ChatAPIHandler
}
func NewChatAPIVersionHandler(h ChatAPIHandler) *ChatAPIVersionHandler {
return &ChatAPIVersionHandler{
handler: h,
}
}
func (d *ChatAPIVersionHandler) handle(ctx context.Context, c Call, w io.Writer) error {
switch c.Params.Version {
case 0, 1:
return d.handleV1(ctx, c, w)
default:
return ErrInvalidVersion{version: c.Params.Version}
}
}
func (d *ChatAPIVersionHandler) handleV1(ctx context.Context, c Call, w io.Writer) error {
switch c.Method {
case methodList:
return d.handler.ListV1(ctx, c, w)
case methodRead:
return d.handler.ReadV1(ctx, c, w)
case methodSend:
return d.handler.SendV1(ctx, c, w)
case methodGet:
return d.handler.GetV1(ctx, c, w)
case methodEdit:
return d.handler.EditV1(ctx, c, w)
case methodReaction:
return d.handler.ReactionV1(ctx, c, w)
case methodDelete:
return d.handler.DeleteV1(ctx, c, w)
case methodAttach:
return d.handler.AttachV1(ctx, c, w)
case methodDownload:
return d.handler.DownloadV1(ctx, c, w)
case methodSetStatus:
return d.handler.SetStatusV1(ctx, c, w)
case methodMark:
return d.handler.MarkV1(ctx, c, w)
case methodSearchInbox:
return d.handler.SearchInboxV1(ctx, c, w)
case methodSearchRegexp:
return d.handler.SearchRegexpV1(ctx, c, w)
case methodNewConv:
return d.handler.NewConvV1(ctx, c, w)
case methodListConvsOnName:
return d.handler.ListConvsOnNameV1(ctx, c, w)
case methodJoin:
return d.handler.JoinV1(ctx, c, w)
case methodLeave:
return d.handler.LeaveV1(ctx, c, w)
case methodAddToChannel:
return d.handler.AddToChannelV1(ctx, c, w)
case methodRemoveFromChannel:
return d.handler.RemoveFromChannelV1(ctx, c, w)
case methodLoadFlip:
return d.handler.LoadFlipV1(ctx, c, w)
case methodGetUnfurlSettings:
return d.handler.GetUnfurlSettingsV1(ctx, c, w)
case methodSetUnfurlSettings:
return d.handler.SetUnfurlSettingsV1(ctx, c, w)
case methodAdvertiseCommands:
return d.handler.AdvertiseCommandsV1(ctx, c, w)
case methodClearCommands:
return d.handler.ClearCommandsV1(ctx, c, w)
case methodListCommands:
return d.handler.ListCommandsV1(ctx, c, w)
case methodPin:
return d.handler.PinV1(ctx, c, w)
case methodUnpin:
return d.handler.UnpinV1(ctx, c, w)
case methodGetResetConvMembers:
return d.handler.GetResetConvMembersV1(ctx, c, w)
case methodAddResetConvMember:
return d.handler.AddResetConvMemberV1(ctx, c, w)
case methodGetDeviceInfo:
return d.handler.GetDeviceInfoV1(ctx, c, w)
case methodListMembers:
return d.handler.ListMembersV1(ctx, c, w)
case methodEmojiAdd:
return d.handler.EmojiAddV1(ctx, c, w)
case methodEmojiAddAlias:
return d.handler.EmojiAddAliasV1(ctx, c, w)
case methodEmojiList:
return d.handler.EmojiListV1(ctx, c, w)
case methodEmojiRemove:
return d.handler.EmojiRemoveV1(ctx, c, w)
default:
return ErrInvalidMethod{name: c.Method, version: 1}
}
}