@@ -37,7 +37,8 @@ type Applications interface {
3737 GetApplicationRoleConnectionMetadata (applicationID snowflake.ID , opts ... RequestOpt ) ([]discord.ApplicationRoleConnectionMetadata , error )
3838 UpdateApplicationRoleConnectionMetadata (applicationID snowflake.ID , newRecords []discord.ApplicationRoleConnectionMetadata , opts ... RequestOpt ) ([]discord.ApplicationRoleConnectionMetadata , error )
3939
40- GetEntitlements (applicationID snowflake.ID , userID snowflake.ID , guildID snowflake.ID , before snowflake.ID , after snowflake.ID , limit int , excludeEnded bool , skuIDs []snowflake.ID , opts ... RequestOpt ) ([]discord.Entitlement , error )
40+ GetEntitlements (applicationID snowflake.ID , params GetEntitlementsParams , opts ... RequestOpt ) ([]discord.Entitlement , error )
41+ GetEntitlement (applicationID snowflake.ID , entitlementID snowflake.ID , opts ... RequestOpt ) (* discord.Entitlement , error )
4142 CreateTestEntitlement (applicationID snowflake.ID , entitlementCreate discord.TestEntitlementCreate , opts ... RequestOpt ) (* discord.Entitlement , error )
4243 DeleteTestEntitlement (applicationID snowflake.ID , entitlementID snowflake.ID , opts ... RequestOpt ) error
4344 ConsumeEntitlement (applicationID snowflake.ID , entitlementID snowflake.ID , opts ... RequestOpt ) error
@@ -51,6 +52,42 @@ type Applications interface {
5152 GetActivityInstance (applicationID snowflake.ID , instanceID string , opts ... RequestOpt ) (* discord.ActivityInstance , error )
5253}
5354
55+ // GetEntitlementsParams holds query parameters for Applications.GetEntitlements (https://discord.com/developers/docs/resources/entitlement#list-entitlements)
56+ type GetEntitlementsParams struct {
57+ UserID snowflake.ID
58+ SkuIDs []snowflake.ID
59+ Before int
60+ After int
61+ Limit int
62+ GuildID snowflake.ID
63+ ExcludeEnded bool
64+ ExcludeDeleted bool
65+ }
66+
67+ func (p GetEntitlementsParams ) ToQueryValues () discord.QueryValues {
68+ queryValues := discord.QueryValues {
69+ "exclude_ended" : p .ExcludeEnded ,
70+ "exclude_deleted" : p .ExcludeDeleted ,
71+ "sku_ids" : slicehelper .JoinSnowflakes (p .SkuIDs ),
72+ }
73+ if p .UserID != 0 {
74+ queryValues ["user_id" ] = p .UserID
75+ }
76+ if p .Before != 0 {
77+ queryValues ["before" ] = p .Before
78+ }
79+ if p .After != 0 {
80+ queryValues ["after" ] = p .After
81+ }
82+ if p .Limit != 0 {
83+ queryValues ["limit" ] = p .Limit
84+ }
85+ if p .GuildID != 0 {
86+ queryValues ["guild_id" ] = p .GuildID
87+ }
88+ return queryValues
89+ }
90+
5491type applicationsImpl struct {
5592 client Client
5693}
@@ -183,27 +220,13 @@ func (s *applicationsImpl) UpdateApplicationRoleConnectionMetadata(applicationID
183220 return
184221}
185222
186- func (s * applicationsImpl ) GetEntitlements (applicationID snowflake.ID , userID snowflake.ID , guildID snowflake.ID , before snowflake.ID , after snowflake.ID , limit int , excludeEnded bool , skuIDs []snowflake.ID , opts ... RequestOpt ) (entitlements []discord.Entitlement , err error ) {
187- queryValues := discord.QueryValues {
188- "exclude_ended" : excludeEnded ,
189- "sku_ids" : slicehelper .JoinSnowflakes (skuIDs ),
190- }
191- if userID != 0 {
192- queryValues ["user_id" ] = userID
193- }
194- if guildID != 0 {
195- queryValues ["guild_id" ] = guildID
196- }
197- if before != 0 {
198- queryValues ["before" ] = before
199- }
200- if after != 0 {
201- queryValues ["after" ] = after
202- }
203- if limit != 0 {
204- queryValues ["limit" ] = limit
205- }
206- err = s .client .Do (GetEntitlements .Compile (queryValues , applicationID ), nil , & entitlements , opts ... )
223+ func (s * applicationsImpl ) GetEntitlements (applicationID snowflake.ID , params GetEntitlementsParams , opts ... RequestOpt ) (entitlements []discord.Entitlement , err error ) {
224+ err = s .client .Do (GetEntitlements .Compile (params .ToQueryValues (), applicationID ), nil , & entitlements , opts ... )
225+ return
226+ }
227+
228+ func (s * applicationsImpl ) GetEntitlement (applicationID snowflake.ID , entitlementID snowflake.ID , opts ... RequestOpt ) (entitlement * discord.Entitlement , err error ) {
229+ err = s .client .Do (GetEntitlement .Compile (nil , applicationID , entitlementID ), nil , & entitlement , opts ... )
207230 return
208231}
209232
0 commit comments