-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathclient.go
97 lines (77 loc) · 2.31 KB
/
client.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
package teams_api
import (
"fmt"
"github.com/fossteams/teams-api/pkg/csa"
"github.com/fossteams/teams-api/pkg/models"
"github.com/fossteams/teams-api/pkg/mt"
"net/http"
)
import "github.com/fossteams/teams-api/pkg"
type TeamsClient struct {
httpClient *http.Client
chatSvc *csa.CSASvc
mtSvc *mt.Service
}
func (t *TeamsClient) Debug(debugFlag bool) {
t.chatSvc.DebugSave(debugFlag)
}
func (t *TeamsClient) ChatSvc() *csa.CSASvc {
return t.chatSvc
}
func New() (*TeamsClient, error) {
teamsClient := TeamsClient{}
// Get Skype Spaces Token
skypeSpaces, err := api.GetSkypeSpacesToken()
if err != nil {
return nil, fmt.Errorf("unable to get SkypeSpaces token: %v", err)
}
chatSvcToken, err := api.GetChatSvcAggToken()
if err != nil {
return nil, fmt.Errorf("unable to get chat service token: %v", err)
}
skypeToken, err := api.GetSkypeToken()
if err != nil {
return nil, err
}
teamsToken, err := api.GetTeamsToken()
if err != nil {
return nil, err
}
// Initialize Chat Service
csaSvc, err := csa.NewCSAService(chatSvcToken, skypeToken)
if err != nil {
return nil, fmt.Errorf("unable to init Chat Service")
}
teamsClient.chatSvc = csaSvc
// Initialize MT Service
mtSvc, err := mt.NewMiddleTierService(api.Emea, skypeSpaces, teamsToken)
if err != nil {
return nil, fmt.Errorf("unable to init MT Service: %v", err)
}
teamsClient.mtSvc = mtSvc
return &teamsClient, err
}
func (t *TeamsClient) GetConversations() (*models.ConversationResponse, error) {
return t.chatSvc.GetConversations()
}
func (t *TeamsClient) GetMessages(channel *models.Channel) ([]models.ChatMessage, error) {
return t.chatSvc.GetMessagesByChannel(channel)
}
func (t *TeamsClient) GetMe() (*models.User, error) {
return t.mtSvc.GetMe()
}
func (t *TeamsClient) FetchShortProfile(mris []string) ([]models.User, error) {
return t.mtSvc.FetchShortProfile(mris...)
}
func (t *TeamsClient) GetProfilePicture(emailOrId string) ([]byte, error) {
return t.mtSvc.GetProfilePicture(emailOrId)
}
func (t *TeamsClient) GetTeamsProfilePicture(emailOrId string) ([]byte, error) {
return t.mtSvc.GetTeamsProfilePicture(emailOrId)
}
func (t *TeamsClient) GetTenants() ([]models.Tenant, error) {
return t.mtSvc.GetTenants()
}
func (t *TeamsClient) GetPinnedChannels() ([]csa.ChannelId, error) {
return t.chatSvc.GetPinnedChannels()
}