-
Notifications
You must be signed in to change notification settings - Fork 1
/
files.go
42 lines (35 loc) · 1.31 KB
/
files.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
package gochatwork
import (
"fmt"
"net/url"
)
// GetFiles return /rooms/{room_id}/files response by []File
func (c *Client) GetFiles(roomID int64, accountID int64) ([]File, error) {
var files []File
b, err := c.GetFilesRaw(roomID, accountID)
err = setStructFromJSON(b, &files, err)
return files, err
}
// GetFilesRaw return /rooms/{room_id}/files response by []byte
func (c *Client) GetFilesRaw(roomID int64, accountID int64) ([]byte, error) {
params := url.Values{}
if accountID != 0 {
params.Add("account_id", fmt.Sprintf("%d", accountID))
}
return c.connection.Get(fmt.Sprintf("rooms/%d/files", roomID), params, c.config)
}
// GetSpecificFiles return /rooms/{room_id}/files/file_id response by File
func (c *Client) GetSpecificFiles(roomID int64, fileID int64, createDownloadURL bool) (File, error) {
var file File
b, err := c.GetSpecificFilesRaw(roomID, fileID, createDownloadURL)
err = setStructFromJSON(b, &file, err)
return file, err
}
// GetSpecificFilesRaw return /rooms/{room_id}/files/file_id response by []byte
func (c *Client) GetSpecificFilesRaw(roomID int64, fileID int64, createDownloadURL bool) ([]byte, error) {
params := url.Values{}
if createDownloadURL {
params.Add("create_download_url", "1")
}
return c.connection.Get(fmt.Sprintf("rooms/%d/files/%d", roomID, fileID), params, c.config)
}