-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare.go
150 lines (134 loc) · 3.24 KB
/
prepare.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package scrive
import (
"fmt"
"net/http"
)
type NewDocumentParams struct {
FileName string
File []byte
Saved *bool
}
func (c *Client) NewDocument(p NewDocumentParams) (*Document, *ScriveError) {
doc := &Document{}
_, se := c.pwe(
"documents/new",
func(req *request) {
req.writeMFile("file", p.FileName, p.File)
req.writeMBool("saved", p.Saved)
},
http.StatusCreated,
doc,
)
return doc, se
}
type NewDocumentFromTemplateParams struct {
DocumentID string
ObjectVersion *uint64
}
func (c *Client) NewDocumentFromTemplate(p NewDocumentFromTemplateParams) (*Document, *ScriveError) {
doc := &Document{}
_, se := c.pwe(
fmt.Sprintf("documents/newfromtemplate/%s", p.DocumentID),
func(req *request) {
req.writeMUInt("object_version", p.ObjectVersion)
},
http.StatusCreated,
doc,
)
return doc, se
}
type CloneDocumentParams struct {
DocumentID string
ObjectVersion *uint64
}
func (c *Client) CloneDocument(p CloneDocumentParams) (*Document, *ScriveError) {
doc := &Document{}
_, se := c.pwe(
fmt.Sprintf("documents/%s/clone", p.DocumentID),
func(req *request) {
req.writeMUInt("object_version", p.ObjectVersion)
},
http.StatusCreated,
doc,
)
return doc, se
}
type UpdateDocumentParams struct {
DocumentID string
Document *Document
ObjectVersion *uint64
}
func (c *Client) UpdateDocument(p UpdateDocumentParams) (*Document, *ScriveError) {
doc := &Document{}
_, se := c.pw(
fmt.Sprintf("documents/%s/update", p.DocumentID),
func(req *request) {
req.writeMJSON("document", p.Document)
req.writeMUInt("object_version", p.ObjectVersion)
},
doc,
)
return doc, se
}
type SetAttachment struct {
Name string `json:"name"`
Required bool `json:"required"`
AddToSealedFile bool `json:"add_to_sealed_file"`
FileParam string `json:"file_param"`
FileName string `json:"-"`
File []byte `json:"-"`
}
type SetAttachmentsParams struct {
DocumentID string
Attachments []*SetAttachment
Incremental *bool
ObjectVersion *uint64
}
func (c *Client) SetAttachments(p SetAttachmentsParams) (*Document, *ScriveError) {
doc := &Document{}
_, se := c.pw(
fmt.Sprintf("documents/%s/setattachments", p.DocumentID),
func(req *request) {
req.writeMJSON("attachments", p.Attachments)
req.writeMBool("incremental", p.Incremental)
req.writeMUInt("object_version", p.ObjectVersion)
for _, a := range p.Attachments {
req.writeMFile(a.FileParam, a.FileName, a.File)
}
},
doc,
)
return doc, se
}
type RemovePagesParams struct {
DocumentID string
Pages []uint64
ObjectVersion *uint64
}
func (c *Client) RemovePages(p RemovePagesParams) (*Document, *ScriveError) {
doc := &Document{}
_, se := c.pw(
fmt.Sprintf("documents/%s/removepages", p.DocumentID),
func(req *request) {
req.writeMJSON("pages", p.Pages)
req.writeMUInt("object_version", p.ObjectVersion)
},
doc,
)
return doc, se
}
type StartParams struct {
DocumentID string
ObjectVersion *uint64
}
func (c *Client) Start(p StartParams) (*Document, *ScriveError) {
doc := &Document{}
_, se := c.pw(
fmt.Sprintf("documents/%s/start", p.DocumentID),
func(req *request) {
req.writeMUInt("object_version", p.ObjectVersion)
},
doc,
)
return doc, se
}