Skip to content

Commit

Permalink
move QueryParamsGetEntitlements
Browse files Browse the repository at this point in the history
  • Loading branch information
sebm253 committed Dec 1, 2024
1 parent 76c6342 commit 83390b5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 38 deletions.
37 changes: 37 additions & 0 deletions rest/applications.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rest

import (
"github.com/disgoorg/disgo/internal/slicehelper"
"github.com/disgoorg/snowflake/v2"

"github.com/disgoorg/disgo/discord"
Expand Down Expand Up @@ -51,6 +52,42 @@ type Applications interface {
GetActivityInstance(applicationID snowflake.ID, instanceID string, opts ...RequestOpt) (*discord.ActivityInstance, error)
}

// 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
}

type applicationsImpl struct {
client Client
}
Expand Down
38 changes: 0 additions & 38 deletions rest/query_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,10 @@ 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.
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
}

0 comments on commit 83390b5

Please sign in to comment.