-
Notifications
You must be signed in to change notification settings - Fork 0
/
plots.go
46 lines (38 loc) · 965 Bytes
/
plots.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
package main
import (
"encoding/json"
"log"
"net/url"
"path"
"strconv"
)
type PlotStatus struct {
Id int `json:"id"`
Progress string `json:"progressPercentage"`
Eta string `json:"eta"`
Status string `json:"status"`
Filename string `json:"filename"`
AwaitingRemoval bool `json:"awaitingRemoval"`
}
type PlotList []PlotStatus
func getPlotStatuses(u, key string) PlotList {
endpoint, _ := url.Parse(u)
endpoint.Path = path.Join(endpoint.Path, "plots", key)
body, err := DoRequest("GET", endpoint )
if err != nil {
log.Println("ERROR: could not get list of plots:", err)
return nil
}
plots := PlotList{}
jsonErr := json.Unmarshal(body, &plots)
if jsonErr != nil {
log.Println("Failed to parse response:", jsonErr)
return nil
}
return plots
}
func UrlForPlotDownload(plot PlotStatus) *url.URL {
plotURL, _ := url.Parse(config.URL)
plotURL.Path = path.Join(plotURL.Path, "plots", strconv.Itoa(plot.Id), "download")
return plotURL
}