Add requested changes

This commit is contained in:
IchBinLeoon 2022-05-29 15:08:38 +02:00
parent b53256ca3f
commit 29343d1c6f
3 changed files with 20 additions and 20 deletions

View file

@ -1,11 +1,13 @@
package crunchyroll
import "time"
// Account contains information about a crunchyroll account.
type Account struct {
AccountID string `json:"account_id"`
ExternalID string `json:"external_id"`
EmailVerified bool `json:"email_verified"`
Created string `json:"created"`
AccountID string `json:"account_id"`
ExternalID string `json:"external_id"`
EmailVerified bool `json:"email_verified"`
Created time.Time `json:"created"`
Avatar string `json:"avatar"`
CrBetaOptIn bool `json:"cr_beta_opt_in"`

View file

@ -79,8 +79,7 @@ type Episode struct {
type HistoryEpisode struct {
*Episode
ID string `json:"id"`
DatePlayed string `json:"date_played"`
DatePlayed time.Time `json:"date_played"`
ParentID string `json:"parent_id"`
ParentType MediaType `json:"parent_type"`
Playhead uint `json:"playhead"`

View file

@ -35,8 +35,19 @@ func encodeStructToQueryValues(s interface{}) (string, error) {
for i := 0; i < v.Type().NumField(); i++ {
// don't include parameters with default or without values in the query to avoid corruption of the API response.
if isEmptyValue(v.Field(i)) {
continue
switch v.Field(i).Kind() {
case reflect.Slice, reflect.String:
if v.Field(i).Len() == 0 {
continue
}
case reflect.Bool:
if !v.Field(i).Bool() {
continue
}
case reflect.Uint:
if v.Field(i).Uint() == 0 {
continue
}
}
key := v.Type().Field(i).Tag.Get("param")
@ -59,15 +70,3 @@ func encodeStructToQueryValues(s interface{}) (string, error) {
return values.Encode(), nil
}
func isEmptyValue(v reflect.Value) bool {
switch v.Kind() {
case reflect.Slice, reflect.String:
return v.Len() == 0
case reflect.Bool:
return !v.Bool()
case reflect.Uint:
return v.Uint() == 0
}
return false
}