2024-02-27 22:13:57 -05:00
|
|
|
|
package channels
|
|
|
|
|
|
|
|
|
|
import (
|
2024-02-27 23:03:40 -05:00
|
|
|
|
"context"
|
2024-02-27 22:13:57 -05:00
|
|
|
|
"encoding/json"
|
2024-02-27 23:03:40 -05:00
|
|
|
|
"net/http"
|
2024-02-27 22:13:57 -05:00
|
|
|
|
"net/url"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/google/go-querystring/query"
|
|
|
|
|
"go.fifitido.net/twitch/api/types"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type GetFollowedChannelsParams struct {
|
|
|
|
|
// A user’s ID. Returns the list of broadcasters that this user follows. This ID must match the user ID in the user OAuth token.
|
|
|
|
|
UserID string `url:"user_id"`
|
|
|
|
|
|
|
|
|
|
// A broadcaster’s ID. Use this parameter to see whether the user follows this broadcaster.
|
|
|
|
|
// If specified, the response contains this broadcaster if the user follows them.
|
|
|
|
|
// If not specified, the response contains all broadcasters that the user follows.
|
|
|
|
|
BroadcasterID *string `url:"broadcaster_id,omitempty"`
|
|
|
|
|
|
|
|
|
|
// The maximum number of items to return per page in the response. The minimum page size is 1 item per page and the maximum is 100. The default is 20.
|
|
|
|
|
First *int `url:"first,omitempty"`
|
|
|
|
|
|
|
|
|
|
// The cursor used to get the next page of results. The Pagination object in the response contains the cursor’s value.
|
|
|
|
|
// Read more: https://dev.twitch.tv/docs/api/guide#pagination
|
|
|
|
|
After *types.Cursor `url:"after,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type GetFollowedChannelsResponse struct {
|
|
|
|
|
// The list of broadcasters that the user follows.
|
|
|
|
|
// The list is in descending order by followed_at (with the most recently followed broadcaster first)
|
|
|
|
|
// The list is empty if the user doesn’t follow anyone.
|
|
|
|
|
Data []FollowedChannel `json:"data"`
|
|
|
|
|
|
|
|
|
|
// Contains the information used to page through the list of results. The object is empty if there are no more pages left to page through.
|
|
|
|
|
// Read more: https://dev.twitch.tv/docs/api/guide#pagination
|
|
|
|
|
Pagination types.Pagination `json:"pagination"`
|
|
|
|
|
|
|
|
|
|
// The total number of broadcasters that the user follows.
|
|
|
|
|
// As someone pages through the list, the number may change as the user follows or unfollows broadcasters.
|
|
|
|
|
Total int `json:"total"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type FollowedChannel struct {
|
|
|
|
|
// An ID that uniquely identifies the broadcaster that this user is following.
|
|
|
|
|
BroadcasterID string `json:"broadcaster_id"`
|
|
|
|
|
|
|
|
|
|
// The broadcaster’s login name.
|
|
|
|
|
BroadcasterLogin string `json:"broadcaster_login"`
|
|
|
|
|
|
|
|
|
|
// The broadcaster’s display name.
|
|
|
|
|
BroadcasterName string `json:"broadcaster_name"`
|
|
|
|
|
|
|
|
|
|
// The UTC timestamp when the user started following the broadcaster.
|
|
|
|
|
FollowedAt time.Time `json:"followed_at"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gets a list of broadcasters that the specified user follows. You can also use this endpoint to see whether a user follows a specific broadcaster.
|
|
|
|
|
//
|
|
|
|
|
// Requires a user access token that includes the user:read:follows scope.
|
2024-02-27 23:03:40 -05:00
|
|
|
|
func (c *Channels) GetFollowedChannels(ctx context.Context, params *GetFollowedChannelsParams) (*GetFollowedChannelsResponse, error) {
|
2024-02-27 22:13:57 -05:00
|
|
|
|
v, _ := query.Values(params)
|
|
|
|
|
endpoint := c.baseUrl.ResolveReference(&url.URL{Path: "users/follows", RawQuery: v.Encode()})
|
|
|
|
|
|
2024-02-27 23:03:40 -05:00
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint.String(), nil)
|
2024-02-27 22:13:57 -05:00
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-27 23:03:40 -05:00
|
|
|
|
res, err := c.client.Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defer res.Body.Close()
|
2024-02-27 22:13:57 -05:00
|
|
|
|
|
|
|
|
|
var data GetFollowedChannelsResponse
|
2024-02-27 23:03:40 -05:00
|
|
|
|
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
|
2024-02-27 22:13:57 -05:00
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &data, nil
|
|
|
|
|
}
|