Browse Source

DeleteCollection: Make params a struct

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.
Abhinav Gupta 1 year ago
parent
commit
1d34eede72
2 changed files with 12 additions and 4 deletions
  1. 8
    2
      collection.go
  2. 4
    2
      collection_test.go

+ 8
- 2
collection.go View File

@@ -29,6 +29,12 @@ type (
29 29
 		Alias string `json:"alias"`
30 30
 		Title string `json:"title"`
31 31
 	}
32
+
33
+	// DeleteCollectionParams holds the parameters required to delete a
34
+	// collection.
35
+	DeleteCollectionParams struct {
36
+		Alias string `json:"-"`
37
+	}
32 38
 )
33 39
 
34 40
 // CreateCollection creates a new collection, returning a user-friendly error
@@ -140,8 +146,8 @@ func (c *Client) GetUserCollections() (*[]Collection, error) {
140 146
 // anonymous.
141 147
 //
142 148
 // See https://developers.write.as/docs/api/#delete-a-collection.
143
-func (c *Client) DeleteCollection(alias string) error {
144
-	endpoint := "/collections/" + alias
149
+func (c *Client) DeleteCollection(p *DeleteCollectionParams) error {
150
+	endpoint := "/collections/" + p.Alias
145 151
 	env, err := c.delete(endpoint, nil /* data */)
146 152
 	if err != nil {
147 153
 		return err

+ 4
- 2
collection_test.go View File

@@ -71,7 +71,8 @@ func TestCreateAndDeleteCollection(t *testing.T) {
71 71
 		t.Fatalf("Unable to create collection %q: %v", alias, err)
72 72
 	}
73 73
 
74
-	if err := wac.DeleteCollection(c.Alias); err != nil {
74
+	p := &DeleteCollectionParams{Alias: c.Alias}
75
+	if err := wac.DeleteCollection(p); err != nil {
75 76
 		t.Fatalf("Unable to delete collection %q: %v", alias, err)
76 77
 	}
77 78
 }
@@ -81,7 +82,8 @@ func TestDeleteCollectionUnauthenticated(t *testing.T) {
81 82
 
82 83
 	now := time.Now().Unix()
83 84
 	alias := fmt.Sprintf("test-collection-does-not-exist-%v", now)
84
-	err := wac.DeleteCollection(alias)
85
+	p := &DeleteCollectionParams{Alias: alias}
86
+	err := wac.DeleteCollection(p)
85 87
 	if err == nil {
86 88
 		t.Fatalf("Should not be able to delete collection %q unauthenticated.", alias)
87 89
 	}