(ctx context.Context, args GroupArguments)
| 86 | } |
| 87 | |
| 88 | func (c *Client) Groups(ctx context.Context, args GroupArguments) ([]Group, error) { |
| 89 | qp := url.Values{} |
| 90 | if args.Organization != "" { |
| 91 | qp.Set("organization", args.Organization) |
| 92 | } |
| 93 | if args.HasMember != "" { |
| 94 | qp.Set("has_member", args.HasMember) |
| 95 | } |
| 96 | if len(args.GroupIDs) > 0 { |
| 97 | idStrs := make([]string, 0, len(args.GroupIDs)) |
| 98 | for _, id := range args.GroupIDs { |
| 99 | idStrs = append(idStrs, id.String()) |
| 100 | } |
| 101 | qp.Set("group_ids", strings.Join(idStrs, ",")) |
| 102 | } |
| 103 | |
| 104 | res, err := c.Request(ctx, http.MethodGet, |
| 105 | fmt.Sprintf("/api/v2/groups?%s", qp.Encode()), |
| 106 | nil, |
| 107 | ) |
| 108 | if err != nil { |
| 109 | return nil, xerrors.Errorf("make request: %w", err) |
| 110 | } |
| 111 | defer res.Body.Close() |
| 112 | |
| 113 | if res.StatusCode != http.StatusOK { |
| 114 | return nil, ReadBodyAsError(res) |
| 115 | } |
| 116 | |
| 117 | var groups []Group |
| 118 | return groups, json.NewDecoder(res.Body).Decode(&groups) |
| 119 | } |
| 120 | |
| 121 | func (c *Client) GroupByOrgAndName(ctx context.Context, orgID uuid.UUID, name string) (Group, error) { |
| 122 | res, err := c.Request(ctx, http.MethodGet, |
no test coverage detected