Skip to content

Commit

Permalink
move optional entitlement filter options into a separate struct
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoffi committed Aug 15, 2024
1 parent 54287e3 commit 7cf6c73
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 28 deletions.
52 changes: 24 additions & 28 deletions restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -3525,37 +3525,33 @@ func (s *Session) SKUs(appID string) (skus []*SKU, err error) {

// Entitlements returns all antitlements for a given app, active and expired.
// appID : The ID of the application.
// userID : Optional user ID to look up for.
// skuIDs : Optional array of SKU IDs to check for.
// before : Optional timestamp to retrieve Entitlements before this time.
// after : Optional timestamp to retrieve Entitlements after this time.
// limit : Optional maximum number of entitlements to return (1-100, default 100).
// guildID : Optional guild ID to look up for.
// exclude_ended : Optional whether or not ended entitlements should be omitted.
func (s *Session) Entitlements(appID, userID string, skuIDs *[]string, beforeID, afterID string, limit int, guildID string, excludeEnded bool, options ...RequestOption) (entitlements []*Entitlement, err error) {
// filterOptions : Optional filter options; otherwise set it to nil.
func (s *Session) Entitlements(appID string, filterOptions *EntitlementFilterOptions, options ...RequestOption) (entitlements []*Entitlement, err error) {
endpoint := EndpointEntitlements(appID)

queryParams := url.Values{}
if userID != "" {
queryParams.Set("user_id", userID)
}
if skuIDs != nil && len(*skuIDs) > 0 {
queryParams.Set("sku_ids", strings.Join(*skuIDs, ","))
}
if beforeID != "" {
queryParams.Set("before", beforeID)
}
if afterID != "" {
queryParams.Set("after", afterID)
}
if limit > 0 {
queryParams.Set("limit", strconv.Itoa(limit))
}
if guildID != "" {
queryParams.Set("guild_id", guildID)
}
if excludeEnded {
queryParams.Set("exclude_ended", "true")
if filterOptions != nil {
if filterOptions.UserID != "" {
queryParams.Set("user_id", filterOptions.UserID)
}
if filterOptions.SkuIDs != nil && len(filterOptions.SkuIDs) > 0 {
queryParams.Set("sku_ids", strings.Join(filterOptions.SkuIDs, ","))
}
if filterOptions.BeforeID != "" {
queryParams.Set("before", filterOptions.BeforeID)
}
if filterOptions.AfterID != "" {
queryParams.Set("after", filterOptions.AfterID)
}
if filterOptions.Limit > 0 {
queryParams.Set("limit", strconv.Itoa(filterOptions.Limit))
}
if filterOptions.GuildID != "" {
queryParams.Set("guild_id", filterOptions.GuildID)
}
if filterOptions.ExcludeEnded {
queryParams.Set("exclude_ended", "true")
}
}

body, err := s.RequestWithBucketID("GET", endpoint+"?"+queryParams.Encode(), nil, endpoint, options...)
Expand Down
24 changes: 24 additions & 0 deletions structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2513,6 +2513,30 @@ type EntitlementTest struct {
OwnerType EntitlementOwnerType `json:"owner_type"`
}

// EntitlementFilterOptions are the options for filtering Entitlements
type EntitlementFilterOptions struct {
// Optional user ID to look up for.
UserID string

// Optional array of SKU IDs to check for.
SkuIDs []string

// Optional timestamp (snowflake) to retrieve Entitlements before this time.
BeforeID string

// Optional timestamp (snowflake) to retrieve Entitlements after this time.
AfterID string

// Optional maximum number of entitlements to return (1-100, default 100).
Limit int

// Optional guild ID to look up for.
GuildID string

// Optional whether or not ended entitlements should be omitted.
ExcludeEnded bool
}

// Constants for the different bit offsets of text channel permissions
const (
// Deprecated: PermissionReadMessages has been replaced with PermissionViewChannel for text and voice channels
Expand Down

0 comments on commit 7cf6c73

Please sign in to comment.