YTSFlix_Go/ytsclient/requests.go

62 lines
1.3 KiB
Go
Raw Normal View History

2018-11-04 14:58:15 +00:00
package ytsclient
import (
r "github.com/levigross/grequests"
"strconv"
)
type ListParams struct {
Limit int
Page int
Quality Quality
MinimumRating int
QueryTerm string
Genre Genre
SortBy SortBy
OrderBy Order
WithRottenTomatoesRating bool
}
func (l *ListParams) format() *r.RequestOptions {
p := map[string]string{}
if l.Limit != 0 {
p["limit"] = strconv.Itoa(l.Limit)
}
if l.Page != 0 {
p["page"] = strconv.Itoa(l.Page)
}
if l.Quality != "" {
p["quality"] = string(l.Quality)
}
if l.MinimumRating != 0 {
p["minimum_rating"] = strconv.Itoa(l.MinimumRating)
}
if l.QueryTerm != "" {
p["query_term"] = l.QueryTerm
}
if l.Genre != "" {
p["genre"] = string(l.Genre)
}
if l.SortBy != "" {
p["sort_by"] = string(l.SortBy)
}
if l.Genre != "" {
p["order_by"] = string(l.Genre)
}
p["with_rt_ratings"] = strconv.FormatBool(l.WithRottenTomatoesRating)
return &r.RequestOptions{Params: p}
}
type MovieParams struct {
WithImages bool
WithCast bool
}
func (m *MovieParams) format() *r.RequestOptions {
p := map[string]string{
"with_images": strconv.FormatBool(m.WithImages),
"with_cast": strconv.FormatBool(m.WithCast),
}
return &r.RequestOptions{Params: p}
}