Skip to content

Commit 27495b4

Browse files
author
Diwaker Gupta
committed
Add custom handling for ListSharedLinksResult
1 parent e4f93d8 commit 27495b4

File tree

4 files changed

+100
-2
lines changed

4 files changed

+100
-2
lines changed

dropbox/sharing/metadata.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) Dropbox, Inc.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
package sharing
22+
23+
import "encoding/json"
24+
25+
type listSharedLinksResult struct {
26+
Links []sharedLinkMetadataUnion `json:"links"`
27+
HasMore bool `json:"has_more"`
28+
Cursor string `json:"cursor,omitempty"`
29+
}
30+
31+
// UnmarshalJSON deserializes into a ListSharedLinksResult instance
32+
func (r *ListSharedLinksResult) UnmarshalJSON(b []byte) error {
33+
var l listSharedLinksResult
34+
if err := json.Unmarshal(b, &l); err != nil {
35+
return err
36+
}
37+
r.Cursor = l.Cursor
38+
r.HasMore = l.HasMore
39+
r.Links = make([]IsSharedLinkMetadata, len(l.Links))
40+
for i, e := range l.Links {
41+
switch e.Tag {
42+
case "file":
43+
r.Links[i] = e.File
44+
case "folder":
45+
r.Links[i] = e.Folder
46+
}
47+
}
48+
return nil
49+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) Dropbox, Inc.
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
21+
package sharing
22+
23+
import "encoding/json"
24+
25+
type listSharedLinksResult struct {
26+
Links []sharedLinkMetadataUnion `json:"links"`
27+
HasMore bool `json:"has_more"`
28+
Cursor string `json:"cursor,omitempty"`
29+
}
30+
31+
// UnmarshalJSON deserializes into a ListSharedLinksResult instance
32+
func (r *ListSharedLinksResult) UnmarshalJSON(b []byte) error {
33+
var l listSharedLinksResult
34+
if err := json.Unmarshal(b, &l); err != nil {
35+
return err
36+
}
37+
r.Cursor = l.Cursor
38+
r.HasMore = l.HasMore
39+
r.Links = make([]IsSharedLinkMetadata, len(l.Links))
40+
for i, e := range l.Links {
41+
switch e.Tag {
42+
case "file":
43+
r.Links[i] = e.File
44+
case "folder":
45+
r.Links[i] = e.Folder
46+
}
47+
}
48+
return nil
49+
}

generator/go_types.stoneg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def generate(self, api):
2626
self.target_folder_path)
2727
for namespace in api.namespaces.values():
2828
self._generate_namespace(namespace)
29-
if namespace.name == 'files':
29+
if namespace.name == 'files' or namespace.name == 'sharing':
3030
self.logger.info('Copying metadata.go to files')
31-
shutil.copy(os.path.join(rsrc_folder, 'metadata.go'),
31+
shutil.copy(os.path.join(rsrc_folder, namespace.name, 'metadata.go'),
3232
os.path.join(self.target_folder_path, namespace.name))
3333

3434
def _generate_namespace(self, namespace):

0 commit comments

Comments
 (0)