-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice_group.go
100 lines (86 loc) · 2.74 KB
/
service_group.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package manifold
import (
"encoding/json"
"fmt"
"net/url"
"time"
)
// GroupService provides methods for interacting with groups,
// including retrieving a list of groups, getting details of a specific group by slug or ID.
type GroupService struct {
client *Client
}
// Groups retrieves a list of groups based on optional filtering criteria.
//
// Parameters:
// - beforeTime: Only return groups created before this timestamp. Optional.
// - availableToUserID: Filter groups that are available to the specified user ID. Optional.
//
// Returns:
// - []Group: A slice of groups matching the specified criteria.
// - error: An error object if the request fails or if the response cannot be parsed.
func (s *GroupService) Groups(beforeTime *time.Time, availableToUserID *string) ([]Group, error) {
params := make(map[string]string, 2)
if beforeTime != nil {
params["beforeTime"] = fmt.Sprintf("%d", beforeTime.UnixMilli())
}
if availableToUserID != nil {
params["availableToUserID"] = *availableToUserID
}
result, err := s.client.GET(
"/groups", params,
)
if err != nil {
return nil, fmt.Errorf("Group: Groups: %w: %w", ErrorGETFailed, err)
}
groups := make([]Group, 0)
err = json.Unmarshal(result, &groups)
if err != nil {
return nil, fmt.Errorf("Group: Groups: %w: %w", ErrorFailedToParseResponse, err)
}
return groups, nil
}
// Group retrieves the details of a specific group using its slug.
//
// Parameters:
// - slug: The slug of the group to retrieve. Required.
//
// Returns:
// - *Group: A pointer to the retrieved group object.
// - error: An error object if the request fails or if the response cannot be parsed.
func (s *GroupService) Group(slug string) (*Group, error) {
result, err := s.client.GET(
fmt.Sprintf("/group/%s", url.PathEscape(slug)), nil,
)
if err != nil {
return nil, fmt.Errorf("Group: Group: %w: %w", ErrorGETFailed, err)
}
group := new(Group)
err = json.Unmarshal(result, group)
if err != nil {
return nil, fmt.Errorf("Group: Group: %w: %w", ErrorFailedToParseResponse, err)
}
return group, nil
}
// ID retrieves the details of a specific group using its ID.
//
// Parameters:
// - id: The ID of the group to retrieve. Required.
//
// Returns:
// - *Group: A pointer to the retrieved group object.
// - error: An error object if the request fails or if the response cannot be parsed.
func (s *GroupService) ID(id string) (*Group, error) {
result, err := s.client.GET(
fmt.Sprintf("/group/by-id/%s", url.PathEscape(id)), nil,
)
if err != nil {
return nil, fmt.Errorf("Group: ID: %w: %w", ErrorGETFailed, err)
}
group := new(Group)
err = json.Unmarshal(result, group)
if err != nil {
return nil, fmt.Errorf("Group: ID: %w: %w", ErrorFailedToParseResponse, err)
}
return group, nil
}