-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathauth_gen.go
144 lines (124 loc) · 3.4 KB
/
auth_gen.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
package slack
// Auto-generated by internal/cmd/genmethods/genmethods.go. DO NOT EDIT!
import (
"context"
"net/url"
"strconv"
"strings"
"github.com/lestrrat-go/slack/objects"
"github.com/pkg/errors"
)
var _ = strconv.Itoa
var _ = strings.Index
var _ = objects.EpochTime(0)
// AuthRevokeCall is created by AuthService.Revoke method call
type AuthRevokeCall struct {
service *AuthService
test bool
}
// AuthTestCall is created by AuthService.Test method call
type AuthTestCall struct {
service *AuthService
}
// Revoke creates a AuthRevokeCall object in preparation for accessing the auth.revoke endpoint
func (s *AuthService) Revoke() *AuthRevokeCall {
var call AuthRevokeCall
call.service = s
return &call
}
// Test sets the value for optional test parameter
func (c *AuthRevokeCall) Test(test bool) *AuthRevokeCall {
c.test = test
return c
}
// ValidateArgs checks that all required fields are set in the AuthRevokeCall object
func (c *AuthRevokeCall) ValidateArgs() error {
return nil
}
// Values returns the AuthRevokeCall object as url.Values
func (c *AuthRevokeCall) Values() (url.Values, error) {
if err := c.ValidateArgs(); err != nil {
return nil, errors.Wrap(err, `failed validation`)
}
v := url.Values{}
v.Set(`token`, c.service.token)
if c.test {
v.Set("test", "true")
}
return v, nil
}
// Do executes the call to access auth.revoke endpoint
func (c *AuthRevokeCall) Do(ctx context.Context) error {
const endpoint = "auth.revoke"
v, err := c.Values()
if err != nil {
return err
}
var res struct {
objects.GenericResponse
}
if err := c.service.client.postForm(ctx, endpoint, v, &res); err != nil {
return errors.Wrap(err, `failed to post to auth.revoke`)
}
if !res.OK {
return errors.New(res.Error.String())
}
return nil
}
// FromValues parses the data in v and populates `c`
func (c *AuthRevokeCall) FromValues(v url.Values) error {
var tmp AuthRevokeCall
if raw := strings.TrimSpace(v.Get("test")); len(raw) > 0 {
parsed, err := strconv.ParseBool(raw)
if err != nil {
return errors.Wrap(err, `failed to parse boolean value "test"`)
}
tmp.test = parsed
}
*c = tmp
return nil
}
// Test creates a AuthTestCall object in preparation for accessing the auth.test endpoint
func (s *AuthService) Test() *AuthTestCall {
var call AuthTestCall
call.service = s
return &call
}
// ValidateArgs checks that all required fields are set in the AuthTestCall object
func (c *AuthTestCall) ValidateArgs() error {
return nil
}
// Values returns the AuthTestCall object as url.Values
func (c *AuthTestCall) Values() (url.Values, error) {
if err := c.ValidateArgs(); err != nil {
return nil, errors.Wrap(err, `failed validation`)
}
v := url.Values{}
v.Set(`token`, c.service.token)
return v, nil
}
// Do executes the call to access auth.test endpoint
func (c *AuthTestCall) Do(ctx context.Context) (*objects.AuthTestResponse, error) {
const endpoint = "auth.test"
v, err := c.Values()
if err != nil {
return nil, err
}
var res struct {
objects.GenericResponse
*objects.AuthTestResponse
}
if err := c.service.client.postForm(ctx, endpoint, v, &res); err != nil {
return nil, errors.Wrap(err, `failed to post to auth.test`)
}
if !res.OK {
return nil, errors.New(res.Error.String())
}
return res.AuthTestResponse, nil
}
// FromValues parses the data in v and populates `c`
func (c *AuthTestCall) FromValues(v url.Values) error {
var tmp AuthTestCall
*c = tmp
return nil
}