-
Notifications
You must be signed in to change notification settings - Fork 19
/
users_profile_gen.go
221 lines (191 loc) · 5.55 KB
/
users_profile_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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
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)
// UsersProfileGetCall is created by UsersProfileService.Get method call
type UsersProfileGetCall struct {
service *UsersProfileService
includeLabels bool
user string
}
// UsersProfileSetCall is created by UsersProfileService.Set method call
type UsersProfileSetCall struct {
service *UsersProfileService
name string
profile *objects.UserProfile
user string
value string
}
// Get creates a UsersProfileGetCall object in preparation for accessing the users.profile.get endpoint
func (s *UsersProfileService) Get() *UsersProfileGetCall {
var call UsersProfileGetCall
call.service = s
return &call
}
// IncludeLabels sets the value for optional includeLabels parameter
func (c *UsersProfileGetCall) IncludeLabels(includeLabels bool) *UsersProfileGetCall {
c.includeLabels = includeLabels
return c
}
// User sets the value for optional user parameter
func (c *UsersProfileGetCall) User(user string) *UsersProfileGetCall {
c.user = user
return c
}
// ValidateArgs checks that all required fields are set in the UsersProfileGetCall object
func (c *UsersProfileGetCall) ValidateArgs() error {
return nil
}
// Values returns the UsersProfileGetCall object as url.Values
func (c *UsersProfileGetCall) 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.includeLabels {
v.Set("include_labels", "true")
}
if len(c.user) > 0 {
v.Set("user", c.user)
}
return v, nil
}
// Do executes the call to access users.profile.get endpoint
func (c *UsersProfileGetCall) Do(ctx context.Context) (*objects.UserProfile, error) {
const endpoint = "users.profile.get"
v, err := c.Values()
if err != nil {
return nil, err
}
var res struct {
objects.GenericResponse
*objects.UserProfile
}
if err := c.service.client.postForm(ctx, endpoint, v, &res); err != nil {
return nil, errors.Wrap(err, `failed to post to users.profile.get`)
}
if !res.OK {
return nil, errors.New(res.Error.String())
}
return res.UserProfile, nil
}
// FromValues parses the data in v and populates `c`
func (c *UsersProfileGetCall) FromValues(v url.Values) error {
var tmp UsersProfileGetCall
if raw := strings.TrimSpace(v.Get("include_labels")); len(raw) > 0 {
parsed, err := strconv.ParseBool(raw)
if err != nil {
return errors.Wrap(err, `failed to parse boolean value "include_labels"`)
}
tmp.includeLabels = parsed
}
if raw := strings.TrimSpace(v.Get("user")); len(raw) > 0 {
tmp.user = raw
}
*c = tmp
return nil
}
// Set creates a UsersProfileSetCall object in preparation for accessing the users.profile.set endpoint
func (s *UsersProfileService) Set() *UsersProfileSetCall {
var call UsersProfileSetCall
call.service = s
return &call
}
// Name sets the value for optional name parameter
func (c *UsersProfileSetCall) Name(name string) *UsersProfileSetCall {
c.name = name
return c
}
// Profile sets the value for optional profile parameter
func (c *UsersProfileSetCall) Profile(profile *objects.UserProfile) *UsersProfileSetCall {
c.profile = profile
return c
}
// User sets the value for optional user parameter
func (c *UsersProfileSetCall) User(user string) *UsersProfileSetCall {
c.user = user
return c
}
// Value sets the value for optional value parameter
func (c *UsersProfileSetCall) Value(value string) *UsersProfileSetCall {
c.value = value
return c
}
// ValidateArgs checks that all required fields are set in the UsersProfileSetCall object
func (c *UsersProfileSetCall) ValidateArgs() error {
return nil
}
// Values returns the UsersProfileSetCall object as url.Values
func (c *UsersProfileSetCall) 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 len(c.name) > 0 {
v.Set("name", c.name)
}
if c.profile != nil {
profileEncoded, err := c.profile.Encode()
if err != nil {
return nil, errors.Wrap(err, `failed to encode field`)
}
v.Set("profile", profileEncoded)
}
if len(c.user) > 0 {
v.Set("user", c.user)
}
if len(c.value) > 0 {
v.Set("value", c.value)
}
return v, nil
}
// Do executes the call to access users.profile.set endpoint
func (c *UsersProfileSetCall) Do(ctx context.Context) (*objects.UserProfile, error) {
const endpoint = "users.profile.set"
v, err := c.Values()
if err != nil {
return nil, err
}
var res struct {
objects.GenericResponse
*objects.UserProfile
}
if err := c.service.client.postForm(ctx, endpoint, v, &res); err != nil {
return nil, errors.Wrap(err, `failed to post to users.profile.set`)
}
if !res.OK {
return nil, errors.New(res.Error.String())
}
return res.UserProfile, nil
}
// FromValues parses the data in v and populates `c`
func (c *UsersProfileSetCall) FromValues(v url.Values) error {
var tmp UsersProfileSetCall
if raw := strings.TrimSpace(v.Get("name")); len(raw) > 0 {
tmp.name = raw
}
if raw := strings.TrimSpace(v.Get("profile")); len(raw) > 0 {
if err := tmp.profile.Decode(raw); err != nil {
return errors.Wrap(err, `failed to decode value "profile"`)
}
}
if raw := strings.TrimSpace(v.Get("user")); len(raw) > 0 {
tmp.user = raw
}
if raw := strings.TrimSpace(v.Get("value")); len(raw) > 0 {
tmp.value = raw
}
*c = tmp
return nil
}