TaskByOwnerAndName fetches a single task by its owner and name.
(ctx context.Context, owner, ident string)
| 221 | |
| 222 | // TaskByOwnerAndName fetches a single task by its owner and name. |
| 223 | func (c *Client) TaskByOwnerAndName(ctx context.Context, owner, ident string) (Task, error) { |
| 224 | if owner == "" { |
| 225 | owner = Me |
| 226 | } |
| 227 | res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/tasks/%s/%s", owner, ident), nil) |
| 228 | if err != nil { |
| 229 | return Task{}, err |
| 230 | } |
| 231 | defer res.Body.Close() |
| 232 | if res.StatusCode != http.StatusOK { |
| 233 | return Task{}, ReadBodyAsError(res) |
| 234 | } |
| 235 | |
| 236 | var task Task |
| 237 | if err := json.NewDecoder(res.Body).Decode(&task); err != nil { |
| 238 | return Task{}, err |
| 239 | } |
| 240 | |
| 241 | return task, nil |
| 242 | } |
| 243 | |
| 244 | func splitTaskIdentifier(identifier string) (owner string, taskName string, err error) { |
| 245 | parts := strings.Split(identifier, "/") |