45 lines
954 B
Go
45 lines
954 B
Go
package conduit
|
||
|
||
import (
|
||
"context"
|
||
"encoding/json"
|
||
"fmt"
|
||
"net/http"
|
||
"net/url"
|
||
)
|
||
|
||
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) {
|
||
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "eventsub/conduits"})
|
||
|
||
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()
|
||
|
||
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
|
||
}
|