FindDials retrieves a list of dials based on a filter. Only returns dials that the user owns or is a member of. Also returns a count of total matching dials which may different from the number of returned dials if the "Limit" field is set.
(ctx context.Context, filter wtf.DialFilter)
| 361 | // dials which may different from the number of returned dials if the |
| 362 | // "Limit" field is set. |
| 363 | func (s *DialService) FindDials(ctx context.Context, filter wtf.DialFilter) ([]*wtf.Dial, int, error) { |
| 364 | // Marshal filter into JSON format. |
| 365 | body, err := json.Marshal(filter) |
| 366 | if err != nil { |
| 367 | return nil, 0, err |
| 368 | } |
| 369 | |
| 370 | // Create request with API key. |
| 371 | req, err := s.Client.newRequest(ctx, "GET", "/dials", bytes.NewReader(body)) |
| 372 | if err != nil { |
| 373 | return nil, 0, err |
| 374 | } |
| 375 | |
| 376 | // Issue request. Any non-200 status code is considered an error. |
| 377 | resp, err := http.DefaultClient.Do(req) |
| 378 | if err != nil { |
| 379 | return nil, 0, err |
| 380 | } else if resp.StatusCode != http.StatusOK { |
| 381 | return nil, 0, parseResponseError(resp) |
| 382 | } |
| 383 | defer resp.Body.Close() |
| 384 | |
| 385 | // Unmarshal result set of dials & total dial count. |
| 386 | var jsonResponse findDialsResponse |
| 387 | if err := json.NewDecoder(resp.Body).Decode(&jsonResponse); err != nil { |
| 388 | return nil, 0, err |
| 389 | } |
| 390 | return jsonResponse.Dials, jsonResponse.N, nil |
| 391 | } |
| 392 | |
| 393 | // CreateDial creates a new dial and assigns the current user as the owner. |
| 394 | // The owner will automatically be added as a member of the new dial. |