Skip to content

Commit 08c81c6

Browse files
Output RootListChangeResponse
1 parent ab209d3 commit 08c81c6

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

app/app.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ func GetRootList(token, userId string) (*RootListResponse, int, error) {
3838
data := RootListResponse{}
3939
err = json.Unmarshal(body, &data)
4040
if err != nil {
41-
fmt.Println("could not read request response body")
41+
fmt.Println("could not unmarshal JSON body")
4242
return nil, 0, err
4343
}
4444

4545
return &data, resp.StatusCode, nil
4646
}
4747

48-
func PostRootListChanges(ops []DeltaOps, baseRevision, token, userId string) (string, int, error) {
48+
func PostRootListChanges(ops []DeltaOps, baseRevision, token, userId string) (*RootListChangeResponse, int, error) {
4949
str := &ChangesPayload{
5050
BaseRevision: baseRevision,
5151
Deltas: []ChangeDelta{
@@ -58,7 +58,7 @@ func PostRootListChanges(ops []DeltaOps, baseRevision, token, userId string) (st
5858
jsonStr, err := json.Marshal(str)
5959
if err != nil {
6060
fmt.Printf("Error: %s", err)
61-
return "", 0, err
61+
return nil, 0, err
6262
}
6363

6464
url := fmt.Sprintf("https://spclient.wg.spotify.com/playlist/v2/user/%s/rootlist/changes", userId)
@@ -73,17 +73,22 @@ func PostRootListChanges(ops []DeltaOps, baseRevision, token, userId string) (st
7373
resp, err := client.Do(req)
7474
if err != nil {
7575
fmt.Println("error during POST request")
76-
return "", 0, err
76+
return nil, 0, err
7777
}
7878

7979
body, err := ioutil.ReadAll(resp.Body)
8080
if err != nil {
8181
fmt.Println("could not read request response body")
82-
return "", 0, err
82+
return nil, 0, err
8383
}
8484
_ = resp.Body.Close()
8585

86-
res := string(body)
86+
data := RootListChangeResponse{}
87+
err = json.Unmarshal(body, &data)
88+
if err != nil {
89+
fmt.Println("could not unmarshal JSON body")
90+
return nil, 0, err
91+
}
8792

88-
return res, resp.StatusCode, nil
93+
return &data, resp.StatusCode, nil
8994
}

app/structs.go

+12
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ type RootListResponse struct {
4949
Contents RootListResponseContents `json:"contents"`
5050
}
5151

52+
type SyncResult struct {
53+
FromRevision string `json:"fromRevision"`
54+
ToRevision string `json:"toRevision"`
55+
}
56+
57+
type RootListChangeResponse struct {
58+
Revision string `json:"revision"`
59+
MultipleHeads bool `json:"multipleHeads"`
60+
ResultingRevisions []string `json:"resultingRevisions"`
61+
SyncResult SyncResult `json:"syncResult"`
62+
}
63+
5264
type ChangeDelta struct {
5365
Ops []DeltaOps `json:"ops"`
5466
}

0 commit comments

Comments
 (0)