Skip to content

Commit

Permalink
chat: add some BuildRequestContext methods for backwards compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
  • Loading branch information
zchee committed Feb 24, 2022
1 parent 1645ac2 commit a0029c9
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions chat.go
Expand Up @@ -291,7 +291,11 @@ type sendConfig struct {
deleteOriginal bool
}

func (t sendConfig) BuildRequest(ctx context.Context, token, channelID string) (req *http.Request, _ func(*chatResponseFull) responseParser, err error) {
func (t sendConfig) BuildRequest(token, channelID string) (req *http.Request, _ func(*chatResponseFull) responseParser, err error) {
return t.BuildRequestContext(context.Background(), token, channelID)
}

func (t sendConfig) BuildRequestContext(ctx context.Context, token, channelID string) (req *http.Request, _ func(*chatResponseFull) responseParser, err error) {
if t, err = applyMsgOptions(token, channelID, t.apiurl, t.options...); err != nil {
return nil, nil, err
}
Expand All @@ -306,9 +310,9 @@ func (t sendConfig) BuildRequest(ctx context.Context, token, channelID string) (
responseType: t.responseType,
replaceOriginal: t.replaceOriginal,
deleteOriginal: t.deleteOriginal,
}.BuildRequest(ctx)
}.BuildRequestContext(ctx)
default:
return formSender{endpoint: t.endpoint, values: t.values}.BuildRequest(ctx)
return formSender{endpoint: t.endpoint, values: t.values}.BuildRequestContext(ctx)
}
}

Expand All @@ -317,7 +321,11 @@ type formSender struct {
values url.Values
}

func (t formSender) BuildRequest(ctx context.Context) (*http.Request, func(*chatResponseFull) responseParser, error) {
func (t formSender) BuildRequest() (*http.Request, func(*chatResponseFull) responseParser, error) {
return t.BuildRequestContext(context.Background())
}

func (t formSender) BuildRequestContext(ctx context.Context) (*http.Request, func(*chatResponseFull) responseParser, error) {
req, err := formReq(ctx, t.endpoint, t.values)
return req, func(resp *chatResponseFull) responseParser {
return newJSONParser(resp)
Expand All @@ -334,7 +342,11 @@ type responseURLSender struct {
deleteOriginal bool
}

func (t responseURLSender) BuildRequest(ctx context.Context) (*http.Request, func(*chatResponseFull) responseParser, error) {
func (t responseURLSender) BuildRequest() (*http.Request, func(*chatResponseFull) responseParser, error) {
return t.BuildRequestContext(context.Background())
}

func (t responseURLSender) BuildRequestContext(ctx context.Context) (*http.Request, func(*chatResponseFull) responseParser, error) {
req, err := jsonReq(ctx, t.endpoint, Msg{
Text: t.values.Get("text"),
Timestamp: t.values.Get("ts"),
Expand Down

0 comments on commit a0029c9

Please sign in to comment.