-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
share.go
36 lines (32 loc) · 780 Bytes
/
share.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
package room
import (
"encoding/json"
"net/http"
"github.com/monaco-io/request"
"gomod.garykim.dev/nc-talk/constants"
"gomod.garykim.dev/nc-talk/ocs"
)
// ShareFile shares the file at the given path with the talk room
func (t *TalkRoom) ShareFile(path string) (string, error) {
req := t.User.RequestClient(request.Client{
URL: constants.FilesSharingEndpoint + "shares",
Params: map[string]string{
"shareType": ocs.ShareTypeRoom,
"path": path,
"shareWith": t.Token,
},
})
resp, err := req.Do()
if err != nil {
return "", err
}
if resp.StatusCode() != http.StatusOK {
return "", ErrUnexpectedReturnCode
}
data := &ocs.ShareReturn{}
err = json.Unmarshal(resp.Data, data)
if err != nil {
return "", err
}
return data.OCS.Data.URL, nil
}