62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package conduit
|
||
|
||
import (
|
||
"context"
|
||
"encoding/json"
|
||
"fmt"
|
||
"net/http"
|
||
|
||
"github.com/google/go-querystring/query"
|
||
"go.fifitido.net/twitch/api/endpoint"
|
||
"go.fifitido.net/twitch/api/types"
|
||
)
|
||
|
||
type GetConduitShardsParams struct {
|
||
// Conduit ID.
|
||
ConduitID string `url:"conduit_id"`
|
||
|
||
// Status to filter by.
|
||
Status *Status `url:"status,omitempty"`
|
||
|
||
// The cursor used to get the next page of results. The pagination object in the response contains the cursor’s value.
|
||
Cursor *types.Cursor `url:"cursor,omitempty"`
|
||
}
|
||
|
||
type GetConduitShardsResponse struct {
|
||
// List of information about a conduit's shards.
|
||
Data []Shard `json:"data"`
|
||
|
||
// The cursor used to get the next page of results. Use the cursor to set the request’s after query parameter.
|
||
Pagination types.Pagination `json:"pagination"`
|
||
}
|
||
|
||
// Gets a lists of all shards for a conduit.
|
||
//
|
||
// Requires an app access token.
|
||
func (c *Conduit) GetConduitShards(ctx context.Context, params *GetConduitShardsParams) (*GetConduitShardsResponse, error) {
|
||
v, _ := query.Values(params)
|
||
|
||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "eventsub/conduits/shards", v), nil)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
res, err := c.client.Do(req)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
defer res.Body.Close()
|
||
|
||
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
||
if !statusOK {
|
||
return nil, fmt.Errorf("failed to get conduit shards (%d)", res.StatusCode)
|
||
}
|
||
|
||
var data GetConduitShardsResponse
|
||
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
||
return nil, err
|
||
}
|
||
|
||
return &data, nil
|
||
}
|