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 package crunchyroll
import "time"
// Account contains information about a crunchyroll account. // Account contains information about a crunchyroll account.
type Account struct { type Account struct {
AccountID string `json:"account_id"` AccountID string `json:"account_id"`
ExternalID string `json:"external_id"` ExternalID string `json:"external_id"`
EmailVerified bool `json:"email_verified"` EmailVerified bool `json:"email_verified"`
Created string `json:"created"` Created time.Time `json:"created"`
Avatar string `json:"avatar"` Avatar string `json:"avatar"`
CrBetaOptIn bool `json:"cr_beta_opt_in"` CrBetaOptIn bool `json:"cr_beta_opt_in"`

View file

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

View file

@ -35,9 +35,20 @@ func encodeStructToQueryValues(s interface{}) (string, error) {
for i := 0; i < v.Type().NumField(); i++ { 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. // don't include parameters with default or without values in the query to avoid corruption of the API response.
if isEmptyValue(v.Field(i)) { switch v.Field(i).Kind() {
case reflect.Slice, reflect.String:
if v.Field(i).Len() == 0 {
continue 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") key := v.Type().Field(i).Tag.Get("param")
var val string var val string
@ -59,15 +70,3 @@ func encodeStructToQueryValues(s interface{}) (string, error) {
return values.Encode(), nil 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
}