anitrack/SimklFunctions.go

40 lines
803 B
Go
Raw Normal View History

2024-07-30 12:57:08 -04:00
package main
2024-07-30 12:59:06 -04:00
import (
"encoding/json"
2024-07-30 20:40:16 -04:00
"fmt"
2024-07-30 12:59:06 -04:00
"io"
"log"
"net/http"
2024-07-30 20:40:16 -04:00
"os"
2024-07-30 12:59:06 -04:00
)
2024-07-30 20:40:16 -04:00
func (a *App) SimklGetUserWatchlist() SimklWatchList {
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.simkl.com/sync/all-items/anime/watching", nil)
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "Bearer "+simklJwt.AccessToken)
req.Header.Add("simkl-api-key", os.Getenv("SIMKL_CLIENT_ID"))
resp, err := client.Do(req)
2024-07-30 12:59:06 -04:00
if err != nil {
2024-07-30 20:40:16 -04:00
fmt.Println("Errored when sending request to the server")
return SimklWatchList{}
2024-07-30 12:59:06 -04:00
}
2024-07-30 20:40:16 -04:00
defer resp.Body.Close()
respBody, _ := io.ReadAll(resp.Body)
2024-07-30 12:59:06 -04:00
2024-07-30 20:40:16 -04:00
var watchlist SimklWatchList
2024-07-30 12:59:06 -04:00
2024-07-30 20:40:16 -04:00
err = json.Unmarshal(respBody, &watchlist)
if err != nil {
log.Printf("Failed at unmarshal, %s\n", err)
}
2024-07-30 12:59:06 -04:00
2024-07-30 20:40:16 -04:00
return watchlist
2024-07-30 12:59:06 -04:00
}