1
1
package knock
2
2
3
3
import (
4
+ "bytes"
4
5
"context"
6
+ "encoding/json"
5
7
"fmt"
6
8
"github.com/pkg/errors"
7
9
"net/http"
@@ -58,11 +60,28 @@ type ProviderAuthCheckResponse struct {
58
60
type ProviderListChannelsRequest struct {
59
61
ProviderContext `json:"-"`
60
62
AccessTokenObject ProviderAccessTokenObject `json:"access_token_object"`
61
- // TODO: query_options
63
+ SlackQueryOptions * SlackQueryOptions `json:" query_options,omitempty"`
62
64
}
63
65
64
66
type ProviderListChannelsResponse struct {
65
- // TODO:
67
+ SlackChannels []SlackChannel `json:"slack_channels"`
68
+ NextCursor string `json:"next_cursor"`
69
+ }
70
+
71
+ type SlackQueryOptions struct {
72
+ Cursor string `json:"cursor,omitempty"`
73
+ ExcludeArchived bool `json:"exclude_archived,omitempty"`
74
+ Limit int `json:"limit,omitempty"`
75
+ TeamId string `json:"team_id,omitempty"`
76
+ Types string `json:"types,omitempty"`
77
+ }
78
+
79
+ type SlackChannel struct {
80
+ ID string `json:"id"`
81
+ Name string `json:"name"`
82
+ IsPrivate bool `json:"is_private"`
83
+ IsIM bool `json:"is_im"`
84
+ ContextTeamId string `json:"context_team_id"`
66
85
}
67
86
68
87
type ProviderRevokeAccessRequest struct {
@@ -78,7 +97,12 @@ func (ps providersService) AuthCheck(ctx context.Context, request *ProviderAuthC
78
97
path := providersAPIPath (request .ProviderName , request .ChannelId )
79
98
path = fmt .Sprintf ("%s/auth_check" , path )
80
99
81
- req , err := ps .client .newRequest (http .MethodGet , path , nil , nil )
100
+ raw , err := json .Marshal (request )
101
+ if err != nil {
102
+ return nil , errors .Wrap (err , "error creating body for provider auth check" )
103
+ }
104
+
105
+ req , err := ps .client .newRequest (http .MethodGet , path , bytes .NewBuffer (raw ), nil )
82
106
if err != nil {
83
107
return nil , errors .Wrap (err , "error creating request for provider auth check" )
84
108
}
@@ -96,11 +120,46 @@ func (ps providersService) ListChannels(ctx context.Context, request *ProviderLi
96
120
path := providersAPIPath (request .ProviderName , request .ChannelId )
97
121
path = fmt .Sprintf ("%s/channels" , path )
98
122
99
- //TODO implement me
100
- panic ("implement me" )
123
+ raw , err := json .Marshal (request )
124
+ if err != nil {
125
+ return nil , errors .Wrap (err , "error creating body for provider list channels" )
126
+ }
127
+
128
+ req , err := ps .client .newRequest (http .MethodGet , path , bytes .NewBuffer (raw ), nil )
129
+ if err != nil {
130
+ return nil , errors .Wrap (err , "error creating request for provider list channels" )
131
+ }
132
+
133
+ listChannelsResponse := & ProviderListChannelsResponse {}
134
+ _ , err = ps .client .do (ctx , req , listChannelsResponse )
135
+ if err != nil {
136
+ return nil , errors .Wrap (err , "error making request for provider list channels" )
137
+ }
138
+
139
+ return listChannelsResponse , nil
101
140
}
102
141
103
142
func (ps providersService ) RevokeAccess (ctx context.Context , request * ProviderRevokeAccessRequest ) (bool , error ) {
104
- //TODO implement me
105
- panic ("implement me" )
143
+ path := providersAPIPath (request .ProviderName , request .ChannelId )
144
+ path = fmt .Sprintf ("%s/revoke_access" , path )
145
+
146
+ raw , err := json .Marshal (request )
147
+ if err != nil {
148
+ return false , errors .Wrap (err , "error creating body for provider revoke access" )
149
+ }
150
+
151
+ req , err := ps .client .newRequest (http .MethodGet , path , bytes .NewBuffer (raw ), nil )
152
+ if err != nil {
153
+ return false , errors .Wrap (err , "error creating request for provider revoke access" )
154
+ }
155
+
156
+ revokeAccessResponse := struct {
157
+ Ok bool `json:"ok"`
158
+ }{}
159
+ _ , err = ps .client .do (ctx , req , revokeAccessResponse )
160
+ if err != nil {
161
+ return false , errors .Wrap (err , "error making request for provider revoke access" )
162
+ }
163
+
164
+ return revokeAccessResponse .Ok , nil
106
165
}
0 commit comments