-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdialog_gen.go
98 lines (85 loc) · 2.46 KB
/
dialog_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
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)
// DialogOpenCall is created by DialogService.Open method call
type DialogOpenCall struct {
service *DialogService
dialog *objects.Dialog
trigger_id string
}
// Open creates a DialogOpenCall object in preparation for accessing the dialog.open endpoint
func (s *DialogService) Open(dialog *objects.Dialog, trigger_id string) *DialogOpenCall {
var call DialogOpenCall
call.service = s
call.dialog = dialog
call.trigger_id = trigger_id
return &call
}
// ValidateArgs checks that all required fields are set in the DialogOpenCall object
func (c *DialogOpenCall) ValidateArgs() error {
if c.dialog == nil {
return errors.New(`required field dialog not initialized`)
}
if len(c.trigger_id) <= 0 {
return errors.New(`required field trigger_id not initialized`)
}
return nil
}
// Values returns the DialogOpenCall object as url.Values
func (c *DialogOpenCall) 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)
dialogEncoded, err := c.dialog.Encode()
if err != nil {
return nil, errors.Wrap(err, `failed to encode field`)
}
v.Set("dialog", dialogEncoded)
v.Set("trigger_id", c.trigger_id)
return v, nil
}
// Do executes the call to access dialog.open endpoint
func (c *DialogOpenCall) Do(ctx context.Context) (*objects.DialogResponse, error) {
const endpoint = "dialog.open"
v, err := c.Values()
if err != nil {
return nil, err
}
var res struct {
objects.GenericResponse
*objects.DialogResponse
}
if err := c.service.client.postForm(ctx, endpoint, v, &res); err != nil {
return nil, errors.Wrap(err, `failed to post to dialog.open`)
}
if !res.OK {
return nil, errors.New(res.Error.String())
}
return res.DialogResponse, nil
}
// FromValues parses the data in v and populates `c`
func (c *DialogOpenCall) FromValues(v url.Values) error {
var tmp DialogOpenCall
if raw := strings.TrimSpace(v.Get("dialog")); len(raw) > 0 {
if err := tmp.dialog.Decode(raw); err != nil {
return errors.Wrap(err, `failed to decode value "dialog"`)
}
}
if raw := strings.TrimSpace(v.Get("trigger_id")); len(raw) > 0 {
tmp.trigger_id = raw
}
*c = tmp
return nil
}