Skip to content

Commit

Permalink
Merge pull request #899 from jacobbednarz/filter-by-name-with-accounts
Browse files Browse the repository at this point in the history
accounts: allow filtering by name for `Accounts`
  • Loading branch information
jacobbednarz committed May 23, 2022
2 parents d1668ec + af69d3c commit 47b45ad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions accounts.go
Expand Up @@ -48,13 +48,20 @@ type AccountDetailResponse struct {
Result Account `json:"result"`
}

// AccountsListParams holds the filterable options for Accounts.
type AccountsListParams struct {
Name string `url:"name"`

PaginationOptions
}

// Accounts returns all accounts the logged in user has access to.
//
// API reference: https://api.cloudflare.com/#accounts-list-accounts
func (api *API) Accounts(ctx context.Context, pageOpts PaginationOptions) ([]Account, ResultInfo, error) {
func (api *API) Accounts(ctx context.Context, params AccountsListParams) ([]Account, ResultInfo, error) {
uri := "/accounts"

v, _ := query.Values(pageOpts)
v, _ := query.Values(params)
queryParams := v.Encode()
if queryParams != "" {
queryParams = "?" + queryParams
Expand Down
2 changes: 1 addition & 1 deletion accounts_test.go
Expand Up @@ -57,7 +57,7 @@ func TestAccounts(t *testing.T) {
mux.HandleFunc("/accounts", handler)
want := []Account{expectedAccountStruct}

actual, _, err := client.Accounts(context.Background(), PaginationOptions{})
actual, _, err := client.Accounts(context.Background(), AccountsListParams{})

if assert.NoError(t, err) {
assert.Equal(t, want, actual)
Expand Down
4 changes: 2 additions & 2 deletions cmd/flarectl/firewall.go
Expand Up @@ -316,8 +316,8 @@ func getScope(c *cli.Context) (string, string, error) {
var account, accountID string
if c.String("account") != "" {
account = c.String("account")
pageOpts := cloudflare.PaginationOptions{}
accounts, _, err := api.Accounts(context.Background(), pageOpts)
params := cloudflare.AccountsListParams{}
accounts, _, err := api.Accounts(context.Background(), params)
if err != nil {
fmt.Println(err)
return "", "", err
Expand Down

0 comments on commit 47b45ad

Please sign in to comment.