Skip to content

Commit

Permalink
Add GetEntitlement and new GetEntitlements param
Browse files Browse the repository at this point in the history
  • Loading branch information
sebm253 committed Nov 30, 2024
1 parent cffc8eb commit 4ab8ee6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
23 changes: 13 additions & 10 deletions discord/entitlement.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ import (
)

type Entitlement struct {
ID snowflake.ID `json:"id"`
SkuID snowflake.ID `json:"sku_id"`
ApplicationID snowflake.ID `json:"application_id"`
UserID *snowflake.ID `json:"user_id"`
Type EntitlementType `json:"type"`
Deleted bool `json:"deleted"`
StartsAt *time.Time `json:"starts_at"`
EndsAt *time.Time `json:"ends_at"`
GuildID *snowflake.ID `json:"guild_id"`
Consumed *bool `json:"consumed"`
ID snowflake.ID `json:"id"`
SkuID snowflake.ID `json:"sku_id"`
ApplicationID snowflake.ID `json:"application_id"`
UserID *snowflake.ID `json:"user_id"`
PromotionID *snowflake.ID `json:"promotion_id"`
Type EntitlementType `json:"type"`
Deleted bool `json:"deleted"`
GiftCodeFlags int `json:"gift_code_flags"`
Consumed *bool `json:"consumed"`
StartsAt *time.Time `json:"starts_at"`
EndsAt *time.Time `json:"ends_at"`
GuildID *snowflake.ID `json:"guild_id"`
SubscriptionID *snowflake.ID `json:"subscription_id"`
}

type EntitlementType int
Expand Down
15 changes: 11 additions & 4 deletions rest/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ 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, skuIDs []snowflake.ID, opts ...RequestOpt) ([]discord.Entitlement, 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)
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
ConsumeEntitlement(applicationID snowflake.ID, entitlementID snowflake.ID, opts ...RequestOpt) error
Expand Down Expand Up @@ -183,10 +184,11 @@ 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, skuIDs []snowflake.ID, opts ...RequestOpt) (entitlements []discord.Entitlement, err error) {
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,
"sku_ids": slicehelper.JoinSnowflakes(skuIDs),
"exclude_ended": excludeEnded,
"exclude_deleted": excludeDeleted,
"sku_ids": slicehelper.JoinSnowflakes(skuIDs),
}
if userID != 0 {
queryValues["user_id"] = userID
Expand All @@ -207,6 +209,11 @@ func (s *applicationsImpl) GetEntitlements(applicationID snowflake.ID, userID sn
return
}

func (s *applicationsImpl) GetEntitlement(applicationID snowflake.ID, entitlementID snowflake.ID, opts ...RequestOpt) (entitlement *discord.Entitlement, err error) {
err = s.client.Do(GetEntitlement.Compile(nil, applicationID, entitlementID), nil, &entitlement, opts...)
return
}

func (s *applicationsImpl) CreateTestEntitlement(applicationID snowflake.ID, entitlementCreate discord.TestEntitlementCreate, opts ...RequestOpt) (entitlement *discord.Entitlement, err error) {
err = s.client.Do(CreateTestEntitlement.Compile(nil, applicationID), entitlementCreate, &entitlement, opts...)
return
Expand Down
1 change: 1 addition & 0 deletions rest/rest_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ var (
UpdateApplicationRoleConnectionMetadata = NewEndpoint(http.MethodPut, "/applications/{application.id}/role-connections/metadata")

GetEntitlements = NewEndpoint(http.MethodGet, "/applications/{application.id}/entitlements")
GetEntitlement = NewEndpoint(http.MethodGet, "/applications/{application.id}/entitlements/{entitlement.id}")
CreateTestEntitlement = NewEndpoint(http.MethodPost, "/applications/{application.id}/entitlements")
DeleteTestEntitlement = NewEndpoint(http.MethodDelete, "/applications/{application.id}/entitlements/{entitlement.id}")
ConsumeEntitlement = NewEndpoint(http.MethodPost, "/applications/{application.id}/entitlements/{entitlement.id}/consume")
Expand Down

0 comments on commit 4ab8ee6

Please sign in to comment.