2024-02-28 13:50:07 -05:00
|
|
|
|
package conduit
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
2024-03-07 19:41:05 -05:00
|
|
|
|
"fmt"
|
2024-02-28 13:50:07 -05:00
|
|
|
|
"net/http"
|
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
|
|
"github.com/google/go-querystring/query"
|
|
|
|
|
"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)
|
|
|
|
|
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "eventsub/conduits/shards", RawQuery: v.Encode()})
|
|
|
|
|
|
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res, err := c.client.Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
|
2024-03-07 19:41:05 -05:00
|
|
|
|
statusOK := res.StatusCode >= 200 && res.StatusCode < 300
|
|
|
|
|
if !statusOK {
|
|
|
|
|
return nil, fmt.Errorf("failed to get conduit shards (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 13:50:07 -05:00
|
|
|
|
var data GetConduitShardsResponse
|
|
|
|
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &data, nil
|
|
|
|
|
}
|