Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions sharing.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ func (c *Sharing) ListSharedLinks(in *ListShareLinksInput) (out *ListShareLinksO
return
}

type RevokeSharedLinkInput struct {
Url string `json:"url"`
}


func (c *Sharing) RevokeSharedLink(in *RevokeSharedLinkInput) (err error) {

endpoint := "/sharing/revoke_shared_link"
_, err := c.call(endpoint, in)
if err != nil {
return
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a big deal but could just do return here instead of the conditional. Mind adding a comment to the struct/method as well?

LGTM otherswise thanks!!


return
}

// ListSharedFolderInput request input.
type ListSharedFolderInput struct {
Limit uint64 `json:"limit"`
Expand Down
67 changes: 62 additions & 5 deletions sharing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,33 @@ import (

func TestSharing_CreateSharedLink(t *testing.T) {
c := client()
out, err := c.Sharing.CreateSharedLink(&CreateSharedLinkInput{
Path: "/hello.txt",
})
//list shares
links, _ := c.Sharing.ListSharedLinks(&ListShareLinksInput {
Path: "/hello.txt",
})

assert.NoError(t, err, "error sharing file")
assert.Equal(t, "/hello.txt", out.Path)
var sharedLink string
if len(links.Links) == 0 {
out, err := c.Sharing.CreateSharedLink(&CreateSharedLinkInput{
Path: "/hello.txt",
})

assert.NoError(t, err, "error sharing file")
assert.Contains(t, out.URL, "/hello.txt")
} else {
sharedLink = links.Links[0].URL

err := c.Sharing.RevokeSharedLink(&RevokeSharedLinkInput{
Url: sharedLink,
})

out, err := c.Sharing.CreateSharedLink(&CreateSharedLinkInput{
Path: "/hello.txt",
})

assert.NoError(t, err, "error sharing file")
assert.Contains(t, out.URL, "/hello.txt")
}
}

func TestSharing_ListSharedFolder(t *testing.T) {
Expand All @@ -34,3 +55,39 @@ func TestSharing_ListSharedFolder(t *testing.T) {
assert.NotEmpty(t, out.Entries, "output should be non-empty")
}
}

func TestSharing_ListSharedLinks(t *testing.T) {
c := client()
out, err := c.Sharing.ListSharedLinks(&ListShareLinksInput{
Path: "/hello.txt",
})

assert.NoError(t, err, "listing shared folders")
assert.NotEmpty(t, out.Links, "output should be non-empty")
}

func TestSharing_RevokeSharedLink(t *testing.T) {
c := client()

links, err := c.Sharing.ListSharedLinks(&ListShareLinksInput {
Path: "/hello.txt",
})

var sharedLink string
if len(links.Links) == 0 {
sl := CreateSharedLinkInput{ Path: "/hello.txt" }

link, err := c.Sharing.CreateSharedLink(&sl)

assert.NoError(t, err, "revoke shared link")
sharedLink = link.URL
} else {
sharedLink = links.Links[0].URL
}

err = c.Sharing.RevokeSharedLink(&RevokeSharedLinkInput{
Url: sharedLink,
})

assert.NoError(t, err, "revoke shared link")
}