go-twitch/api/conduit/get_conduits.go

44 lines
933 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package conduit
import (
"context"
"encoding/json"
"fmt"
"net/http"
"go.fifitido.net/twitch/api/endpoint"
)
type GetConduitsResponse struct {
// List of information about the clients 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) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.Make(c.baseUrl, "eventsub/conduits"), 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 conduits (%d)", res.StatusCode)
}
var data GetConduitsResponse
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
return nil, err
}
return &data, nil
}