go-twitch/api/eventsub/get_subscriptions.go

44 lines
1.1 KiB
Go
Raw Normal View History

2024-02-27 22:13:57 -05:00
package eventsub
import (
"encoding/json"
"net/url"
"github.com/google/go-querystring/query"
"go.fifitido.net/twitch/api/types"
)
type GetSubscriptionsParams struct {
Status *Status `url:"status,omitempty"`
Type *SubscriptionType `url:"type,omitempty"`
UserID *string `url:"user_id,omitempty"`
After *types.Cursor `url:"after,omitempty"`
}
type GetSubscriptionsResponse struct {
Data []Subscription `json:"data"`
Total int `json:"total"`
TotalCost int `json:"total_cost"`
MaxTotalCost int `json:"max_total_cost"`
Pagination types.Pagination `json:"pagination"`
}
func (e *EventSub) GetSubscriptions(params *GetSubscriptionsParams) (*GetSubscriptionsResponse, error) {
v, _ := query.Values(params)
endpoint := e.baseUrl.ResolveReference(&url.URL{Path: "eventsub/subscriptions", RawQuery: v.Encode()})
resp, err := e.client.Get(endpoint.String())
if err != nil {
return nil, err
}
defer resp.Body.Close()
var data GetSubscriptionsResponse
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}