@@ -27,26 +27,13 @@ import (
2727 "github.com/dropbox/dropbox-sdk-go-unofficial/dropbox"
2828)
2929
30- // InvalidPathRootError : has no documentation (yet)
31- type InvalidPathRootError struct {
32- // PathRoot : The latest path root id for user's team if the user is still
33- // in a team.
34- PathRoot string `json:"path_root,omitempty"`
35- }
36-
37- // NewInvalidPathRootError returns a new InvalidPathRootError instance
38- func NewInvalidPathRootError () * InvalidPathRootError {
39- s := new (InvalidPathRootError )
40- return s
41- }
42-
4330// PathRoot : has no documentation (yet)
4431type PathRoot struct {
4532 dropbox.Tagged
46- // Team : Paths are relative to the given team directory. (This results in
47- // `PathRootError.invalid ` if the user is not a member of the team
48- // associated with that path root id .).
49- Team string `json:"team ,omitempty"`
33+ // Root : Paths are relative to the authenticating user's root namespace
34+ // (This results in `PathRootError.invalid_root ` if the user's root
35+ // namespace has changed .).
36+ Root string `json:"root ,omitempty"`
5037 // NamespaceId : Paths are relative to given namespace id (This results in
5138 // `PathRootError.no_permission` if you don't have access to this
5239 // namespace.).
@@ -56,9 +43,7 @@ type PathRoot struct {
5643// Valid tag values for PathRoot
5744const (
5845 PathRootHome = "home"
59- PathRootMemberHome = "member_home"
60- PathRootTeam = "team"
61- PathRootUserHome = "user_home"
46+ PathRootRoot = "root"
6247 PathRootNamespaceId = "namespace_id"
6348 PathRootOther = "other"
6449)
@@ -75,8 +60,8 @@ func (u *PathRoot) UnmarshalJSON(body []byte) error {
7560 }
7661 u .Tag = w .Tag
7762 switch u .Tag {
78- case "team " :
79- err = json .Unmarshal (body , & u .Team )
63+ case "root " :
64+ err = json .Unmarshal (body , & u .Root )
8065
8166 if err != nil {
8267 return err
@@ -94,14 +79,14 @@ func (u *PathRoot) UnmarshalJSON(body []byte) error {
9479// PathRootError : has no documentation (yet)
9580type PathRootError struct {
9681 dropbox.Tagged
97- // Invalid : The path root id value in Dropbox-API-Path-Root header is no
98- // longer valid.
99- Invalid * InvalidPathRootError `json:"invalid ,omitempty"`
82+ // InvalidRoot : The root namespace id in Dropbox-API-Path-Root header is
83+ // not valid. The value of this error is use's latest root info .
84+ InvalidRoot IsRootInfo `json:"invalid_root ,omitempty"`
10085}
10186
10287// Valid tag values for PathRootError
10388const (
104- PathRootErrorInvalid = "invalid "
89+ PathRootErrorInvalidRoot = "invalid_root "
10590 PathRootErrorNoPermission = "no_permission"
10691 PathRootErrorOther = "other"
10792)
@@ -110,9 +95,75 @@ const (
11095func (u * PathRootError ) UnmarshalJSON (body []byte ) error {
11196 type wrap struct {
11297 dropbox.Tagged
113- // Invalid : The path root id value in Dropbox-API-Path-Root header is
114- // no longer valid.
115- Invalid json.RawMessage `json:"invalid,omitempty"`
98+ // InvalidRoot : The root namespace id in Dropbox-API-Path-Root header
99+ // is not valid. The value of this error is use's latest root info.
100+ InvalidRoot json.RawMessage `json:"invalid_root,omitempty"`
101+ }
102+ var w wrap
103+ var err error
104+ if err = json .Unmarshal (body , & w ); err != nil {
105+ return err
106+ }
107+ u .Tag = w .Tag
108+ switch u .Tag {
109+ case "invalid_root" :
110+ u .InvalidRoot , err = IsRootInfoFromJSON (body )
111+
112+ if err != nil {
113+ return err
114+ }
115+ }
116+ return nil
117+ }
118+
119+ // RootInfo : Information about current user's root.
120+ type RootInfo struct {
121+ // RootNamespaceId : The namespace id for user's root namespace. It will be
122+ // the namespace id of the shared team root if the user is member of a CDM
123+ // team. Otherwise it will be same as `RootInfo.home_namespace_id`.
124+ RootNamespaceId string `json:"root_namespace_id"`
125+ // HomeNamespaceId : The namespace id for user's home namespace.
126+ HomeNamespaceId string `json:"home_namespace_id"`
127+ }
128+
129+ // NewRootInfo returns a new RootInfo instance
130+ func NewRootInfo (RootNamespaceId string , HomeNamespaceId string ) * RootInfo {
131+ s := new (RootInfo )
132+ s .RootNamespaceId = RootNamespaceId
133+ s .HomeNamespaceId = HomeNamespaceId
134+ return s
135+ }
136+
137+ // IsRootInfo is the interface type for RootInfo and its subtypes
138+ type IsRootInfo interface {
139+ IsRootInfo ()
140+ }
141+
142+ // IsRootInfo implements the IsRootInfo interface
143+ func (u * RootInfo ) IsRootInfo () {}
144+
145+ type rootInfoUnion struct {
146+ dropbox.Tagged
147+ // Team : has no documentation (yet)
148+ Team * TeamRootInfo `json:"team,omitempty"`
149+ // User : has no documentation (yet)
150+ User * UserRootInfo `json:"user,omitempty"`
151+ }
152+
153+ // Valid tag values for RootInfo
154+ const (
155+ RootInfoTeam = "team"
156+ RootInfoUser = "user"
157+ )
158+
159+ // UnmarshalJSON deserializes into a rootInfoUnion instance
160+ func (u * rootInfoUnion ) UnmarshalJSON (body []byte ) error {
161+ type wrap struct {
162+ dropbox.Tagged
163+ // Team : has no documentation (yet)
164+ Team json.RawMessage `json:"team,omitempty"`
165+ // User : has no documentation (yet)
166+ User json.RawMessage `json:"user,omitempty"`
116167 }
117168 var w wrap
118169 var err error
@@ -121,12 +172,64 @@ func (u *PathRootError) UnmarshalJSON(body []byte) error {
121172 }
122173 u .Tag = w .Tag
123174 switch u .Tag {
124- case "invalid" :
125- err = json .Unmarshal (body , & u .Invalid )
175+ case "team" :
176+ err = json .Unmarshal (body , & u .Team )
177+
178+ if err != nil {
179+ return err
180+ }
181+ case "user" :
182+ err = json .Unmarshal (body , & u .User )
126183
127184 if err != nil {
128185 return err
129186 }
130187 }
131188 return nil
132189}
190+
191+ // IsRootInfoFromJSON converts JSON to a concrete IsRootInfo instance
192+ func IsRootInfoFromJSON (data []byte ) (IsRootInfo , error ) {
193+ var t rootInfoUnion
194+ if err := json .Unmarshal (data , & t ); err != nil {
195+ return nil , err
196+ }
197+ switch t .Tag {
198+ case "team" :
199+ return t .Team , nil
200+
201+ case "user" :
202+ return t .User , nil
203+
204+ }
205+ return nil , nil
206+ }
207+
208+ // TeamRootInfo : Root info when user is member of a CDM team.
209+ type TeamRootInfo struct {
210+ RootInfo
211+ // HomePath : The path for user's home directory under the shared team root.
212+ HomePath string `json:"home_path"`
213+ }
214+
215+ // NewTeamRootInfo returns a new TeamRootInfo instance
216+ func NewTeamRootInfo (RootNamespaceId string , HomeNamespaceId string , HomePath string ) * TeamRootInfo {
217+ s := new (TeamRootInfo )
218+ s .RootNamespaceId = RootNamespaceId
219+ s .HomeNamespaceId = HomeNamespaceId
220+ s .HomePath = HomePath
221+ return s
222+ }
223+
224+ // UserRootInfo : Root info when user is not member of a CDM team.
225+ type UserRootInfo struct {
226+ RootInfo
227+ }
228+
229+ // NewUserRootInfo returns a new UserRootInfo instance
230+ func NewUserRootInfo (RootNamespaceId string , HomeNamespaceId string ) * UserRootInfo {
231+ s := new (UserRootInfo )
232+ s .RootNamespaceId = RootNamespaceId
233+ s .HomeNamespaceId = HomeNamespaceId
234+ return s
235+ }
0 commit comments