created get simkl watchlist function
This commit is contained in:
parent
de38d0335b
commit
c95b658131
@ -1,36 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func SimklQuery(body interface{}, login bool) (json.RawMessage, string) {
|
||||
reader, _ := json.Marshal(body)
|
||||
response, err := http.NewRequest("POST", "https://graphql.anilist.co", bytes.NewBuffer(reader))
|
||||
if err != nil {
|
||||
log.Printf("Failed at response, %s\n", err)
|
||||
}
|
||||
if login && (SimklJWT{}) != simklJwt {
|
||||
response.Header.Add("Authorization", "Bearer "+simklJwt.AccessToken)
|
||||
} else if login {
|
||||
return nil, "Please login to anilist to make this request"
|
||||
}
|
||||
response.Header.Add("Content-Type", "application/json")
|
||||
response.Header.Add("Accept", "application/json")
|
||||
|
||||
func (a *App) SimklGetUserWatchlist() SimklWatchList {
|
||||
client := &http.Client{}
|
||||
res, reserr := client.Do(response)
|
||||
if reserr != nil {
|
||||
log.Printf("Failed at res, %s\n", err)
|
||||
|
||||
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)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Errored when sending request to the server")
|
||||
return SimklWatchList{}
|
||||
}
|
||||
|
||||
defer res.Body.Close()
|
||||
defer resp.Body.Close()
|
||||
respBody, _ := io.ReadAll(resp.Body)
|
||||
|
||||
returnedBody, err := io.ReadAll(res.Body)
|
||||
var watchlist SimklWatchList
|
||||
|
||||
return returnedBody, ""
|
||||
err = json.Unmarshal(respBody, &watchlist)
|
||||
if err != nil {
|
||||
log.Printf("Failed at unmarshal, %s\n", err)
|
||||
}
|
||||
|
||||
return watchlist
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user