diff --git a/account.go b/account.go index f6f87f1..d22eba5 100644 --- a/account.go +++ b/account.go @@ -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"` diff --git a/episode.go b/episode.go index 07f6705..de38c65 100644 --- a/episode.go +++ b/episode.go @@ -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"` diff --git a/utils.go b/utils.go index 672772f..d32d39b 100644 --- a/utils.go +++ b/utils.go @@ -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 -}