Skip to content

Commit

Permalink
add close task method
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Neznaykin committed Apr 20, 2023
1 parent cce49e0 commit 7d14261
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
10 changes: 7 additions & 3 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,19 @@ func (s *Session) SetCookie(v string) {
}

func (s *Session) doGet(path string, params interface{}, resp interface{}) error {
return s.doRaw("GET", path, params, nil, resp)
return s.doRaw(http.MethodGet, path, params, nil, resp)
}

func (s *Session) doPost(path string, data, v interface{}) error {
return s.doRaw("POST", path, nil, data, v)
return s.doRaw(http.MethodPost, path, nil, data, v)
}

func (s *Session) doDelete(path string, resp interface{}) error {
return s.doRaw("DELETE", path, nil, nil, resp)
return s.doRaw(http.MethodDelete, path, nil, nil, resp)
}

func (s *Session) doPut(path string, data, v interface{}) error {
return s.doRaw(http.MethodPut, path, nil, nil, v)
}

func (s *Session) doRaw(method, path string, params, data, v interface{}) error {
Expand Down
24 changes: 23 additions & 1 deletion v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package tdclient

import (
"fmt"
"io"

"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/tada-team/tdproto"
"github.com/tada-team/tdproto/tdapi"
"io"
)

func (s *Session) Ping() error {
Expand Down Expand Up @@ -240,6 +241,27 @@ func (s *Session) CreateTask(teamUid string, req tdapi.Task) (tdproto.Chat, erro
return resp.Result, nil
}

func (s *Session) CloseTask(teamUid, taskUid string) (tdproto.Chat, error) {
resp := new(struct {
tdapi.Resp
Result tdproto.Chat `json:"result"`
})

req := map[string]interface{}{
"task_status": "done",
}

if err := s.doPut(fmt.Sprintf("/api/v4/teams/%s/tasks/%s", teamUid, taskUid), req, resp); err != nil {
return resp.Result, err
}

if !resp.Ok {
return resp.Result, errors.Wrap(resp.Error, "")
}

return resp.Result, nil
}

// FIXME: move to tdapi
type tdapiTeam struct {
Name string `json:"name"`
Expand Down

0 comments on commit 7d14261

Please sign in to comment.