Initial commit
This commit is contained in:
commit
02a6dabcfb
62 files changed
+15751
No files matched your search
@@ -0,0 +1,315 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// AccountSettings represents account settings
|
||||
type AccountSettings struct {
|
||||
BaseModel
|
||||
Language string `json:"language"`
|
||||
Region string `json:"region"`
|
||||
Email string `json:"email"`
|
||||
Phone string `json:"phone"`
|
||||
Notifications bool `json:"notifications"`
|
||||
AutoPlay bool `json:"auto_play"`
|
||||
HighQuality bool `json:"high_quality"`
|
||||
CacheSize int `json:"cache_size"`
|
||||
DownloadQuality string `json:"download_quality"`
|
||||
ExplicitContent bool `json:"explicit_content"`
|
||||
NormalizeVolume bool `json:"normalize_volume"`
|
||||
Crossfade bool `json:"crossfade"`
|
||||
GaplessPlayback bool `json:"gapless_playback"`
|
||||
ShowLyrics bool `json:"show_lyrics"`
|
||||
ShowCredits bool `json:"show_credits"`
|
||||
AutoDownload bool `json:"auto_download"`
|
||||
DownloadOnWifiOnly bool `json:"download_on_wifi_only"`
|
||||
}
|
||||
|
||||
// DeJSON deserializes AccountSettings from JSON
|
||||
func (a *AccountSettings) DeJSON(data []byte, c ClientInterface) (Model, error) {
|
||||
var raw map[string]json.RawMessage
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
settings := &AccountSettings{BaseModel: *NewBaseModel(c)}
|
||||
|
||||
if v, ok := raw["language"]; ok {
|
||||
json.Unmarshal(v, &settings.Language)
|
||||
}
|
||||
if v, ok := raw["region"]; ok {
|
||||
json.Unmarshal(v, &settings.Region)
|
||||
}
|
||||
if v, ok := raw["email"]; ok {
|
||||
json.Unmarshal(v, &settings.Email)
|
||||
}
|
||||
if v, ok := raw["phone"]; ok {
|
||||
json.Unmarshal(v, &settings.Phone)
|
||||
}
|
||||
if v, ok := raw["notifications"]; ok {
|
||||
json.Unmarshal(v, &settings.Notifications)
|
||||
}
|
||||
if v, ok := raw["auto_play"]; ok {
|
||||
json.Unmarshal(v, &settings.AutoPlay)
|
||||
}
|
||||
if v, ok := raw["high_quality"]; ok {
|
||||
json.Unmarshal(v, &settings.HighQuality)
|
||||
}
|
||||
if v, ok := raw["cache_size"]; ok {
|
||||
json.Unmarshal(v, &settings.CacheSize)
|
||||
}
|
||||
if v, ok := raw["download_quality"]; ok {
|
||||
json.Unmarshal(v, &settings.DownloadQuality)
|
||||
}
|
||||
if v, ok := raw["explicit_content"]; ok {
|
||||
json.Unmarshal(v, &settings.ExplicitContent)
|
||||
}
|
||||
if v, ok := raw["normalize_volume"]; ok {
|
||||
json.Unmarshal(v, &settings.NormalizeVolume)
|
||||
}
|
||||
if v, ok := raw["crossfade"]; ok {
|
||||
json.Unmarshal(v, &settings.Crossfade)
|
||||
}
|
||||
if v, ok := raw["gapless_playback"]; ok {
|
||||
json.Unmarshal(v, &settings.GaplessPlayback)
|
||||
}
|
||||
if v, ok := raw["show_lyrics"]; ok {
|
||||
json.Unmarshal(v, &settings.ShowLyrics)
|
||||
}
|
||||
if v, ok := raw["show_credits"]; ok {
|
||||
json.Unmarshal(v, &settings.ShowCredits)
|
||||
}
|
||||
if v, ok := raw["auto_download"]; ok {
|
||||
json.Unmarshal(v, &settings.AutoDownload)
|
||||
}
|
||||
if v, ok := raw["download_on_wifi_only"]; ok {
|
||||
json.Unmarshal(v, &settings.DownloadOnWifiOnly)
|
||||
}
|
||||
|
||||
return settings, nil
|
||||
}
|
||||
|
||||
// DeList deserializes a list of AccountSettings
|
||||
func (a *AccountSettings) DeList(data []byte, c ClientInterface) ([]Model, error) {
|
||||
var rawList []json.RawMessage
|
||||
if err := json.Unmarshal(data, &rawList); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make([]Model, 0, len(rawList))
|
||||
for _, item := range rawList {
|
||||
settings := &AccountSettings{BaseModel: *NewBaseModel(c)}
|
||||
if err := json.Unmarshal(item, settings); err != nil {
|
||||
continue
|
||||
}
|
||||
result = append(result, settings)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Subscription represents subscription info
|
||||
type Subscription struct {
|
||||
BaseModel
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Status string `json:"status"`
|
||||
StartDate string `json:"start_date"`
|
||||
EndDate string `json:"end_date"`
|
||||
AutoRenew bool `json:"auto_renew"`
|
||||
PaymentMethod string `json:"payment_method"`
|
||||
Price int `json:"price"`
|
||||
Currency string `json:"currency"`
|
||||
Features []string `json:"features"`
|
||||
CanCancel bool `json:"can_cancel"`
|
||||
CanUpgrade bool `json:"can_upgrade"`
|
||||
TrialAvailable bool `json:"trial_available"`
|
||||
TrialUsed bool `json:"trial_used"`
|
||||
}
|
||||
|
||||
// DeJSON deserializes Subscription from JSON
|
||||
func (s *Subscription) DeJSON(data []byte, c ClientInterface) (Model, error) {
|
||||
var raw map[string]json.RawMessage
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sub := &Subscription{BaseModel: *NewBaseModel(c)}
|
||||
|
||||
if v, ok := raw["id"]; ok {
|
||||
json.Unmarshal(v, &sub.ID)
|
||||
}
|
||||
if v, ok := raw["type"]; ok {
|
||||
json.Unmarshal(v, &sub.Type)
|
||||
}
|
||||
if v, ok := raw["status"]; ok {
|
||||
json.Unmarshal(v, &sub.Status)
|
||||
}
|
||||
if v, ok := raw["start_date"]; ok {
|
||||
json.Unmarshal(v, &sub.StartDate)
|
||||
}
|
||||
if v, ok := raw["end_date"]; ok {
|
||||
json.Unmarshal(v, &sub.EndDate)
|
||||
}
|
||||
if v, ok := raw["auto_renew"]; ok {
|
||||
json.Unmarshal(v, &sub.AutoRenew)
|
||||
}
|
||||
if v, ok := raw["payment_method"]; ok {
|
||||
json.Unmarshal(v, &sub.PaymentMethod)
|
||||
}
|
||||
if v, ok := raw["price"]; ok {
|
||||
json.Unmarshal(v, &sub.Price)
|
||||
}
|
||||
if v, ok := raw["currency"]; ok {
|
||||
json.Unmarshal(v, &sub.Currency)
|
||||
}
|
||||
if v, ok := raw["features"]; ok {
|
||||
json.Unmarshal(v, &sub.Features)
|
||||
}
|
||||
if v, ok := raw["can_cancel"]; ok {
|
||||
json.Unmarshal(v, &sub.CanCancel)
|
||||
}
|
||||
if v, ok := raw["can_upgrade"]; ok {
|
||||
json.Unmarshal(v, &sub.CanUpgrade)
|
||||
}
|
||||
if v, ok := raw["trial_available"]; ok {
|
||||
json.Unmarshal(v, &sub.TrialAvailable)
|
||||
}
|
||||
if v, ok := raw["trial_used"]; ok {
|
||||
json.Unmarshal(v, &sub.TrialUsed)
|
||||
}
|
||||
|
||||
return sub, nil
|
||||
}
|
||||
|
||||
// DeList deserializes a list of Subscriptions
|
||||
func (s *Subscription) DeList(data []byte, c ClientInterface) ([]Model, error) {
|
||||
var rawList []json.RawMessage
|
||||
if err := json.Unmarshal(data, &rawList); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make([]Model, 0, len(rawList))
|
||||
for _, item := range rawList {
|
||||
sub := &Subscription{BaseModel: *NewBaseModel(c)}
|
||||
if err := json.Unmarshal(item, sub); err != nil {
|
||||
continue
|
||||
}
|
||||
result = append(result, sub)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// PlusInfo represents Plus subscription info (from /account/plus or account status)
|
||||
type PlusInfo struct {
|
||||
BaseModel
|
||||
HasPlus bool `json:"has_plus"`
|
||||
IsTutorialCompleted bool `json:"is_tutorial_completed"`
|
||||
Migrated *bool `json:"migrated,omitempty"`
|
||||
}
|
||||
|
||||
// DeJSON deserializes PlusInfo from JSON
|
||||
func (p *PlusInfo) DeJSON(data []byte, c ClientInterface) (Model, error) {
|
||||
var raw map[string]json.RawMessage
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
plus := &PlusInfo{BaseModel: *NewBaseModel(c)}
|
||||
|
||||
if v, ok := raw["has_plus"]; ok {
|
||||
json.Unmarshal(v, &plus.HasPlus)
|
||||
}
|
||||
if v, ok := raw["is_tutorial_completed"]; ok {
|
||||
json.Unmarshal(v, &plus.IsTutorialCompleted)
|
||||
}
|
||||
if v, ok := raw["migrated"]; ok {
|
||||
var val bool
|
||||
json.Unmarshal(v, &val)
|
||||
plus.Migrated = &val
|
||||
}
|
||||
|
||||
return plus, nil
|
||||
}
|
||||
|
||||
// DeList deserializes a list of PlusInfo
|
||||
func (p *PlusInfo) DeList(data []byte, c ClientInterface) ([]Model, error) {
|
||||
var rawList []json.RawMessage
|
||||
if err := json.Unmarshal(data, &rawList); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make([]Model, 0, len(rawList))
|
||||
for _, item := range rawList {
|
||||
plus := &PlusInfo{BaseModel: *NewBaseModel(c)}
|
||||
if err := json.Unmarshal(item, plus); err != nil {
|
||||
continue
|
||||
}
|
||||
result = append(result, plus)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// PromoCodeStatus represents promo code status
|
||||
type PromoCodeStatus struct {
|
||||
BaseModel
|
||||
Code string `json:"code"`
|
||||
Status string `json:"status"`
|
||||
Description string `json:"description"`
|
||||
Discount int `json:"discount"`
|
||||
Months int `json:"months"`
|
||||
ExpiresAt string `json:"expires_at"`
|
||||
Activated bool `json:"activated"`
|
||||
}
|
||||
|
||||
// DeJSON deserializes PromoCodeStatus from JSON
|
||||
func (p *PromoCodeStatus) DeJSON(data []byte, c ClientInterface) (Model, error) {
|
||||
var raw map[string]json.RawMessage
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
promo := &PromoCodeStatus{BaseModel: *NewBaseModel(c)}
|
||||
|
||||
if v, ok := raw["code"]; ok {
|
||||
json.Unmarshal(v, &promo.Code)
|
||||
}
|
||||
if v, ok := raw["status"]; ok {
|
||||
json.Unmarshal(v, &promo.Status)
|
||||
}
|
||||
if v, ok := raw["description"]; ok {
|
||||
json.Unmarshal(v, &promo.Description)
|
||||
}
|
||||
if v, ok := raw["discount"]; ok {
|
||||
json.Unmarshal(v, &promo.Discount)
|
||||
}
|
||||
if v, ok := raw["months"]; ok {
|
||||
json.Unmarshal(v, &promo.Months)
|
||||
}
|
||||
if v, ok := raw["expires_at"]; ok {
|
||||
json.Unmarshal(v, &promo.ExpiresAt)
|
||||
}
|
||||
if v, ok := raw["activated"]; ok {
|
||||
json.Unmarshal(v, &promo.Activated)
|
||||
}
|
||||
|
||||
return promo, nil
|
||||
}
|
||||
|
||||
// DeList deserializes a list of PromoCodeStatus
|
||||
func (p *PromoCodeStatus) DeList(data []byte, c ClientInterface) ([]Model, error) {
|
||||
var rawList []json.RawMessage
|
||||
if err := json.Unmarshal(data, &rawList); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make([]Model, 0, len(rawList))
|
||||
for _, item := range rawList {
|
||||
promo := &PromoCodeStatus{BaseModel: *NewBaseModel(c)}
|
||||
if err := json.Unmarshal(item, promo); err != nil {
|
||||
continue
|
||||
}
|
||||
result = append(result, promo)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
Reference in new issue
Block a user