- Document all exported types, functions, methods, and constants across 52 files - Add package-level doc comments to client, models, utils, and ynison packages - Document HTTP method and endpoint path for each API client method - Document model struct fields and DeJSON/DeList/ToJSON/ToMap methods - Fix duplicate package doc comment in internal/models/base.go Co-Authored-By: Claude Code <noreply@anthropic.com>
312 lines
7.8 KiB
Go
312 lines
7.8 KiB
Go
// Package models provides data models for the Yandex Music API.
|
|
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
)
|
|
|
|
// Metatag represents a metatag from the Yandex Music API.
|
|
type Metatag struct {
|
|
BaseModel
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
Image string `json:"image"`
|
|
Type string `json:"type"`
|
|
Position int `json:"position"`
|
|
Children []Metatag `json:"children"`
|
|
}
|
|
|
|
// DeJSON deserializes a Metatag from JSON data.
|
|
func (m *Metatag) DeJSON(data []byte, client ClientInterface) (Model, error) {
|
|
var raw map[string]json.RawMessage
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
metatag := &Metatag{BaseModel: *NewBaseModel(client)}
|
|
|
|
if v, ok := raw["id"]; ok {
|
|
json.Unmarshal(v, &metatag.ID)
|
|
}
|
|
if v, ok := raw["title"]; ok {
|
|
json.Unmarshal(v, &metatag.Title)
|
|
}
|
|
if v, ok := raw["description"]; ok {
|
|
json.Unmarshal(v, &metatag.Description)
|
|
}
|
|
if v, ok := raw["image"]; ok {
|
|
json.Unmarshal(v, &metatag.Image)
|
|
}
|
|
if v, ok := raw["type"]; ok {
|
|
json.Unmarshal(v, &metatag.Type)
|
|
}
|
|
if v, ok := raw["position"]; ok {
|
|
json.Unmarshal(v, &metatag.Position)
|
|
}
|
|
if v, ok := raw["children"]; ok {
|
|
var children []Metatag
|
|
json.Unmarshal(v, &children)
|
|
metatag.Children = children
|
|
}
|
|
|
|
return metatag, nil
|
|
}
|
|
|
|
// DeList deserializes a list of Metatags from JSON data.
|
|
func (m *Metatag) DeList(data []byte, client 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 {
|
|
metatag := &Metatag{BaseModel: *NewBaseModel(client)}
|
|
if err := json.Unmarshal(item, metatag); err != nil {
|
|
continue
|
|
}
|
|
result = append(result, metatag)
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
// MetatagTree represents a metatag tree.
|
|
type MetatagTree struct {
|
|
BaseModel
|
|
Root *Metatag `json:"root"`
|
|
Leaves []Metatag `json:"leaves"`
|
|
}
|
|
|
|
// MetatagLeaf represents a metatag leaf.
|
|
type MetatagLeaf struct {
|
|
BaseModel
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
Image string `json:"image"`
|
|
Type string `json:"type"`
|
|
Position int `json:"position"`
|
|
}
|
|
|
|
// MetatagArtists represents metatag artists.
|
|
type MetatagArtists struct {
|
|
BaseModel
|
|
Artists []Artist `json:"artists"`
|
|
Total int `json:"total"`
|
|
Page int `json:"page"`
|
|
PageSize int `json:"page_size"`
|
|
}
|
|
|
|
// MetatagAlbums represents metatag albums.
|
|
type MetatagAlbums struct {
|
|
BaseModel
|
|
Albums []Album `json:"albums"`
|
|
Total int `json:"total"`
|
|
Page int `json:"page"`
|
|
PageSize int `json:"page_size"`
|
|
}
|
|
|
|
// MetatagPlaylists represents metatag playlists.
|
|
type MetatagPlaylists struct {
|
|
BaseModel
|
|
Playlists []Playlist `json:"playlists"`
|
|
Total int `json:"total"`
|
|
Page int `json:"page"`
|
|
PageSize int `json:"page_size"`
|
|
}
|
|
|
|
// MetatagTitle represents a metatag title.
|
|
type MetatagTitle struct {
|
|
BaseModel
|
|
Title string `json:"title"`
|
|
}
|
|
|
|
// MetatagSortByValue represents metatag sort by value.
|
|
type MetatagSortByValue struct {
|
|
BaseModel
|
|
Value string `json:"value"`
|
|
Label string `json:"label"`
|
|
}
|
|
|
|
// MetatagArtistEntry represents a metatag artist entry.
|
|
type MetatagArtistEntry struct {
|
|
BaseModel
|
|
Artist *Artist `json:"artist"`
|
|
Score float64 `json:"score"`
|
|
}
|
|
|
|
// Genre represents a genre from the Yandex Music API.
|
|
type Genre struct {
|
|
BaseModel
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
Image string `json:"image"`
|
|
Position int `json:"position"`
|
|
ParentID string `json:"parent_id"`
|
|
Children []Genre `json:"children"`
|
|
}
|
|
|
|
// DeJSON deserializes a Genre from JSON data.
|
|
func (g *Genre) DeJSON(data []byte, client ClientInterface) (Model, error) {
|
|
var raw map[string]json.RawMessage
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
genre := &Genre{BaseModel: *NewBaseModel(client)}
|
|
|
|
if v, ok := raw["id"]; ok {
|
|
json.Unmarshal(v, &genre.ID)
|
|
}
|
|
if v, ok := raw["title"]; ok {
|
|
json.Unmarshal(v, &genre.Title)
|
|
}
|
|
if v, ok := raw["description"]; ok {
|
|
json.Unmarshal(v, &genre.Description)
|
|
}
|
|
if v, ok := raw["image"]; ok {
|
|
json.Unmarshal(v, &genre.Image)
|
|
}
|
|
if v, ok := raw["position"]; ok {
|
|
json.Unmarshal(v, &genre.Position)
|
|
}
|
|
if v, ok := raw["parent_id"]; ok {
|
|
json.Unmarshal(v, &genre.ParentID)
|
|
}
|
|
if v, ok := raw["children"]; ok {
|
|
var children []Genre
|
|
json.Unmarshal(v, &children)
|
|
genre.Children = children
|
|
}
|
|
|
|
return genre, nil
|
|
}
|
|
|
|
// DeList deserializes a list of Genres from JSON data.
|
|
func (g *Genre) DeList(data []byte, client 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 {
|
|
genre := &Genre{BaseModel: *NewBaseModel(client)}
|
|
if err := json.Unmarshal(item, genre); err != nil {
|
|
continue
|
|
}
|
|
result = append(result, genre)
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
// Chart represents a chart from the Yandex Music API.
|
|
type Chart struct {
|
|
BaseModel
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
CoverURI string `json:"cover_uri"`
|
|
Type string `json:"type"`
|
|
Items []ChartItem `json:"items"`
|
|
}
|
|
|
|
// DeJSON deserializes a Chart from JSON data.
|
|
func (c *Chart) DeJSON(data []byte, client ClientInterface) (Model, error) {
|
|
var raw map[string]json.RawMessage
|
|
if err := json.Unmarshal(data, &raw); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
chart := &Chart{BaseModel: *NewBaseModel(client)}
|
|
|
|
if v, ok := raw["id"]; ok {
|
|
json.Unmarshal(v, &chart.ID)
|
|
}
|
|
if v, ok := raw["title"]; ok {
|
|
json.Unmarshal(v, &chart.Title)
|
|
}
|
|
if v, ok := raw["description"]; ok {
|
|
json.Unmarshal(v, &chart.Description)
|
|
}
|
|
if v, ok := raw["cover_uri"]; ok {
|
|
json.Unmarshal(v, &chart.CoverURI)
|
|
}
|
|
if v, ok := raw["type"]; ok {
|
|
json.Unmarshal(v, &chart.Type)
|
|
}
|
|
if v, ok := raw["items"]; ok {
|
|
var items []ChartItem
|
|
json.Unmarshal(v, &items)
|
|
chart.Items = items
|
|
}
|
|
|
|
return chart, nil
|
|
}
|
|
|
|
// DeList deserializes a list of Charts from JSON data.
|
|
func (c *Chart) DeList(data []byte, client 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 {
|
|
chart := &Chart{BaseModel: *NewBaseModel(client)}
|
|
if err := json.Unmarshal(item, chart); err != nil {
|
|
continue
|
|
}
|
|
result = append(result, chart)
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
// ChartInfo represents chart info.
|
|
type ChartInfo struct {
|
|
BaseModel
|
|
Chart *Chart `json:"chart"`
|
|
Menu []ChartInfoMenu `json:"menu"`
|
|
}
|
|
|
|
// ChartItem represents a chart item.
|
|
type ChartItem struct {
|
|
BaseModel
|
|
Position int `json:"position"`
|
|
Track *Track `json:"track"`
|
|
Artist *Artist `json:"artist"`
|
|
Album *Album `json:"album"`
|
|
Playlist *Playlist `json:"playlist"`
|
|
Score float64 `json:"score"`
|
|
Trend string `json:"trend"`
|
|
}
|
|
|
|
// ChartInfoMenu represents a chart info menu.
|
|
type ChartInfoMenu struct {
|
|
BaseModel
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
Items []ChartInfoMenuItem `json:"items"`
|
|
}
|
|
|
|
// ChartInfoMenuItem represents a chart info menu item.
|
|
type ChartInfoMenuItem struct {
|
|
BaseModel
|
|
ID string `json:"id"`
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
Action string `json:"action"`
|
|
}
|
|
|
|
// ChartItems represents chart items response.
|
|
type ChartItems struct {
|
|
BaseModel
|
|
Items []ChartItem `json:"items"`
|
|
Total int `json:"total"`
|
|
Page int `json:"page"`
|
|
PageSize int `json:"page_size"`
|
|
}
|