-
Notifications
You must be signed in to change notification settings - Fork 3
/
file.go
67 lines (57 loc) · 1.85 KB
/
file.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
package yousign
import (
"encoding/json"
"net/http"
"time"
)
type FileService struct {
client *Client
}
type File struct {
ID *string `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Type *string `json:"type,omitempty"`
ContentType *string `json:"contentType,omitempty"`
Description *string `json:"description,omitempty"`
CreatedAt *time.Time `json:"createdAt,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
Metadata json.RawMessage `json:"metadata,omitempty"`
Company *string `json:"company,omitempty"`
Creator *string `json:"creator,omitempty"`
}
type FileRequest struct {
Name *string `json:"name,omitempty"`
Type *string `json:"type,omitempty"`
Password *string `json:"password,omitempty"`
Description *string `json:"description,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
Content *string `json:"content,omitempty"`
Procedure *string `json:"procedure,omitempty"`
}
func (s *FileService) Create(r *FileRequest) (*File, *http.Response, error) {
req, err := s.client.NewRequest("POST", "files", nil, r)
if err != nil {
return nil, nil, err
}
var f File
resp, err := s.client.Do(req, &f)
return &f, resp, err
}
func (s *FileService) Get(id string) (*File, *http.Response, error) {
req, err := s.client.NewRequest("GET", id, nil, nil)
if err != nil {
return nil, nil, err
}
var f File
resp, err := s.client.Do(req, &f)
return &f, resp, err
}
func (s *FileService) Download(id string) (*string, *http.Response, error) {
req, err := s.client.NewRequest("GET", id+"/download", nil, nil)
if err != nil {
return nil, nil, err
}
var data string
resp, err := s.client.Do(req, &data)
return &data, resp, err
}