diff --git a/rest/applications.go b/rest/applications.go index 22adee44..f16b70ac 100644 --- a/rest/applications.go +++ b/rest/applications.go @@ -1,7 +1,6 @@ package rest import ( - "github.com/disgoorg/disgo/internal/slicehelper" "github.com/disgoorg/snowflake/v2" "github.com/disgoorg/disgo/discord" @@ -37,7 +36,7 @@ type Applications interface { GetApplicationRoleConnectionMetadata(applicationID snowflake.ID, opts ...RequestOpt) ([]discord.ApplicationRoleConnectionMetadata, error) UpdateApplicationRoleConnectionMetadata(applicationID snowflake.ID, newRecords []discord.ApplicationRoleConnectionMetadata, opts ...RequestOpt) ([]discord.ApplicationRoleConnectionMetadata, error) - GetEntitlements(applicationID snowflake.ID, userID snowflake.ID, guildID snowflake.ID, before snowflake.ID, after snowflake.ID, limit int, excludeEnded bool, excludeDeleted bool, skuIDs []snowflake.ID, opts ...RequestOpt) ([]discord.Entitlement, error) + GetEntitlements(applicationID snowflake.ID, params QueryParamsGetEntitlements, opts ...RequestOpt) ([]discord.Entitlement, error) GetEntitlement(applicationID snowflake.ID, entitlementID snowflake.ID, opts ...RequestOpt) (*discord.Entitlement, error) CreateTestEntitlement(applicationID snowflake.ID, entitlementCreate discord.TestEntitlementCreate, opts ...RequestOpt) (*discord.Entitlement, error) DeleteTestEntitlement(applicationID snowflake.ID, entitlementID snowflake.ID, opts ...RequestOpt) error @@ -184,28 +183,8 @@ func (s *applicationsImpl) UpdateApplicationRoleConnectionMetadata(applicationID return } -func (s *applicationsImpl) GetEntitlements(applicationID snowflake.ID, userID snowflake.ID, guildID snowflake.ID, before snowflake.ID, after snowflake.ID, limit int, excludeEnded bool, excludeDeleted bool, skuIDs []snowflake.ID, opts ...RequestOpt) (entitlements []discord.Entitlement, err error) { - queryValues := discord.QueryValues{ - "exclude_ended": excludeEnded, - "exclude_deleted": excludeDeleted, - "sku_ids": slicehelper.JoinSnowflakes(skuIDs), - } - if userID != 0 { - queryValues["user_id"] = userID - } - if guildID != 0 { - queryValues["guild_id"] = guildID - } - if before != 0 { - queryValues["before"] = before - } - if after != 0 { - queryValues["after"] = after - } - if limit != 0 { - queryValues["limit"] = limit - } - err = s.client.Do(GetEntitlements.Compile(queryValues, applicationID), nil, &entitlements, opts...) +func (s *applicationsImpl) GetEntitlements(applicationID snowflake.ID, params QueryParamsGetEntitlements, opts ...RequestOpt) (entitlements []discord.Entitlement, err error) { + err = s.client.Do(GetEntitlements.Compile(params.ToQueryValues(), applicationID), nil, &entitlements, opts...) return } diff --git a/rest/query_params.go b/rest/query_params.go index 9d17c83d..4dce5721 100644 --- a/rest/query_params.go +++ b/rest/query_params.go @@ -2,6 +2,8 @@ package rest import ( "github.com/disgoorg/disgo/discord" + "github.com/disgoorg/disgo/internal/slicehelper" + "github.com/disgoorg/snowflake/v2" ) // QueryParams serves as a generic interface for implementations of rest endpoint query parameters. @@ -9,3 +11,39 @@ type QueryParams interface { // ToQueryValues transforms fields from the QueryParams interface implementations into discord.QueryValues. ToQueryValues() discord.QueryValues } + +// QueryParamsGetEntitlements holds query parameters for Applications.GetEntitlements (https://discord.com/developers/docs/resources/entitlement#list-entitlements) +type QueryParamsGetEntitlements struct { + UserID snowflake.ID + SkuIDs []snowflake.ID + Before int + After int + Limit int + GuildID snowflake.ID + ExcludeEnded bool + ExcludeDeleted bool +} + +func (p QueryParamsGetEntitlements) ToQueryValues() discord.QueryValues { + queryValues := discord.QueryValues{ + "exclude_ended": p.ExcludeEnded, + "exclude_deleted": p.ExcludeDeleted, + "sku_ids": slicehelper.JoinSnowflakes(p.SkuIDs), + } + if p.UserID != 0 { + queryValues["user_id"] = p.UserID + } + if p.Before != 0 { + queryValues["before"] = p.Before + } + if p.After != 0 { + queryValues["after"] = p.After + } + if p.Limit != 0 { + queryValues["limit"] = p.Limit + } + if p.GuildID != 0 { + queryValues["guild_id"] = p.GuildID + } + return queryValues +}