-
-
Notifications
You must be signed in to change notification settings - Fork 4k
/
types.go
118 lines (103 loc) · 3.42 KB
/
types.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
package api
import (
"strconv"
"time"
)
// Time represents represents date and time information for Zoho
// Zoho uses milliseconds since unix epoch (Java currentTimeMillis)
type Time time.Time
// UnmarshalJSON turns JSON into a Time
func (t *Time) UnmarshalJSON(data []byte) error {
millis, err := strconv.ParseInt(string(data), 10, 64)
if err != nil {
return err
}
*t = Time(time.Unix(0, millis*int64(time.Millisecond)))
return nil
}
// User is a Zoho user we are only interested in the ZUID here
type User struct {
FirstName string `json:"First_Name"`
Email string `json:"Email"`
LastName string `json:"Last_Name"`
DisplayName string `json:"Display_Name"`
ZUID int64 `json:"ZUID"`
}
// TeamWorkspace represents a Zoho Team or workspace
// It's actually a VERY large json object that differs between
// Team and Workspace but we are only interested in some fields
// that both of them have so we can use the same struct for both
type TeamWorkspace struct {
ID string `json:"id"`
Attributes struct {
Name string `json:"name"`
Created Time `json:"created_time_in_millisecond"`
IsPart bool `json:"is_partof"`
} `json:"attributes"`
}
// TeamWorkspaceResponse is the response by the list teams api
type TeamWorkspaceResponse struct {
TeamWorkspace []TeamWorkspace `json:"data"`
}
// Item is may represent a file or a folder in Zoho Workdrive
type Item struct {
ID string `json:"id"`
Attributes struct {
Name string `json:"name"`
Type string `json:"type"`
IsFolder bool `json:"is_folder"`
CreatedTime Time `json:"created_time_in_millisecond"`
ModifiedTime Time `json:"modified_time_in_millisecond"`
UploadedTime Time `json:"uploaded_time_in_millisecond"`
StorageInfo struct {
Size int64 `json:"size_in_bytes"`
FileCount int64 `json:"files_count"`
FolderCount int64 `json:"folders_count"`
} `json:"storage_info"`
} `json:"attributes"`
}
// ItemInfo contains a single Zoho Item
type ItemInfo struct {
Item Item `json:"data"`
}
// ItemList contains multiple Zoho Items
type ItemList struct {
Items []Item `json:"data"`
}
// UploadInfo is a simplified and slightly different version of
// the Item struct only used in the response to uploads
type UploadInfo struct {
Attributes struct {
ParentID string `json:"parent_id"`
FileName string `json:"notes.txt"`
RessourceID string `json:"resource_id"`
} `json:"attributes"`
}
// UploadResponse is the response to a file Upload
type UploadResponse struct {
Uploads []UploadInfo `json:"data"`
}
// WriteMetadataRequest is is used to write metadata for a
// single item
type WriteMetadataRequest struct {
Data WriteMetadata `json:"data"`
}
// WriteMultiMetadataRequest can be used to write metadata for
// multiple items at once but we don't use it that way
type WriteMultiMetadataRequest struct {
Meta []WriteMetadata `json:"data"`
}
// WriteMetadata is used to write item metadata
type WriteMetadata struct {
Attributes WriteAttributes `json:"attributes,omitempty"`
ID string `json:"id,omitempty"`
Type string `json:"type"`
}
// WriteAttributes is used to set various attributes for on items
// this is used for Move, Copy, Delete, Rename
type WriteAttributes struct {
Name string `json:"name,omitempty"`
ParentID string `json:"parent_id,omitempty"`
RessourceID string `json:"resource_id,omitempty"`
Status string `json:"status,omitempty"`
}