-
Notifications
You must be signed in to change notification settings - Fork 19
/
storefronts.go
executable file
·78 lines (64 loc) · 2.19 KB
/
storefronts.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
package applemusic
import (
"context"
"fmt"
)
// StorefrontsService handles communication with the storefront related methods of the Apple Music API.
type StorefrontsService service
// StorefrontAttributes represents a to-one or to-many relationship from one resource object to others.
type StorefrontAttributes struct {
DefaultLanguageTag string `json:"defaultLanguageTag"`
Name string `json:"name"`
SupportedLanguageTags []string `json:"supportedLanguageTags"`
}
// Storefront represents a storefront, an iTunes Store territory that the content is available in.
type Storefront struct {
Id string `json:"id"`
Type string `json:"type"`
Href string `json:"href"`
Attributes StorefrontAttributes `json:"attributes"`
}
// Storefronts represents a list of storefronts.
type Storefronts struct {
Data []Storefront `json:"data"`
Next string `json:"next,omitempty"`
}
func (s *StorefrontsService) get(ctx context.Context, u string) (*Storefronts, *Response, error) {
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
storefronts := &Storefronts{}
resp, err := s.client.Do(ctx, req, storefronts)
if err != nil {
return nil, resp, err
}
return storefronts, resp, nil
}
// Get fetches a single storefront using its identifier.
func (s *StorefrontsService) Get(ctx context.Context, id string, opt *Options) (*Storefronts, *Response, error) {
u := fmt.Sprintf("v1/storefronts/%s", id)
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
return s.get(ctx, u)
}
// GetByIds fetches multiple storefronts by ids.
func (s *StorefrontsService) GetByIds(ctx context.Context, ids []string, opt *Options) (*Storefronts, *Response, error) {
u := "v1/storefronts"
u, err := addOptions(u, makeIdsOptions(ids, opt))
if err != nil {
return nil, nil, err
}
return s.get(ctx, u)
}
// GetAll fetches all the storefronts in alphabetical order.
func (s *StorefrontsService) GetAll(ctx context.Context, opt *PageOptions) (*Storefronts, *Response, error) {
u := "v1/storefronts"
u, err := addOptions(u, opt)
if err != nil {
return nil, nil, err
}
return s.get(ctx, u)
}