-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.go
More file actions
180 lines (147 loc) · 6.38 KB
/
Copy pathclient.go
File metadata and controls
180 lines (147 loc) · 6.38 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// Package listennotes provides an API client to access the listennotes API found here: https://listen-api.listennotes.com/.
// API documentation can be found at https://www.listennotes.com/api/docs/.
package listennotes
import (
"fmt"
"net/http"
"net/url"
)
// HTTPClient is the client interface
type HTTPClient interface {
Search(args map[string]string) (*Response, error)
Typeahead(args map[string]string) (*Response, error)
SearchEpisodeTitles(args map[string]string) (*Response, error)
SpellCheck(args map[string]string) (*Response, error)
FetchRelatedSearches(args map[string]string) (*Response, error)
FetchTrendingSearches(args map[string]string) (*Response, error)
FetchBestPodcasts(args map[string]string) (*Response, error)
FetchPodcastByID(id string, args map[string]string) (*Response, error)
FetchEpisodeByID(id string, args map[string]string) (*Response, error)
BatchFetchEpisodes(args map[string]string) (*Response, error)
BatchFetchPodcasts(args map[string]string) (*Response, error)
FetchCuratedPodcastsListByID(id string, args map[string]string) (*Response, error)
FetchPodcastGenres(args map[string]string) (*Response, error)
FetchPodcastRegions(args map[string]string) (*Response, error)
FetchPodcastLanguages(args map[string]string) (*Response, error)
JustListen(args map[string]string) (*Response, error)
FetchCuratedPodcastsLists(args map[string]string) (*Response, error)
FetchRecommendationsForPodcast(id string, args map[string]string) (*Response, error)
FetchRecommendationsForEpisode(id string, args map[string]string) (*Response, error)
FetchMyPlaylists(args map[string]string) (*Response, error)
FetchPlaylistByID(id string, args map[string]string) (*Response, error)
SubmitPodcast(args map[string]string) (*Response, error)
DeletePodcast(id string, args map[string]string) (*Response, error)
FetchAudienceForPodcast(id string, args map[string]string) (*Response, error)
FetchPodcastsByDomain(domainName string, args map[string]string) (*Response, error)
}
type standardHTTPClient struct {
apiKey string
httpClient *http.Client
baseURL string
}
var _ HTTPClient = &standardHTTPClient{}
// NewClient will create a client with reasonable defaults.
// If an apiKey is not provided, the client will use the mock test API by default.
// You can optionally override some configuration.
func NewClient(apiKey string, opts ...ClientOption) HTTPClient {
baseURL := BaseURLTest
if apiKey != "" {
baseURL = BaseURLProduction
}
client := &standardHTTPClient{
apiKey: apiKey,
httpClient: defaultHTTPClient,
baseURL: baseURL,
}
for _, opt := range opts {
opt(client)
}
return client
}
func (c *standardHTTPClient) Search(args map[string]string) (*Response, error) {
return c.get("search", args)
}
func (c *standardHTTPClient) SearchEpisodeTitles(args map[string]string) (*Response, error) {
return c.get("search_episode_titles", args)
}
func (c *standardHTTPClient) Typeahead(args map[string]string) (*Response, error) {
return c.get("typeahead", args)
}
func (c *standardHTTPClient) SpellCheck(args map[string]string) (*Response, error) {
return c.get("spellcheck", args)
}
func (c *standardHTTPClient) FetchRelatedSearches(args map[string]string) (*Response, error) {
return c.get("related_searches", args)
}
func (c *standardHTTPClient) FetchTrendingSearches(args map[string]string) (*Response, error) {
return c.get("trending_searches", args)
}
func (c *standardHTTPClient) FetchBestPodcasts(args map[string]string) (*Response, error) {
return c.get("best_podcasts", args)
}
func (c *standardHTTPClient) FetchPodcastByID(id string, args map[string]string) (*Response, error) {
return c.get(fmt.Sprintf("podcasts/%s", id), args)
}
func (c *standardHTTPClient) FetchEpisodeByID(id string, args map[string]string) (*Response, error) {
return c.get(fmt.Sprintf("episodes/%s", id), args)
}
func (c *standardHTTPClient) BatchFetchEpisodes(args map[string]string) (*Response, error) {
values := url.Values{}
for k, v := range args {
values.Set(k, v)
}
return c.post("episodes", args, values)
}
func (c *standardHTTPClient) BatchFetchPodcasts(args map[string]string) (*Response, error) {
values := url.Values{}
for k, v := range args {
values.Set(k, v)
}
return c.post("podcasts", args, values)
}
func (c *standardHTTPClient) FetchCuratedPodcastsListByID(id string, args map[string]string) (*Response, error) {
return c.get(fmt.Sprintf("curated_podcasts/%s", id), args)
}
func (c *standardHTTPClient) FetchPodcastGenres(args map[string]string) (*Response, error) {
return c.get("genres", args)
}
func (c *standardHTTPClient) FetchPodcastRegions(args map[string]string) (*Response, error) {
return c.get("regions", args)
}
func (c *standardHTTPClient) FetchPodcastLanguages(args map[string]string) (*Response, error) {
return c.get("languages", args)
}
func (c *standardHTTPClient) JustListen(args map[string]string) (*Response, error) {
return c.get("just_listen", args)
}
func (c *standardHTTPClient) FetchCuratedPodcastsLists(args map[string]string) (*Response, error) {
return c.get("curated_podcasts", args)
}
func (c *standardHTTPClient) FetchRecommendationsForPodcast(id string, args map[string]string) (*Response, error) {
return c.get(fmt.Sprintf("podcasts/%s/recommendations", id), args)
}
func (c *standardHTTPClient) FetchRecommendationsForEpisode(id string, args map[string]string) (*Response, error) {
return c.get(fmt.Sprintf("episodes/%s/recommendations", id), args)
}
func (c *standardHTTPClient) FetchMyPlaylists(args map[string]string) (*Response, error) {
return c.get("playlists", args)
}
func (c *standardHTTPClient) FetchPlaylistByID(id string, args map[string]string) (*Response, error) {
return c.get(fmt.Sprintf("playlists/%s", id), args)
}
func (c *standardHTTPClient) SubmitPodcast(args map[string]string) (*Response, error) {
values := url.Values{}
for k, v := range args {
values.Set(k, v)
}
return c.post("podcasts/submit", args, values)
}
func (c *standardHTTPClient) DeletePodcast(id string, args map[string]string) (*Response, error) {
return c.delete(fmt.Sprintf("podcasts/%s", id), args)
}
func (c *standardHTTPClient) FetchAudienceForPodcast(id string, args map[string]string) (*Response, error) {
return c.get(fmt.Sprintf("podcasts/%s/audience", id), args)
}
func (c *standardHTTPClient) FetchPodcastsByDomain(domainName string, args map[string]string) (*Response, error) {
return c.get(fmt.Sprintf("podcasts/domains/%s", domainName), args)
}