diff --git a/rp.go b/rp.go new file mode 100644 index 0000000..f41f0e9 --- /dev/null +++ b/rp.go @@ -0,0 +1,51 @@ +package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "net/http" +) + +type Response struct { + Title string `json:"title"` + Artist string `json:"artist"` + Album string `json:"album"` + Year string `json:"year"` + Time int `json:"time"` // Seconds to go to end of song + Cover string `json:"cover"` // URL to picture of album cover +} + +/*func getImage(url string) { + fmt.Println("Calling API and get image...") + client := &http.Client{} + req, err := http.NewRequest("GET", url, nil) + if err != nil { + fmt.Print(err.Error()) + } + return req +} +*/ + +func main() { + fmt.Println("Calling API...") + client := &http.Client{} + req, err := http.NewRequest("GET", "https://api.radioparadise.com/api/now_playing", nil) + if err != nil { + fmt.Print(err.Error()) + } + req.Header.Add("Accept", "application/json") + req.Header.Add("Content-Type", "application/json") + resp, err := client.Do(req) + defer resp.Body.Close() + bodyBytes, err := ioutil.ReadAll(resp.Body) + if err != nil { + fmt.Print(err.Error()) + } + var responseObject Response + json.Unmarshal(bodyBytes, &responseObject) + // coverUrl := responseObject.Cover + // getImage(coverUrl) + fmt.Printf("API Response as struct %+v\n", responseObject) + fmt.Println("Image from albumcover...") +}