44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
|
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
|
||
|
}
|