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"
|
2024-03-07 20:52:42 -05:00
|
|
|
|
|
|
|
|
|
"go.fifitido.net/twitch/api/endpoint"
|
2024-02-28 13:50:07 -05:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type GetConduitsResponse struct {
|
|
|
|
|
// List of information about the client’s conduits.
|
|
|
|
|
Data []ConduitData `json:"data"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gets the conduits for a client ID.
|
|
|
|
|
//
|
|
|
|
|
// Requires an app access token.
|
|
|
|
|
func (c *Conduit) GetConduits(ctx context.Context) (*GetConduitsResponse, error) {
|
2024-03-07 20:52:42 -05:00
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "eventsub/conduits"), nil)
|
2024-02-28 13:50:07 -05:00
|
|
|
|
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 conduits (%d)", res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-28 13:50:07 -05:00
|
|
|
|
var data GetConduitsResponse
|
|
|
|
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &data, nil
|
|
|
|
|
}
|