-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpipe.go
52 lines (47 loc) · 1.28 KB
/
pipe.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
package hop
import (
"context"
"net/url"
"go.hop.io/sdk/types"
)
// GetAll is used to get all rooms associated with a pipe.
func (c ClientCategoryPipeRooms) GetAll(ctx context.Context, opts ...ClientOption) ([]*types.Room, error) {
if c.c.getProjectId(opts) == "" && c.c.getTokenType() != "ptk" {
return nil, types.InvalidToken("project ID must be specified when using bearer authentication to get rooms")
}
var rooms []*types.Room
err := c.c.do(ctx, ClientArgs{
Method: "GET",
Path: "/pipe/rooms",
ResultKey: "rooms",
Result: &rooms,
}, opts)
if err != nil {
return nil, err
}
return rooms, nil
}
// Create is used to create a room.
func (c ClientCategoryPipeRooms) Create(
ctx context.Context, opts types.RoomCreationOptions, clientOpts ...ClientOption,
) (*types.Room, error) {
var room types.Room
err := c.c.do(ctx, ClientArgs{
Method: "POST",
Path: "/pipe/rooms",
ResultKey: "room",
Result: &room,
Body: opts,
}, clientOpts)
if err != nil {
return nil, err
}
return &room, nil
}
// Delete is used to delete a room.
func (c ClientCategoryPipeRooms) Delete(ctx context.Context, id string, opts ...ClientOption) error {
return c.c.do(ctx, ClientArgs{
Method: "DELETE",
Path: "/pipe/rooms/" + url.PathEscape(id),
}, opts)
}