-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathmain.go
121 lines (104 loc) · 3.1 KB
/
main.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT
package main
import (
"context"
"fmt"
"os"
api "github.com/deepgram/deepgram-go-sdk/pkg/api/manage/v1"
interfaces "github.com/deepgram/deepgram-go-sdk/pkg/api/manage/v1/interfaces"
client "github.com/deepgram/deepgram-go-sdk/pkg/client/manage"
)
func main() {
// init library
client.InitWithDefault()
// context
ctx := context.Background()
//client
dg := client.NewWithDefaults()
mgClient := api.New(dg)
// list projects
respList, err := mgClient.ListProjects(ctx)
if err != nil {
fmt.Printf("ListProjects failed. Err: %v\n", err)
os.Exit(1)
}
var projectID string
for _, item := range respList.Projects {
projectID = item.ProjectID
name := item.Name
fmt.Printf("ListProjects() - Name: %s, ID: %s\n", name, projectID)
break
}
// list invitations
respGet, err := mgClient.ListInvitations(ctx, projectID)
if err != nil {
fmt.Printf("ListInvitations failed. Err: %v\n", err)
os.Exit(1)
}
if len(respGet.Invites) == 0 {
fmt.Printf("ListInvitations() - No invitations found\n")
} else {
for _, item := range respGet.Invites {
id := item.Email
scope := item.Scope
fmt.Printf("ListInvitations() - ID: %s, Scope: %s\n", id, scope)
}
}
// send invite
respMessage, err := mgClient.SendInvitation(ctx, projectID, &interfaces.InvitationRequest{
Email: "[email protected]",
Scope: "member",
})
if err != nil {
fmt.Printf("SendInvitation failed. Err: %v\n", err)
os.Exit(1)
}
fmt.Printf("SendInvitation() - Result: %s\n", respMessage.Message)
// list invitations
respGet, err = mgClient.ListInvitations(ctx, projectID)
if err != nil {
fmt.Printf("ListInvitations failed. Err: %v\n", err)
os.Exit(1)
}
if len(respGet.Invites) == 0 {
fmt.Printf("ListInvitations() - No invitations found\n")
} else {
for _, item := range respGet.Invites {
id := item.Email
scope := item.Scope
fmt.Printf("ListInvitations() - ID: %s, Scope: %s\n", id, scope)
}
}
// delete invitation
respMessage, err = mgClient.DeleteInvitation(ctx, projectID, "[email protected]")
if err != nil {
fmt.Printf("DeleteInvitation failed. Err: %v\n", err)
os.Exit(1)
}
fmt.Printf("DeleteInvitation() - Result: %s\n", respMessage.Message)
// list invitations
respGet, err = mgClient.ListInvitations(ctx, projectID)
if err != nil {
fmt.Printf("ListInvitations failed. Err: %v\n", err)
os.Exit(1)
}
if len(respGet.Invites) == 0 {
fmt.Printf("ListInvitations() - No invitations found\n")
} else {
for _, item := range respGet.Invites {
id := item.Email
scope := item.Scope
fmt.Printf("ListInvitations() - ID: %s, Scope: %s\n", id, scope)
}
}
// There isnt an API call to add a member to a project. So will leave this commented out as an example
// Leave Project
// respMessage, err = mgClient.LeaveProject(ctx, projectID)
// if err != nil {
// fmt.Printf("LeaveProject failed. Err: %v\n", err)
// os.Exit(1)
// }
// fmt.Printf("LeaveProject() - Name: %s\n", respMessage.Message)
}