forked from jonaswouters/go-doccle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument.go
More file actions
68 lines (59 loc) · 2.05 KB
/
Copy pathdocument.go
File metadata and controls
68 lines (59 loc) · 2.05 KB
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
package main
import (
"io"
"os"
"strings"
)
type (
DocumentsResult struct {
HasMore bool `json:"hasMore"`
NextPage int `json:"nextPage"`
NumberOfPages int `json:"numberOfPages"`
PageIndex int `json:"pageIndex"`
PageSize int `json:"pageSize"`
PreviousPage interface{} `json:"previousPage"`
Results int `json:"results"`
SortField string `json:"sortField"`
SortFieldType string `json:"sortFieldType"`
SortOrder string `json:"sortOrder"`
TotalResults int `json:"totalResults"`
Documents []Document `json:"documents"`
}
Document struct {
Actions []Action `json:"actions"`
CanOpen bool `json:"canOpen"`
Categories []string `json:"categories"`
ContentURL string `json:"contentUrl"`
Name string `json:"name"`
Opened bool `json:"opened"`
Payment interface{} `json:"payment"`
PresentationType string `json:"presentationType"`
PublishDate string `json:"publishDate"`
Sender Sender `json:"sender"`
SenderDocumentType string `json:"senderDocumentType"`
ShortName interface{} `json:"shortName"`
URI string `json:"uri"`
}
)
// Download the document's file
func (document Document) Download(configuration Configuration, path string, filename string) (int64, error) {
var resp = DoRequest(configuration, document.ContentURL, "GET")
defer resp.Body.Close()
out, err := os.Create(strings.Join([]string{path, filename}, ""))
defer out.Close()
if err != nil {
return 0, err
}
n, err := io.Copy(out, resp.Body)
return n, err
}
// Archive the document
func (document Document) Archive(configuration Configuration) {
for _, action := range document.Actions {
if action.Label == "ARCHIVE" && action.Enabled {
// This is very trustworthy at the moment...
var resp = DoRequest(configuration, action.URL, action.Method)
defer resp.Body.Close()
}
}
}