Skip to content

Commit

Permalink
Merge pull request #283 from PagerDuty/ctx_ability
Browse files Browse the repository at this point in the history
Update ability.go to accept a context.Context
  • Loading branch information
Scott McAllister committed Mar 10, 2021
2 parents 3366469 + c19618e commit eaebbbf
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions ability.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,34 @@ type ListAbilityResponse struct {
Abilities []string `json:"abilities"`
}

// ListAbilities lists all abilities on your account.
// ListAbilities lists all abilities on your account. It's recommended to use
// ListAbilitiesWithContext instead.
func (c *Client) ListAbilities() (*ListAbilityResponse, error) {
resp, err := c.get(context.TODO(), "/abilities")
return c.ListAbilitiesWithContext(context.Background())
}

// ListAbilitiesWithContext lists all abilities on your account.
func (c *Client) ListAbilitiesWithContext(ctx context.Context) (*ListAbilityResponse, error) {
resp, err := c.get(ctx, "/abilities")
if err != nil {
return nil, err
}

var result ListAbilityResponse
return &result, c.decodeJSON(resp, &result)
if err := c.decodeJSON(resp, &result); err != nil {
return nil, err
}

return &result, nil
}

// TestAbility Check if your account has the given ability.
func (c *Client) TestAbility(ability string) error {
_, err := c.get(context.TODO(), "/abilities/"+ability)
return c.TestAbilityWithContext(context.Background(), ability)
}

// TestAbility Check if your account has the given ability.
func (c *Client) TestAbilityWithContext(ctx context.Context, ability string) error {
_, err := c.get(ctx, "/abilities/"+ability)
return err
}

0 comments on commit eaebbbf

Please sign in to comment.