go-client/trending.go
Deivid Soto f6f24c2c3f
Some checks failed
CI / Test (push) Failing after 1s
CI / Test-1 (push) Failing after 1s
CI / Test-2 (push) Failing after 1s
CI / Lint (push) Failing after 1s
CI / Vet (push) Failing after 1s
feat: implement TorrentClaw Go API client v0.1.0
2026-03-28 11:28:48 +01:00

60 lines
1.8 KiB
Go

package torrentclaw
import (
"context"
"net/url"
)
// TrendingParams holds the parameters for a trending content request.
type TrendingParams struct {
// Period sets the time window: "daily", "weekly", "monthly" (default "daily").
Period string
// Limit sets the number of items (1-50, default 20).
Limit int
// Page is the page number (starts at 1).
Page int
// Locale sets the language for localized titles.
Locale string
}
// TrendingItem represents a trending content item.
type TrendingItem struct {
ID int `json:"id"`
Title string `json:"title"`
Year *int `json:"year,omitempty"`
ContentType string `json:"contentType"`
PosterURL *string `json:"posterUrl,omitempty"`
RatingIMDb *string `json:"ratingImdb,omitempty"`
RatingTMDb *string `json:"ratingTmdb,omitempty"`
Overview *string `json:"overview,omitempty"`
MaxSeeders int `json:"maxSeeders"`
ClickCount int `json:"clickCount"`
TrendScore int `json:"trendScore"`
}
// TrendingResponse is the paginated response from the trending endpoint.
type TrendingResponse struct {
Period string `json:"period"`
Items []TrendingItem `json:"items"`
Total int `json:"total"`
Page int `json:"page"`
PageSize int `json:"pageSize"`
}
// Trending returns trending content for the given time period.
func (c *Client) Trending(ctx context.Context, params TrendingParams) (*TrendingResponse, error) {
q := url.Values{}
addStringParam(q, "period", params.Period)
addIntParam(q, "limit", params.Limit)
addIntParam(q, "page", params.Page)
addStringParam(q, "locale", params.Locale)
var resp TrendingResponse
if err := c.doJSON(ctx, "/api/v1/trending", q, &resp); err != nil {
return nil, err
}
return &resp, nil
}