aboutsummaryrefslogtreecommitdiff
path: root/api/telegram/bot
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2021-03-14 22:51:01 +0700
committerShulhan <ms@kilabit.info>2021-03-14 22:51:46 +0700
commit25fb633ee6ab446917af8dcd2f9b303e85a13c98 (patch)
tree7e4b3aff5593498e31270c241e5a749a54f69ca8 /api/telegram/bot
parente7552ad0189f761875bc1c2ca3dd716d43a01e0d (diff)
downloadpakakeh.go-25fb633ee6ab446917af8dcd2f9b303e85a13c98.tar.xz
all: refactoring http.Client methods signature
Previously, parameters to method Delete, Get, Post, PostForm, PostFormData, PostJSON, Put, and PutJSON are in the following order: (headers, path, params) This is sometimes confusing. To make it better and works with format of HTTP request header, METHOD PATH HEADERS PARAMS we move the path to the first parameter and headers as the second parameter, so the call to client methods would be (path, headers, params)
Diffstat (limited to 'api/telegram/bot')
-rw-r--r--api/telegram/bot/bot.go15
1 files changed, 7 insertions, 8 deletions
diff --git a/api/telegram/bot/bot.go b/api/telegram/bot/bot.go
index 35c0c14d..844a8c25 100644
--- a/api/telegram/bot/bot.go
+++ b/api/telegram/bot/bot.go
@@ -138,7 +138,7 @@ func New(opts Options) (bot *Bot, err error) {
// getUpdates. Returns True on success. Requires no parameters.
//
func (bot *Bot) DeleteWebhook() (err error) {
- _, resBody, err := bot.client.PostForm(nil, methodDeleteWebhook, nil)
+ _, resBody, err := bot.client.PostForm(methodDeleteWebhook, nil, nil)
if err != nil {
return fmt.Errorf("DeleteWebhook: %w", err)
}
@@ -158,7 +158,7 @@ func (bot *Bot) DeleteWebhook() (err error) {
// Returns basic information about the bot in form of a User object.
//
func (bot *Bot) GetMe() (user *User, err error) {
- _, resBody, err := bot.client.Get(nil, methodGetMe, nil)
+ _, resBody, err := bot.client.Get(methodGetMe, nil, nil)
if err != nil {
return nil, fmt.Errorf("GetMe: %w", err)
}
@@ -179,7 +179,7 @@ func (bot *Bot) GetMe() (user *User, err error) {
// GetMyCommands get the current list of the bot's commands.
//
func (bot *Bot) GetMyCommands() (cmds []Command, err error) {
- _, resBody, err := bot.client.Get(nil, methodGetMyCommands, nil)
+ _, resBody, err := bot.client.Get(methodGetMyCommands, nil, nil)
if err != nil {
return nil, fmt.Errorf("GetMyCommands: %w", err)
}
@@ -201,7 +201,7 @@ func (bot *Bot) GetMyCommands() (cmds []Command, err error) {
// If the bot is using getUpdates, will return an object with the url field
// empty.
func (bot *Bot) GetWebhookInfo() (webhookInfo *WebhookInfo, err error) {
- _, resBody, err := bot.client.Get(nil, methodGetWebhookInfo, nil)
+ _, resBody, err := bot.client.Get(methodGetWebhookInfo, nil, nil)
if err != nil {
return nil, fmt.Errorf("GetWebhookInfo: %w", err)
}
@@ -231,7 +231,7 @@ func (bot *Bot) SendMessage(parent *Message, parseMode, text string) (
ParseMode: parseMode,
}
- _, resBody, err := bot.client.PostJSON(nil, methodSendMessage, req)
+ _, resBody, err := bot.client.PostJSON(methodSendMessage, nil, req)
if err != nil {
return nil, fmt.Errorf("SendMessage: %w", err)
}
@@ -267,8 +267,7 @@ func (bot *Bot) SetMyCommands(cmds []Command) (err error) {
bot.commands.Commands = cmds
- _, resBody, err := bot.client.PostJSON(nil, methodSetMyCommands,
- &bot.commands)
+ _, resBody, err := bot.client.PostJSON(methodSetMyCommands, nil, &bot.commands)
if err != nil {
return fmt.Errorf("SetMyCommands: %w", err)
}
@@ -332,7 +331,7 @@ func (bot *Bot) setWebhook() (err error) {
params[paramNameAllowedUpdates] = allowedUpdates
}
- _, resBody, err := bot.client.PostFormData(nil, methodSetWebhook, params)
+ _, resBody, err := bot.client.PostFormData(methodSetWebhook, nil, params)
if err != nil {
return fmt.Errorf("setWebhook: %w", err)
}