forked from tj/go-dropbox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsharing.go
179 lines (152 loc) · 4.85 KB
/
sharing.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package dropbox
import (
"encoding/json"
"time"
)
// Sharing client.
type Sharing struct {
*Client
}
// NewSharing client.
func NewSharing(config *Config) *Sharing {
return &Sharing{
Client: &Client{
Config: config,
},
}
}
// CreateSharedLinkInput request input.
type CreateSharedLinkInput struct {
Path string `json:"path"`
ShortURL bool `json:"short_url"`
}
// CreateSharedLinkOutput request output.
type CreateSharedLinkOutput struct {
URL string `json:"url"`
Path string `json:"path"`
VisibilityModel struct {
Tag VisibilityType `json:".tag"`
} `json:"visibility"`
Expires time.Time `json:"expires,omitempty"`
}
// VisibilityType determines who can access the link.
type VisibilityType string
// Visibility types supported.
const (
Public VisibilityType = "public"
TeamOnly = "team_only"
Password = "password"
TeamAndPassword = "team_and_password"
SharedFolderOnly = "shared_folder_only"
)
// CreateSharedLink returns a shared link.
func (c *Sharing) CreateSharedLink(in *CreateSharedLinkInput) (out *CreateSharedLinkOutput, err error) {
body, err := c.call("/sharing/create_shared_link", in)
if err != nil {
return
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}
// ListSharedFolderInput request input.
type ListSharedFolderInput struct {
Limit uint64 `json:"limit"`
Actions []FolderAction `json:"actions,omitempty"`
}
// FolderAction defines actions that may be taken on shared folders.
type FolderAction struct {
ChangeOptions string
}
// ListSharedFolderOutput lists metadata about shared folders with a cursor to retrieve the next page.
type ListSharedFolderOutput struct {
Entries []SharedFolderMetadata `json:"entries"`
Cursor string `json:"cursor"`
}
// ListSharedFolders returns the list of all shared folders the current user has access to.
func (c *Sharing) ListSharedFolders(in *ListSharedFolderInput) (out *ListSharedFolderOutput, err error) {
body, err := c.call("/sharing/list_folders", in)
if err != nil {
return
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}
// ListSharedFolderContinueInput request input.
type ListSharedFolderContinueInput struct {
Cursor string `json:"cursor"`
}
// ListSharedFoldersContinue returns the list of all shared folders the current user has access to.
func (c *Sharing) ListSharedFoldersContinue(in *ListSharedFolderContinueInput) (out *ListSharedFolderOutput, err error) {
body, err := c.call("/sharing/list_folders/continue", in)
if err != nil {
return
}
defer body.Close()
err = json.NewDecoder(body).Decode(&out)
return
}
// SharedFolderMetadata includes basic information about the shared folder.
type SharedFolderMetadata struct {
AccessType struct {
Tag AccessType `json:".tag"`
} `json:"access_type"`
IsTeamFolder bool `json:"is_team_folder"`
Policy FolderPolicy `json:"policy"`
Name string `json:"name"`
SharedFolderID string `json:"shared_folder_id"`
TimeInvited time.Time `json:"time_invited"`
OwnerTeam struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"owner_team"`
ParentSharedFolderID string `json:"parent_shared_folder_id"`
PathLower string `json:"path_lower"`
Permissions []string `json:"permissions"`
}
// FolderPolicy enumerates the policies governing this shared folder.
type FolderPolicy struct {
ACLUpdatePolicy struct {
Tag ACLUpdatePolicy `json:".tag"`
} `json:"acl_update_policy"`
SharedLinkPolicy struct {
Tag SharedLinkPolicy `json:".tag"`
} `json:"shared_link_policy"`
MemberPolicy struct {
Tag MemberPolicy `json:".tag"`
} `json:"member_policy"`
ResolvedMemberPolicy struct {
Tag MemberPolicy `json:".tag"`
} `json:"resolved_member_policy"`
}
// AccessType determines the level of access to a shared folder.
type AccessType string
// Access types supported.
const (
Owner AccessType = "owner"
Editor = "editor"
Viewer = "viewer"
ViewerNoComment = "viewer_no_comment"
)
// ACLUpdatePolicy determines who can add and remove members from this shared folder.
type ACLUpdatePolicy string
// ACLUpdatePolicy types supported.
const (
ACLUpdatePolicyOwner ACLUpdatePolicy = "owner"
ACLUpdatePolicyEditors = "editors"
)
// SharedLinkPolicy governs who can view shared links.
type SharedLinkPolicy string
// SharedLinkPolicy types supported.
const (
SharedLinkPolicyAnyone SharedLinkPolicy = "anyone"
SharedLinkPolicyMembers = "members"
)
// MemberPolicy determines who can be a member of this shared folder, as set on the folder itself.
type MemberPolicy string
// MemberPolicy types supported.
const (
MemberPolicyTeam MemberPolicy = "team"
MemberPolicyAnyone = "anyone"
)