-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
subscriptions.go
75 lines (63 loc) · 2.31 KB
/
subscriptions.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
package pocketcasts
import (
"encoding/json"
"fmt"
"net/http"
"strings"
"time"
)
// GetSubscribedPodcasts returns a list of podcasts the user is subscribed to
// as well as the users folders.
func (acon *AuthedConnection) GetSubscribedPodcasts() (*SubscribedPodcasts, error) {
body := strings.NewReader(`{"v":1}`)
req, err := http.NewRequest("POST", "https://api.pocketcasts.com/user/podcast/list", body)
if err != nil {
return nil, err
}
// Fetch Request
resp, err := acon.Client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("request error: %s", resp.Status)
}
dec := json.NewDecoder(resp.Body)
out := &SubscribedPodcasts{}
err = dec.Decode(out)
if err != nil {
return nil, err
}
return out, nil
}
type PodcastUUID string
type FolderUUID string
type SubscribedPodcasts struct {
Podcasts []struct {
UUID PodcastUUID `json:"uuid"`
EpisodesSortOrder int `json:"episodesSortOrder"`
AutoStartFrom int `json:"autoStartFrom"`
Title string `json:"title"`
Author string `json:"author"`
Description string `json:"description"`
URL string `json:"url"`
LastEpisodePublished time.Time `json:"lastEpisodePublished"`
Unplayed bool `json:"unplayed"`
LastEpisodeUUID PodcastEpisodeUUID `json:"lastEpisodeUuid"`
LastEpisodePlayingStatus int `json:"lastEpisodePlayingStatus"`
LastEpisodeArchived bool `json:"lastEpisodeArchived"`
AutoSkipLast int `json:"autoSkipLast"`
FolderUUID FolderUUID `json:"folderUuid"`
SortPosition int `json:"sortPosition"`
DateAdded time.Time `json:"dateAdded"`
} `json:"podcasts"`
Folders []struct {
FolderUUID FolderUUID `json:"folderUuid"`
Name string `json:"name"`
Color int `json:"color"`
SortPosition int `json:"sortPosition"`
PodcastsSortType int `json:"podcastsSortType"`
DateAdded time.Time `json:"dateAdded"`
} `json:"folders"`
}