FixUnlinkedURL() (and improve HasUnlinkedURL())

This commit is contained in:
Ian Gulliver
2021-09-19 06:49:00 +00:00
parent 5b2f3d5d3e
commit 034108a785
4 changed files with 157 additions and 9 deletions

View File

@@ -116,14 +116,26 @@ func (c *Client) get(path string, values *url.Values, out interface{}) error {
}
func (c *Client) post(path string, body interface{}, out interface{}) error {
return c.doWithBody("POST", path, body, out)
}
func (c *Client) put(path string, body interface{}, out interface{}) error {
return c.doWithBody("PUT", path, body, out)
}
func (c *Client) doWithBody(method string, path string, body interface{}, out interface{}) error {
url := fmt.Sprintf("%s%s", baseURL, path)
enc, err := json.Marshal(body)
buf := &bytes.Buffer{}
enc := json.NewEncoder(buf)
enc.SetEscapeHTML(false)
err := enc.Encode(body)
if err != nil {
return err
}
req, err := http.NewRequest("POST", url, bytes.NewReader(enc))
req, err := http.NewRequest(method, url, buf)
if err != nil {
return err
}

View File

@@ -44,11 +44,11 @@ type Tag struct {
}
type Task struct {
GID string `json:"gid"`
Name string `json:"name"`
DueOn string `json:"due_on"`
GID string `json:"gid,omitempty"`
Name string `json:"name,omitempty"`
DueOn string `json:"due_on,omitempty"`
ParsedDueOn *civil.Date `json:"-"`
HTMLNotes string `json:"html_notes"`
HTMLNotes string `json:"html_notes,omitempty"`
ParsedHTMLNotes *html.Node `json:"-"`
}
@@ -94,6 +94,10 @@ type tagsResponse struct {
Data []*Tag `json:"data"`
}
type taskResponse struct {
Data *Task `json:"data"`
}
type tasksResponse struct {
Data []*Task `json:"data"`
}
@@ -102,6 +106,10 @@ type userResponse struct {
Data *User `json:"data"`
}
type taskUpdate struct {
Data *Task `json:"data"`
}
func (wc *WorkspaceClient) GetMe() (*User, error) {
resp := &userResponse{}
err := wc.client.get("users/me", nil, resp)
@@ -303,6 +311,24 @@ func (wc *WorkspaceClient) Search(q *SearchQuery) ([]*Task, error) {
return resp.Data, nil
}
func (wc *WorkspaceClient) UpdateTask(task *Task) error {
path := fmt.Sprintf("tasks/%s", task.GID)
task.GID = ""
update := &taskUpdate{
Data: task,
}
resp := &taskResponse{}
err := wc.client.put(path, update, resp)
if err != nil {
return err
}
return nil
}
func (p *Project) String() string {
return fmt.Sprintf("%s (%s)", p.GID, p.Name)
}