mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Add requested changes
This commit is contained in:
parent
b53256ca3f
commit
29343d1c6f
3 changed files with 20 additions and 20 deletions
|
|
@ -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"`
|
||||
Created time.Time `json:"created"`
|
||||
|
||||
Avatar string `json:"avatar"`
|
||||
CrBetaOptIn bool `json:"cr_beta_opt_in"`
|
||||
|
|
|
|||
|
|
@ -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"`
|
||||
|
|
|
|||
25
utils.go
25
utils.go
|
|
@ -35,9 +35,20 @@ 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)) {
|
||||
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")
|
||||
var val string
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue