Skip to content

Commit

Permalink
fix method params to accept customisation
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz committed Nov 20, 2022
1 parent 28a58ee commit 9387c77
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
15 changes: 12 additions & 3 deletions r2_bucket.go
Expand Up @@ -31,13 +31,22 @@ type R2BucketListResponse struct {
Response
}

// R2Buckets Lists R2 buckets.
func (api *API) R2Buckets(ctx context.Context, rc *ResourceContainer) ([]R2Bucket, error) {
type ListR2BucketsParams struct {
Name string `url:"name_contains,omitempty"`
StartAfter string `url:"start_after,omitempty"`
PerPage int64 `url:"per_page,omitempty"`
Order string `url:"order,omitempty"`
Direction string `url:"direction,omitempty"`
Cursor string `url:"cursor,omitempty"`
}

// ListR2Buckets Lists R2 buckets.
func (api *API) ListR2Buckets(ctx context.Context, rc *ResourceContainer, params ListR2BucketsParams) ([]R2Bucket, error) {
if rc.Identifier == "" {
return []R2Bucket{}, ErrMissingAccountID
}

uri := fmt.Sprintf("/accounts/%s/r2/buckets", rc.Identifier)
uri := buildURI(fmt.Sprintf("/accounts/%s/r2/buckets", rc.Identifier), params)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return []R2Bucket{}, err
Expand Down
7 changes: 1 addition & 6 deletions r2_bucket_test.go
Expand Up @@ -33,18 +33,13 @@ func TestR2_ListBuckets(t *testing.T) {
}`)
})

_, err := client.R2Buckets(context.Background(), AccountIdentifier(""))
if assert.Error(t, err) {
assert.Equal(t, ErrMissingAccountID, err)
}

want := []R2Bucket{
{
Name: "example-bucket",
CreationDate: "2022-06-24T19:58:49.477Z",
},
}
actual, err := client.R2Buckets(context.Background(), AccountIdentifier(testAccountID))
actual, err := client.ListR2Buckets(context.Background(), AccountIdentifier(testAccountID), ListR2BucketsParams{})
if assert.NoError(t, err) {
assert.Equal(t, want, actual)
}
Expand Down

0 comments on commit 9387c77

Please sign in to comment.