Rather than accepting a naked string, accept a DeleteCollectionParams struct so that new optional parameters can be added in the future without breaking the API.pull/13/head
@@ -29,6 +29,12 @@ type ( | |||||
Alias string `json:"alias"` | Alias string `json:"alias"` | ||||
Title string `json:"title"` | Title string `json:"title"` | ||||
} | } | ||||
// DeleteCollectionParams holds the parameters required to delete a | |||||
// collection. | |||||
DeleteCollectionParams struct { | |||||
Alias string `json:"-"` | |||||
} | |||||
) | ) | ||||
// CreateCollection creates a new collection, returning a user-friendly error | // CreateCollection creates a new collection, returning a user-friendly error | ||||
@@ -140,8 +146,8 @@ func (c *Client) GetUserCollections() (*[]Collection, error) { | |||||
// anonymous. | // anonymous. | ||||
// | // | ||||
// See https://developers.write.as/docs/api/#delete-a-collection. | // See https://developers.write.as/docs/api/#delete-a-collection. | ||||
func (c *Client) DeleteCollection(alias string) error { | |||||
endpoint := "/collections/" + alias | |||||
func (c *Client) DeleteCollection(p *DeleteCollectionParams) error { | |||||
endpoint := "/collections/" + p.Alias | |||||
env, err := c.delete(endpoint, nil /* data */) | env, err := c.delete(endpoint, nil /* data */) | ||||
if err != nil { | if err != nil { | ||||
return err | return err | ||||
@@ -71,7 +71,8 @@ func TestCreateAndDeleteCollection(t *testing.T) { | |||||
t.Fatalf("Unable to create collection %q: %v", alias, err) | t.Fatalf("Unable to create collection %q: %v", alias, err) | ||||
} | } | ||||
if err := wac.DeleteCollection(c.Alias); err != nil { | |||||
p := &DeleteCollectionParams{Alias: c.Alias} | |||||
if err := wac.DeleteCollection(p); err != nil { | |||||
t.Fatalf("Unable to delete collection %q: %v", alias, err) | t.Fatalf("Unable to delete collection %q: %v", alias, err) | ||||
} | } | ||||
} | } | ||||
@@ -81,7 +82,8 @@ func TestDeleteCollectionUnauthenticated(t *testing.T) { | |||||
now := time.Now().Unix() | now := time.Now().Unix() | ||||
alias := fmt.Sprintf("test-collection-does-not-exist-%v", now) | alias := fmt.Sprintf("test-collection-does-not-exist-%v", now) | ||||
err := wac.DeleteCollection(alias) | |||||
p := &DeleteCollectionParams{Alias: alias} | |||||
err := wac.DeleteCollection(p) | |||||
if err == nil { | if err == nil { | ||||
t.Fatalf("Should not be able to delete collection %q unauthenticated.", alias) | t.Fatalf("Should not be able to delete collection %q unauthenticated.", alias) | ||||
} | } | ||||