-
Notifications
You must be signed in to change notification settings - Fork 19
/
catalog_charts.go
96 lines (79 loc) · 2.81 KB
/
catalog_charts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package applemusic
import (
"context"
"fmt"
)
// ChartAlbums represents a chart of albums.
type ChartAlbums struct {
Name string `json:"name"`
Chart string `json:"chart"`
Albums
}
// ChartSongs represents a chart of songs.
type ChartSongs struct {
Name string `json:"name"`
Chart string `json:"chart"`
Songs
}
// ChartMusicVideos represents a chart of music videos.
type ChartMusicVideos struct {
Name string `json:"name"`
Chart string `json:"chart"`
MusicVideos
}
// ChartPlaylists represent a chart of playlists.
type ChartPlaylists struct {
Name string `json:"name"`
Chart string `json:"chart"`
Playlists
}
// ChartResults represents a results, that contains chart collections.
type ChartResults struct {
Albums *[]ChartAlbums `json:"albums,omitempty"`
Songs *[]ChartSongs `json:"songs,omitempty"`
MusicVideos *[]ChartMusicVideos `json:"music-videos,omitempty"`
Playlists *[]ChartPlaylists `json:"playlists,omitempty"`
}
// Charts represents the result of one or more charts.
type Charts struct {
Results ChartResults `json:"results"`
}
// ChartsOptions specifies the parameters to fetch charts.
type ChartsOptions struct {
// A list of the types of charts to include in the results.
// The possible values are albums, songs, and music-videos.
Types string `url:"types"`
// (Optional) The localization to use, specified by a language tag.
// The possible values are in the supportedLanguageTags array belonging to the Storefront object specified by storefront.
// Otherwise, the storefront’s defaultLanguageTag is used.
Language string `url:"l,omitempty"`
// (Optional) The chart to fetch for the specified types.
// For possible values, get all the charts by sending this endpoint without the chart parameter.
// The possible values for this parameter are the chart attributes of the Chart objects in the response.
Chart string `url:"chart,omitempty"`
// (Optional) The identifier for the genre to use in the chart results. To get the genre identifiers.
Genre string `url:"genre,omitempty"`
// (Optional) The number of resources to include per chart.
// The default value is 20 and the maximum value is 50.
Limit int `url:"limit,omitempty"`
// (Optional; only with chart specified) The next page or group of objects to fetch.
Offset int `url:"offset,omitempty"`
}
// GetAllCharts fetches one or more charts.
func (s *CatalogService) GetAllCharts(ctx context.Context, storefront string, opt *ChartsOptions) (*Charts, *Response, error) {
u := fmt.Sprintf("v1/catalog/%s/charts", storefront)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
charts := &Charts{}
resp, err := s.client.Do(ctx, req, charts)
if err != nil {
return nil, resp, err
}
return charts, resp, nil
}